diff options
| author | unwox <me@unwox.com> | 2024-09-27 15:35:15 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2024-09-27 15:35:15 +0600 |
| commit | 61eb3bd95a6c723f51d910c4fb95e0ca1e716adc (patch) | |
| tree | 5adc98a37fd00a333dc0ea52227daf0725b8d1a2 | |
| parent | a97422981b1dfb0eff8d36836cb0777a5ecb90ad (diff) | |
implement serving static files with go
| -rw-r--r-- | main.go | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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) |
