From 88d054811df785b92b1b76dd91265849af8f29b3 Mon Sep 17 00:00:00 2001 From: Runxi Yu <me@runxiyu.org> Date: Wed, 12 Feb 2025 11:01:52 +0800 Subject: *: Migrate to the new path scheme --- resources.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'resources.go') diff --git a/resources.go b/resources.go index 30b0de5..4624603 100644 --- a/resources.go +++ b/resources.go @@ -13,12 +13,12 @@ import ( //go:embed static/* templates/* var source_fs embed.FS -func serve_source() { - http.Handle("/source/", - http.StripPrefix( - "/source/", - http.FileServer(http.FS(source_fs)), - ), +var source_handler http.Handler + +func init() { + source_handler = http.StripPrefix( + "/:/source/", + http.FileServer(http.FS(source_fs)), ) } @@ -35,16 +35,12 @@ func load_templates() (err error) { return err } -func serve_static() (err error) { +var static_handler http.Handler +func init() { static_fs, err := fs.Sub(resources_fs, "static") if err != nil { - return err + panic(err) } - http.Handle("/static/", - http.StripPrefix( - "/static/", - http.FileServer(http.FS(static_fs)), - ), - ) - return nil + static_handler = http.StripPrefix("/:/static/", http.FileServer(http.FS(static_fs))) } + -- cgit v1.2.3