diff --git a/modules/http/http.go b/modules/http/http.go index 712beb7..10151cd 100644 --- a/modules/http/http.go +++ b/modules/http/http.go @@ -234,13 +234,13 @@ func handleRequest(ctx *fasthttp.RequestCtx) { req.Path = path req.Body = string(ctx.Request.Body()) - ctx.QueryArgs().VisitAll(func(key, value []byte) { + for key, value := range ctx.QueryArgs().All() { req.Query[string(key)] = string(value) - }) + } - ctx.Request.Header.VisitAll(func(key, value []byte) { + for key, value := range ctx.Request.Header.All() { req.Headers[string(key)] = string(value) - }) + } err := worker.HandleRequest(req, resp) if err != nil { @@ -277,8 +277,8 @@ func tryStaticHandler(ctx *fasthttp.RequestCtx, path string) bool { defer staticMu.RUnlock() for prefix, fs := range staticHandlers { - if strings.HasPrefix(path, prefix) { - ctx.Request.URI().SetPath(strings.TrimPrefix(path, prefix)) + if after, ok := strings.CutPrefix(path, prefix); ok { + ctx.Request.URI().SetPath(after) fs.NewRequestHandler()(ctx) return true } diff --git a/modules/string/string.go b/modules/string/string.go index 3a7824f..e8a6f27 100644 --- a/modules/string/string.go +++ b/modules/string/string.go @@ -30,11 +30,7 @@ func string_slice(s *luajit.State) int { runes := []rune(str) length := len(runes) - startIdx := start - 1 // Convert from 1-indexed - - if startIdx < 0 { - startIdx = 0 - } + startIdx := max(start-1, 0) // Convert from 1-indexed if startIdx >= length { s.PushString("") return 1 diff --git a/state/state.go b/state/state.go index d3f7ab3..4333c2d 100644 --- a/state/state.go +++ b/state/state.go @@ -259,7 +259,7 @@ func (s *State) ExecuteStringWithResults(code, name string) ([]any, error) { } results := make([]any, nresults) - for i := 0; i < nresults; i++ { + for i := range nresults { val, err := s.ToValue(baseTop + i + 1) if err != nil { results[i] = nil diff --git a/watcher.go b/watcher.go index ca4271a..40f3234 100644 --- a/watcher.go +++ b/watcher.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "maps" "os" "path/filepath" "strings" @@ -84,9 +85,7 @@ func (fw *FileWatcher) pollLoop() { func (fw *FileWatcher) checkFiles() { fw.mu.RLock() files := make(map[string]time.Time, len(fw.files)) - for path, modTime := range fw.files { - files[path] = modTime - } + maps.Copy(files, fw.files) fw.mu.RUnlock() changed := false