diff options
| author | lost+skunk <[email protected]> | 2024-07-13 21:32:04 +0300 |
|---|---|---|
| committer | lost+skunk <[email protected]> | 2024-07-13 21:32:04 +0300 |
| commit | 667de65e2fda7cb30ec886ccf6619a4178d5488b (patch) | |
| tree | 72458bc795e31a3a6c8aadada91b71d5ff3acbf5 /app/router.go | |
| parent | 8391cc34a95a82cf025b96e4352246a245d06d61 (diff) | |
| download | skunky-art-667de65e2fda7cb30ec886ccf6619a4178d5488b.tar.gz skunky-art-667de65e2fda7cb30ec886ccf6619a4178d5488b.tar.bz2 skunky-art-667de65e2fda7cb30ec886ccf6619a4178d5488b.zip | |
v1.3
Diffstat (limited to 'app/router.go')
| -rw-r--r-- | app/router.go | 27 |
1 files changed, 11 insertions, 16 deletions
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()) - } -} |
