moved static into source
This commit is contained in:
@@ -10,20 +10,20 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed source static
|
||||
//go:embed source
|
||||
var sourceFS embed.FS
|
||||
|
||||
func main() {
|
||||
port := flag.Int("port", 8081, "port to listen on")
|
||||
flag.Parse()
|
||||
|
||||
staticRoot, err := fs.Sub(sourceFS, "source")
|
||||
sourceRoot, err := fs.Sub(sourceFS, "source")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// print exactly what got embedded
|
||||
fs.WalkDir(staticRoot, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
fs.WalkDir(sourceRoot, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
log.Println("walk error:", err)
|
||||
return nil
|
||||
@@ -34,7 +34,7 @@ func main() {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(staticRoot, "templates/main.html", "pages/index.html")
|
||||
tmpl, err := template.ParseFS(sourceRoot, "templates/main.html", "pages/index.html")
|
||||
if err != nil {
|
||||
log.Println("parse error:", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -58,7 +58,7 @@ func main() {
|
||||
})
|
||||
|
||||
mux.HandleFunc("GET /research", func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(staticRoot, "templates/main.html", "pages/research.html")
|
||||
tmpl, err := template.ParseFS(sourceRoot, "templates/main.html", "pages/research.html")
|
||||
if err != nil {
|
||||
log.Println("parse error:", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -82,7 +82,7 @@ func main() {
|
||||
})
|
||||
|
||||
mux.HandleFunc("GET /bookkeeping", func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(staticRoot, "templates/main.html", "pages/bookkeeping.html")
|
||||
tmpl, err := template.ParseFS(sourceRoot, "templates/main.html", "pages/bookkeeping.html")
|
||||
if err != nil {
|
||||
log.Println("parse error:", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -106,7 +106,7 @@ func main() {
|
||||
})
|
||||
|
||||
mux.HandleFunc("GET /personal", func(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl, err := template.ParseFS(staticRoot, "templates/main.html", "pages/interests.html")
|
||||
tmpl, err := template.ParseFS(sourceRoot, "templates/main.html", "pages/interests.html")
|
||||
if err != nil {
|
||||
log.Println("parse error:", err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -129,9 +129,16 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
assetsRoot, err := fs.Sub(sourceFS, "static")
|
||||
staticRoot, err := fs.Sub(sourceFS, "source/static")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(assetsRoot)))
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(staticRoot)))
|
||||
|
||||
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFileFS(w, r, staticRoot, "favicon.ico")
|
||||
})
|
||||
|
||||
addr := fmt.Sprintf(":%d", *port)
|
||||
log.Printf("running on http://localhost%s/\n", addr)
|
||||
|
||||
Reference in New Issue
Block a user