mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-19 16:21:43 +01:00
- add block syntax parser/scanner with nested @blocks and elif/else support - restructure rule execution into explicit pre/post phases with phase flags - classify commands by phase and termination behavior - enforce flow semantics (default rule handling, dead-rule detection) - expand HTTP flow coverage with block + YAML parity tests and benches - refresh rules README/spec and update playground/docs integration
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package rules
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
|
|
httputils "github.com/yusing/goutils/http"
|
|
)
|
|
|
|
type templateString struct {
|
|
string
|
|
|
|
isTemplate bool
|
|
}
|
|
|
|
type keyValueTemplate struct {
|
|
key string
|
|
tmpl templateString
|
|
}
|
|
|
|
func (tmpl *keyValueTemplate) Unpack() (string, templateString) {
|
|
return tmpl.key, tmpl.tmpl
|
|
}
|
|
|
|
func (tmpl *templateString) ExpandVars(w *httputils.ResponseModifier, req *http.Request, dst io.Writer) (phase PhaseFlag, err error) {
|
|
if !tmpl.isTemplate {
|
|
_, err := asBytesBufferLike(dst).WriteString(tmpl.string)
|
|
return PhaseNone, err
|
|
}
|
|
|
|
return ExpandVars(w, req, tmpl.string, dst)
|
|
}
|
|
|
|
func (tmpl *templateString) ExpandVarsToString(w *httputils.ResponseModifier, r *http.Request) (string, PhaseFlag, error) {
|
|
if !tmpl.isTemplate {
|
|
return tmpl.string, PhaseNone, nil
|
|
}
|
|
|
|
var buf strings.Builder
|
|
phase, err := tmpl.ExpandVars(w, r, &buf)
|
|
if err != nil {
|
|
return "", PhaseNone, err
|
|
}
|
|
return buf.String(), phase, nil
|
|
}
|
|
|
|
func (tmpl *templateString) Len() int {
|
|
return len(tmpl.string)
|
|
}
|