-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
56 lines (47 loc) · 1.22 KB
/
main.go
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
50
51
52
53
54
55
56
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/yznts/oxigen/api"
"github.com/yznts/oxigen/pages"
"go.kyoto.codes/v3/component"
"go.kyoto.codes/v3/htmx"
"go.kyoto.codes/v3/rendering"
"go.kyoto.codes/zen/v3/errorsx"
"go.kyoto.codes/zen/v3/mapx"
"go.kyoto.codes/zen/v3/templatex"
)
func main() {
// Parse arguments
addr := flag.String("http", ":8000", "Serving address")
flag.Parse()
// Setup rendering
rendering.TEMPLATE_GLOB = "**/*.go.html"
rendering.TEMPLATE_FUNCMAP = mapx.Merge(
rendering.FuncMap,
htmx.FuncMap,
component.FuncMap,
templatex.FuncMap,
)
// Initialize mux
mux := http.NewServeMux()
// Setup assets
mux.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("./assets/dist"))))
// Setup serving components (pages/components)
serve := map[string]component.Component{
"/": pages.Home,
"/api": pages.Api,
"/generator": pages.Generator,
}
// Register serving components
for route, component := range serve {
mux.HandleFunc(route, rendering.Handler(component))
}
// Setup API
mux.HandleFunc("/api/ogen", api.Generator)
// Serve
log.Printf(fmt.Sprintf("Serving on %s", *addr))
errorsx.Must(0, http.ListenAndServe(*addr, mux))
}