From 667de65e2fda7cb30ec886ccf6619a4178d5488b Mon Sep 17 00:00:00 2001 From: lost+skunk Date: Sat, 13 Jul 2024 21:32:04 +0300 Subject: v1.3 --- app/router.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'app/router.go') diff --git a/app/router.go b/app/router.go index e833628..f3c59c5 100644 --- a/app/router.go +++ b/app/router.go @@ -4,11 +4,12 @@ import ( "io" "net/http" u "net/url" - "os" "strconv" "strings" ) +var Host string + func Router() { parsepath := func(path string) map[int]string { if l := len(CFG.BasePath); len(path) > l { @@ -43,18 +44,18 @@ func Router() { // функция, что управляет всем handle := func(w http.ResponseWriter, r *http.Request) { - path := parsepath(r.URL.Path) - var wr = io.WriteString - open_n_send := func(name string) { - f, e := os.ReadFile(name) - err(e) - wr(w, string(f)) + if h := r.Header["Scheme"]; len(h) != 0 && h[0] == "https" { + Host = h[0] + "://" + r.Host + } else { + Host = "http://" + r.Host } + path := parsepath(r.URL.Path) + // структура с функциями var skunky skunkyart - skunky.Args = r.URL.Query() skunky.Writer = w + skunky.Args = r.URL.Query() skunky.BasePath = CFG.BasePath arg := skunky.Args.Get @@ -95,18 +96,12 @@ func Router() { } case "about": skunky.About() - case "gui": + case "stylesheet": w.Header().Add("content-type", "text/css") - open_n_send(next(path, 2)) + io.WriteString(w, Templates["css/skunky.css"]) } } http.HandleFunc("/", handle) http.ListenAndServe(CFG.Listen, nil) } - -func err(e error) { - if e != nil { - println(e.Error()) - } -} -- cgit v1.2.3