From 67804a6bb23af0fcdfc514fcd24a66154b0c9509 Mon Sep 17 00:00:00 2001 From: kingxt Date: Wed, 9 Dec 2020 11:16:38 +0800 Subject: [PATCH] optimized parse tag (#256) --- go.mod | 3 +- go.sum | 4 +- tools/goctl/api/spec/fn.go | 107 ++++++++++++----------------------- tools/goctl/api/spec/tags.go | 67 ++++++++++++++++++++++ 4 files changed, 108 insertions(+), 73 deletions(-) create mode 100644 tools/goctl/api/spec/tags.go diff --git a/go.mod b/go.mod index faf90e94..014f5646 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/emicklei/proto v1.9.0 github.com/fatih/color v1.9.0 // indirect + github.com/fatih/structtag v1.2.0 github.com/frankban/quicktest v1.7.2 // indirect github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 github.com/go-redis/redis v6.15.7+incompatible @@ -55,7 +56,7 @@ require ( golang.org/x/tools v0.0.0-20200410132612-ae9902aceb98 // indirect google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f // indirect google.golang.org/grpc v1.29.1 - google.golang.org/protobuf v1.25.0 + google.golang.org/protobuf v1.25.0 // indirect gopkg.in/cheggaaa/pb.v1 v1.0.28 gopkg.in/h2non/gock.v1 v1.0.15 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 47b33660..aa3933fe 100644 --- a/go.sum +++ b/go.sum @@ -63,6 +63,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/frankban/quicktest v1.7.2 h1:2QxQoC1TS09S7fhCPsrvqYdvP1H5M1P1ih5ABm3BTYk= github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= @@ -450,8 +452,6 @@ gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tools/goctl/api/spec/fn.go b/tools/goctl/api/spec/fn.go index 35ee9c76..2fbbc2dc 100644 --- a/tools/goctl/api/spec/fn.go +++ b/tools/goctl/api/spec/fn.go @@ -2,30 +2,15 @@ package spec import ( "errors" - "regexp" "strings" "github.com/tal-tech/go-zero/core/stringx" "github.com/tal-tech/go-zero/tools/goctl/util" ) -const ( - TagKey = "tag" - NameKey = "name" - OptionKey = "option" - BodyTag = "json" -) - -var ( - TagRe = regexp.MustCompile(`(?P\w+):"(?P[^,"]+)[,]?(?P