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.Path = path
|
||||||
req.Body = string(ctx.Request.Body())
|
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)
|
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)
|
req.Headers[string(key)] = string(value)
|
||||||
})
|
}
|
||||||
|
|
||||||
err := worker.HandleRequest(req, resp)
|
err := worker.HandleRequest(req, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -277,8 +277,8 @@ func tryStaticHandler(ctx *fasthttp.RequestCtx, path string) bool {
|
|||||||
defer staticMu.RUnlock()
|
defer staticMu.RUnlock()
|
||||||
|
|
||||||
for prefix, fs := range staticHandlers {
|
for prefix, fs := range staticHandlers {
|
||||||
if strings.HasPrefix(path, prefix) {
|
if after, ok := strings.CutPrefix(path, prefix); ok {
|
||||||
ctx.Request.URI().SetPath(strings.TrimPrefix(path, prefix))
|
ctx.Request.URI().SetPath(after)
|
||||||
fs.NewRequestHandler()(ctx)
|
fs.NewRequestHandler()(ctx)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,7 @@ func string_slice(s *luajit.State) int {
|
|||||||
|
|
||||||
runes := []rune(str)
|
runes := []rune(str)
|
||||||
length := len(runes)
|
length := len(runes)
|
||||||
startIdx := start - 1 // Convert from 1-indexed
|
startIdx := max(start-1, 0) // Convert from 1-indexed
|
||||||
|
|
||||||
if startIdx < 0 {
|
|
||||||
startIdx = 0
|
|
||||||
}
|
|
||||||
if startIdx >= length {
|
if startIdx >= length {
|
||||||
s.PushString("")
|
s.PushString("")
|
||||||
return 1
|
return 1
|
||||||
|
@ -259,7 +259,7 @@ func (s *State) ExecuteStringWithResults(code, name string) ([]any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
results := make([]any, nresults)
|
results := make([]any, nresults)
|
||||||
for i := 0; i < nresults; i++ {
|
for i := range nresults {
|
||||||
val, err := s.ToValue(baseTop + i + 1)
|
val, err := s.ToValue(baseTop + i + 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results[i] = nil
|
results[i] = nil
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -84,9 +85,7 @@ func (fw *FileWatcher) pollLoop() {
|
|||||||
func (fw *FileWatcher) checkFiles() {
|
func (fw *FileWatcher) checkFiles() {
|
||||||
fw.mu.RLock()
|
fw.mu.RLock()
|
||||||
files := make(map[string]time.Time, len(fw.files))
|
files := make(map[string]time.Time, len(fw.files))
|
||||||
for path, modTime := range fw.files {
|
maps.Copy(files, fw.files)
|
||||||
files[path] = modTime
|
|
||||||
}
|
|
||||||
fw.mu.RUnlock()
|
fw.mu.RUnlock()
|
||||||
|
|
||||||
changed := false
|
changed := false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user