ange
df8cd1ea54
Co-authored-by: stcb <21@stcb.cc> Reviewed-on: #7 Co-authored-by: ange <ange@yw5n.com> Co-committed-by: ange <ange@yw5n.com>
33 lines
694 B
Go
33 lines
694 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
func route(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/style.css" {
|
|
http.ServeFile(w, r, "/html/style.css")
|
|
return
|
|
}
|
|
if len(r.URL.Path) > len("/static/") && r.URL.Path[:len("/static/")] == "/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("/", route)
|
|
|
|
err := http.ListenAndServe(":3000", nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|