go backend (#1)

Reviewed-on: yw5n/yw5ncom#1
This commit is contained in:
ange 2024-09-28 16:16:52 +00:00
parent e87932e375
commit 1e228ed338
10 changed files with 105 additions and 34 deletions

33
src/main.go Normal file
View file

@ -0,0 +1,33 @@
package main
import (
"log"
"net/http"
"path/filepath"
"strings"
)
func html(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/style.css" {
http.ServeFile(w, r, "/html/style.css")
return
}
if strings.HasPrefix(r.URL.Path, "/static/") {
http.ServeFile(w, r, r.URL.Path)
return
}
if r.URL.Path == "/" {
http.ServeFile(w, r, "/html/index.html")
return
}
http.ServeFile(w, r, filepath.Join("/html", r.URL.Path + ".html"))
}
func main() {
http.HandleFunc("/", html)
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
}

19
src/vars/vars.go Normal file
View file

@ -0,0 +1,19 @@
package vars
import (
"path/filepath"
)
var (
templates string
static string
html string
css string
)
func init() {
templates = "templates"
static = "static"
html = filepath.Join(static, "html")
css = filepath.Join(static, "css")
}