From 61eb3bd95a6c723f51d910c4fb95e0ca1e716adc Mon Sep 17 00:00:00 2001 From: unwox Date: Fri, 27 Sep 2024 15:35:15 +0600 Subject: implement serving static files with go --- main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index 09ebd01..00629f3 100644 --- a/main.go +++ b/main.go @@ -90,6 +90,27 @@ func main() { ) return 0 } + routeModule["static"] = func (l *Lua) int { + var route, dir string + err := l.Scan(&route, &dir) + if err != nil { + fmt.Println("error:", err) + // FIXME: handle + return 0 + } + // check if route is already registered. otherwise + // mux.HandleFunc will panic + _, ok := routes[route] + if ok { + return 0 + } + routes[route] = true + mux.Handle( + route, + http.StripPrefix("/static/", http.FileServer(http.Dir(dir))), + ) + return 0 + } // define luna.http module httpModule := make(map[string]any) -- cgit v1.2.3