forked from malteburkert/robotfactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (43 loc) 路 1.2 KB
/
Copy pathmain.go
File metadata and controls
49 lines (43 loc) 路 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"path/filepath"
)
func loadTemplate(name string) *template.Template {
return template.Must(template.ParseFiles(
filepath.Join("templates", "layout.html"),
filepath.Join("templates", name),
))
}
func handleIndex(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
t := loadTemplate("index.html")
err := t.ExecuteTemplate(w, "index.html", map[string]any{
"Title": "RoboForge Industries",
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func main() {
initDB()
seedParts()
seedProducts()
http.HandleFunc("/", handleIndex)
http.HandleFunc("/bom", handleBOM)
http.HandleFunc("/bom/import", handleUploadProcess)
http.HandleFunc("/procurement", handleProcurement)
http.HandleFunc("/products", handleProducts)
http.HandleFunc("/products/detail", handleProductDetail)
http.HandleFunc("/products/generate", handleGenerateImage)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
addr := ":8080"
fmt.Printf("馃 RoboForge Industries running at http://localhost%s\n", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}