summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-09-27 15:35:15 +0600
committerunwox <me@unwox.com>2024-09-27 15:35:15 +0600
commit61eb3bd95a6c723f51d910c4fb95e0ca1e716adc (patch)
tree5adc98a37fd00a333dc0ea52227daf0725b8d1a2 /main.go
parenta97422981b1dfb0eff8d36836cb0777a5ecb90ad (diff)
implement serving static files with go
Diffstat (limited to 'main.go')
-rw-r--r--main.go21
1 files changed, 21 insertions, 0 deletions
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)