-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
83 lines (70 loc) · 1.9 KB
/
main.go
File metadata and controls
83 lines (70 loc) · 1.9 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"embed"
"flag"
"io/fs"
"log"
"net/http"
"os"
"strings"
"time"
"github.com/kernelkit/infix-webui/internal/auth"
"github.com/kernelkit/infix-webui/internal/restconf"
"github.com/kernelkit/infix-webui/internal/server"
)
//go:embed templates/*
var templateFS embed.FS
//go:embed static/*
var staticFS embed.FS
func main() {
defaultRC := "http://localhost:8080/restconf"
if env := os.Getenv("RESTCONF_URL"); env != "" {
defaultRC = env
}
listen := flag.String("listen", ":8080", "address to listen on")
restconfURL := flag.String("restconf", defaultRC, "RESTCONF base URL")
sessionKey := flag.String("session-key", "/var/lib/misc/webui-session.key", "path to persistent session key file")
insecureTLS := flag.Bool("insecure-restconf", envBool("RESTCONF_INSECURE"), "disable RESTCONF TLS verification")
flag.Parse()
store, err := auth.NewSessionStore(*sessionKey)
if err != nil {
log.Fatalf("session store: %v", err)
}
rc := restconf.NewClient(*restconfURL, *insecureTLS)
tmplFS, err := fs.Sub(templateFS, "templates")
if err != nil {
log.Fatalf("template fs: %v", err)
}
stFS, err := fs.Sub(staticFS, "static")
if err != nil {
log.Fatalf("static fs: %v", err)
}
handler, err := server.New(store, rc, tmplFS, stFS)
if err != nil {
log.Fatalf("server setup: %v", err)
}
log.Printf("listening on %s (restconf %s)", *listen, *restconfURL)
srv := &http.Server{
Addr: *listen,
Handler: handler,
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("listen: %v", err)
}
}
func envBool(key string) bool {
v := strings.TrimSpace(os.Getenv(key))
if v == "" {
return false
}
switch strings.ToLower(v) {
case "1", "true", "yes", "y", "on":
return true
default:
return false
}
}