From 044b3664ed2917c6b9ee42582b3213c1e59a5a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 14 Apr 2025 15:46:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96nginx=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/nginx/parser.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/nginx/parser.go b/pkg/nginx/parser.go index d285d3d1..4496dcae 100644 --- a/pkg/nginx/parser.go +++ b/pkg/nginx/parser.go @@ -2,6 +2,7 @@ package nginx import ( "errors" + "fmt" "slices" "strings" @@ -49,7 +50,7 @@ func (p *Parser) Find(key string) ([]config.IDirective, error) { key = parts[i] directives := block.FindDirectives(key) if len(directives) == 0 { - return nil, errors.New("given key not found") + return nil, fmt.Errorf("given key %s not found", key) } if len(directives) > 1 { return nil, errors.New("multiple directives found") @@ -78,7 +79,7 @@ func (p *Parser) FindOne(key string) (config.IDirective, error) { return nil, err } if len(directives) == 0 { - return nil, errors.New("given key not found") + return nil, fmt.Errorf("given key %s not found", key) } return directives[0], nil @@ -97,10 +98,10 @@ func (p *Parser) Clear(key string) error { for i := 0; i < len(parts); i++ { directives := block.FindDirectives(parts[i]) if len(directives) == 0 { - return errors.New("given key not found") + return fmt.Errorf("given key %s not found", parts[i]) } if len(directives) > 1 { - return errors.New("multiple directives found") + return fmt.Errorf("multiple directives found for %s", parts[i]) } block, ok = directives[0].GetBlock().(*config.Block) if !ok { @@ -131,10 +132,10 @@ func (p *Parser) Set(key string, directives []*config.Directive) error { for i := 0; i < len(parts); i++ { sub := block.FindDirectives(parts[i]) if len(sub) == 0 { - return errors.New("given key not found") + return fmt.Errorf("given key %s not found", parts[i]) } if len(sub) > 1 { - return errors.New("multiple directives found") + return fmt.Errorf("multiple directives found for %s", parts[i]) } block, ok = sub[0].GetBlock().(*config.Block) if !ok {