Clean errors (#1019)

* cmd/upgrade add proto-gen-go-errors
modify proto-gen-go-errors template and go.mod

* modify proto-gen-go-errors version and clean code
pull/1020/head
包子 4 years ago committed by GitHub
parent 7585257f9e
commit 996922fa87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cmd/kratos/internal/upgrade/upgrade.go
  2. 2
      cmd/protoc-gen-go-errors/go.mod
  3. 2
      cmd/protoc-gen-go-errors/go.sum
  4. 3
      cmd/protoc-gen-go-errors/main.go
  5. 5
      cmd/protoc-gen-go-errors/template.go

@ -21,6 +21,7 @@ func Run(cmd *cobra.Command, args []string) {
err := base.GoGet(
"github.com/go-kratos/kratos/cmd/kratos/v2",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2",
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2",
"google.golang.org/protobuf/cmd/protoc-gen-go",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc",
)

@ -3,6 +3,6 @@ module github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
go 1.15
require (
github.com/go-kratos/kratos/v2 v2.0.0-20210608032802-c551448bbd64
github.com/go-kratos/kratos/v2 v2.0.0-20210608085308-7585257f9ea1
google.golang.org/protobuf v1.26.0
)

@ -12,6 +12,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-kratos/kratos/v2 v2.0.0-20210608032802-c551448bbd64 h1:+x/Zgv46tYhyhdWgoASZRWQpwuaEoHtNz0PMfwT9svM=
github.com/go-kratos/kratos/v2 v2.0.0-20210608032802-c551448bbd64/go.mod h1:puDEhRv+dqKa4ZdlInEAbO8ibGxqNhAXFjGleIRh9V4=
github.com/go-kratos/kratos/v2 v2.0.0-20210608085308-7585257f9ea1 h1:t6O9azVp+Go2H1B5X9xEFgMj5jogpaL0obRz14ek+B0=
github.com/go-kratos/kratos/v2 v2.0.0-20210608085308-7585257f9ea1/go.mod h1:puDEhRv+dqKa4ZdlInEAbO8ibGxqNhAXFjGleIRh9V4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=

@ -7,7 +7,7 @@ import (
"google.golang.org/protobuf/types/pluginpb"
)
const version = "v2.0.0-beta2"
const version = "v2.0.0-rc1"
func main() {
showVersion := flag.Bool("version", false, "print the version and exit")
@ -17,7 +17,6 @@ func main() {
fmt.Printf("protoc-gen-go-errors %v\n", version)
return
}
//fmt.Println(os.Args, "123123")
var flags flag.FlagSet
protogen.Options{
ParamFunc: flags.Set,

@ -10,10 +10,7 @@ var errorsTemplate = `
func Is{{.CamelValue}}(err error) bool {
e := errors.FromError(err)
if e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == {{.HttpCode}} {
return true
}
return false
return e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == {{.HttpCode}}
}
func Error{{.CamelValue}}(format string, args ...interface{}) *errors.Error {

Loading…
Cancel
Save