更新 gotemplate 的参数注入

This commit is contained in:
dragon
2025-04-15 17:23:23 +08:00
parent 2b2617200d
commit 3f63988e2d
4 changed files with 71 additions and 50 deletions

25
pkg/utils/template.go Normal file
View File

@@ -0,0 +1,25 @@
package utils
import (
"net/http"
"strings"
)
func NewTemplateInject(r *http.Request, def map[string]any) map[string]any {
if def == nil {
def = make(map[string]any)
}
headers := make(map[string]string)
for k, vs := range r.Header {
headers[k] = strings.Join(vs, ",")
}
def["Request"] = map[string]any{
"Headers": headers,
"Path": r.URL.Path,
"Method": r.Method,
"RequestURI": r.RequestURI,
"RemoteAddr": r.RemoteAddr,
"RemoteIP": GetRemoteIP(r),
}
return def
}