diff --git a/main.go b/main.go index 0ef6fca..475ee61 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/http" "sync" "github.com/lucas-clemente/quic-go/http3" @@ -14,6 +15,8 @@ import ( "server/src" ) +var loading = true + func main() { config.LoadConfig() log.Log("Loaded config:", fmt.Sprintf("%+v", config.GetConfig())) @@ -23,20 +26,19 @@ func main() { log.Log("Starting server") src.DBInit() - srv.LoadSites() - - serv := srv.CreateServe() + go func() { + loading = true + srv.LoadSites() + loading = false + }() - webServer3 := &http3.Server{ - Addr: "localhost:" + fmt.Sprintf("%d", config.GetConfig().Port), - Handler: serv, - } + serv := srv.CreateServe(&loading) wg := sync.WaitGroup{} wg.Add(1) go func() { - startWebServer(webServer3) + startWebServer("localhost:"+fmt.Sprintf("%d", config.GetConfig().Port), serv) wg.Done() }() @@ -50,11 +52,10 @@ func main() { wg.Wait() } -func startWebServer(webServer *http3.Server) { +func startWebServer(addr string, handler http.Handler) { // blocks if success - log.Log(fmt.Sprintf("ListenAndServe Webserver HTTP/3 with TLS started on https://%s", webServer.Addr)) - // err := webServer.ListenAndServeTLS(config.CertsFile, config.KeyFile) - err := http3.ListenAndServe(webServer.Addr, config.CertsFile, config.KeyFile, webServer.Handler) + log.Log(fmt.Sprintf("ListenAndServe Webserver HTTP/3 with TLS started on https://%s", addr)) + err := http3.ListenAndServe(addr, config.CertsFile, config.KeyFile, handler) if err != nil { log.Err(err, "Error starting webServer") diff --git a/src/db.go b/src/db.go index 7f040c0..6381278 100644 --- a/src/db.go +++ b/src/db.go @@ -10,6 +10,7 @@ import ( var cluster *gocql.ClusterConfig // var GQLSession gocqlx.Session + var Session *gocql.Session // DBInit Create and open DB Connection diff --git a/src/srv/errors.go b/src/srv/errors.go index ab157f8..27a2aa6 100644 --- a/src/srv/errors.go +++ b/src/srv/errors.go @@ -29,14 +29,36 @@ func GetErrorSite(error Errors, host string, path string, additional string) (*[ site = "Error not found" } - site = fmt.Sprintf(` + site = fmt.Sprintf(errorSite, error, http.StatusText(int(error)), http.StatusText(int(error)), path, site, additional, int(error), host, runtime.Version(), getOS()) + + ret := []byte(site) + + return &ret, int(error) +} + +func getOS() string { + f, err := os.Open("/etc/os-release") + if err != nil { + return "Not UNIX" + } + defer f.Close() + s := bufio.NewScanner(f) + for s.Scan() { + if strings.HasPrefix(s.Text(), "NAME=") { + return strings.TrimSuffix(strings.TrimPrefix(s.Text(), "NAME=\""), "\"") + } + } + return "" +} + +const errorSite = `