This commit is contained in:
yusing
2026-02-16 08:59:01 +08:00
parent 15b9635ee1
commit e4e6f6b3e8
242 changed files with 3953 additions and 3502 deletions

View File

@@ -41,6 +41,7 @@ const (
OnRoute = "route"
// on response
OnResponseHeader = "resp_header"
OnStatus = "status"
)
@@ -59,10 +60,11 @@ var checkers = map[string]struct {
),
args: map[string]string{},
},
validate: func(args []string) (any, gperr.Error) {
validate: func(args []string) (any, error) {
if len(args) != 0 {
return nil, ErrExpectNoArg
}
//nolint:nilnil
return nil, nil
},
builder: func(args any) CheckFunc { return func(w http.ResponseWriter, r *http.Request) bool { return false } }, // this should never be called
@@ -251,7 +253,7 @@ var checkers = map[string]struct {
"proto": "the http protocol (http, https, h3)",
},
},
validate: func(args []string) (any, gperr.Error) {
validate: func(args []string) (any, error) {
if len(args) != 1 {
return nil, ErrExpectOneArg
}
@@ -581,7 +583,7 @@ func (on *RuleOn) Parse(v string) error {
}
parsed, isResp, err := parseOn(rule)
if err != nil {
errs.Add(err.Subjectf("line %d", i+1))
errs.AddSubjectf(err, "line %d", i+1)
continue
}
if isResp {
@@ -603,7 +605,7 @@ func (on *RuleOn) MarshalText() ([]byte, error) {
return []byte(on.String()), nil
}
func parseOn(line string) (Checker, bool, gperr.Error) {
func parseOn(line string) (Checker, bool, error) {
ors := splitPipe(line)
if len(ors) > 1 {
@@ -645,7 +647,7 @@ func parseOn(line string) (Checker, bool, gperr.Error) {
validArgs, err := checker.validate(args)
if err != nil {
return nil, false, err.With(checker.help.Error())
return nil, false, gperr.Wrap(err).With(checker.help.Error())
}
checkFunc := checker.builder(validArgs)