Skip to content

Commit

Permalink
optimize: update thriftgo version and optimize validator sdk related …
Browse files Browse the repository at this point in the history
…code (#26)
  • Loading branch information
HeyJavaBean authored May 30, 2024
1 parent 36f2bc7 commit c5069b3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.13

require (
github.com/apache/thrift v0.13.0
github.com/cloudwego/thriftgo v0.2.12
github.com/cloudwego/thriftgo v0.3.13-0.20240530061534-6600bc058d00
)
20 changes: 16 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
github.com/apache/thrift v0.13.0 h1:5hryIiq9gtn+MiLVn0wP37kb/uTeRZgN08WoCsAhIhI=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/cloudwego/thriftgo v0.2.12 h1:W0/+k5xL9lpS/IrUodbezyBNcOKGPvu1djR34kOcpeM=
github.com/cloudwego/thriftgo v0.2.12/go.mod h1:dAyXHEmKXo0LfMCrblVEY3mUZsdeuA5+i0vF5f09j7E=
github.com/cloudwego/thriftgo v0.3.13-0.20240530061534-6600bc058d00 h1:GA6zRxtZh8ctZ2LZCV3h7GfZMuBfrkdOQX1pzEcwRnQ=
github.com/cloudwego/thriftgo v0.3.13-0.20240530061534-6600bc058d00/go.mod h1:R4a+4aVDI0V9YCTfpNgmvbkq/9ThKgF7Om8Z0I36698=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand All @@ -21,9 +28,14 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
}

if queryVersion {
println(Version)
println(validator.Version)
os.Exit(0)
}

Expand Down
21 changes: 11 additions & 10 deletions validator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
"github.com/cloudwego/thriftgo/semantic"
)

var Version string
const (
Version = "v0.2.4"
)

var ValidMethodName string = "IsValid"

Expand Down Expand Up @@ -115,16 +117,15 @@ func (g *generator) generate() ([]*plugin.Generated, error) {
var ret []*plugin.Generated
// generate file header
for ast := range g.request.AST.DepthFirstSearch() {
if ok, _ := golang.DoRef(ast.Filename); ok {
// if it's common struct refs, do not generate files
continue
}
g.buffer.Reset()
g.enumImport = g.enumImport[:0]
scope, err := golang.BuildScope(g.utils, ast)
scope, _, err := golang.BuildRefScope(g.utils, ast)
if err != nil {
return nil, err
}
if scope == nil {
continue
}
g.utils.SetRootScope(scope)
resolver := golang.NewResolver(g.utils.RootScope(), g.utils)
// generate validation
Expand Down Expand Up @@ -601,10 +602,10 @@ func (g *generator) generateNumericValidation(vc *ValidateContext) error {
g.unindent()
g.writeLine("}")
case parser.GreatEqual:
if strings.HasPrefix(source,"*"){
sourceVal := strings.TrimPrefix(source,"*")
g.writeLinef("if %s!=nil && %s < %s(%s) {\n",sourceVal, target, typeName, source)
}else{
if strings.HasPrefix(source, "*") {
sourceVal := strings.TrimPrefix(source, "*")
g.writeLinef("if %s!=nil && %s < %s(%s) {\n", sourceVal, target, typeName, source)
} else {
g.writeLinef("if %s < %s(%s) {\n", target, typeName, source)
}
g.indent()
Expand Down
6 changes: 4 additions & 2 deletions validator/plugin_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ type ValidatorSDKPlugin struct {
}

func NewValidatorSDKPlugin(params string) *ValidatorSDKPlugin {
return &ValidatorSDKPlugin{
PluginParameters: strings.Split(params, ","),
plugin := &ValidatorSDKPlugin{}
if params != "" {
plugin.PluginParameters = strings.Split(params, ",")
}
return plugin
}

func (k *ValidatorSDKPlugin) Invoke(req *plugin.Request) (res *plugin.Response) {
Expand Down
25 changes: 0 additions & 25 deletions version.go

This file was deleted.

0 comments on commit c5069b3

Please sign in to comment.