minor code modernization
This commit is contained in:
parent
cc2cb0c682
commit
1e19ba7700
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user