From c7a373ed2e4321257b0429f51915d73a93214651 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Sat, 12 Aug 2023 21:16:00 -0400 Subject: [PATCH 1/3] add support for type meta to service method arguments --- client.go.tmpl | 6 ++--- field.go.tmpl | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ server.go.tmpl | 6 ++--- struct.go.tmpl | 27 ++------------------- type.go.tmpl | 30 ----------------------- types.go.tmpl | 2 +- 6 files changed, 75 insertions(+), 62 deletions(-) create mode 100644 field.go.tmpl delete mode 100644 type.go.tmpl diff --git a/client.go.tmpl b/client.go.tmpl index 0044a3f..dd0ae56 100644 --- a/client.go.tmpl +++ b/client.go.tmpl @@ -35,14 +35,14 @@ func New{{.Name | firstLetterToUpper }}Client(addr string, client HTTPClient) {{ {{- $inputs := $method.Inputs -}} {{- $outputs := $method.Outputs }} -func (c *{{$serviceName}}) {{.Name}}(ctx context.Context{{range $_, $input := $inputs}}, {{$input.Name}} {{template "type" dict "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}}{{end}}) {{if len .Outputs}}({{end}}{{range $i, $output := .Outputs}}{{template "type" dict "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}}{{if lt $i (len $method.Outputs)}}, {{end}}{{end}}error{{if len .Outputs}}){{end}} { +func (c *{{$serviceName}}) {{.Name}}(ctx context.Context{{range $_, $input := $inputs}}, {{$input.Name}} {{template "field" dict "Name" $input.Name "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $input.Meta}}{{end}}) {{if len .Outputs}}({{end}}{{range $i, $output := .Outputs}}{{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta}}{{if lt $i (len $method.Outputs)}}, {{end}}{{end}}error{{if len .Outputs}}){{end}} { {{- $inputVar := "nil" -}} {{- $outputVar := "nil" -}} {{- if $inputs | len}} {{- $inputVar = "in"}} in := struct { {{- range $i, $input := $inputs}} - Arg{{$i}} {{template "type" dict "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} `json:"{{$input.Name}}"` + Arg{{$i}} {{template "field" dict "Name" $input.Name "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $input.Meta "JsonTags" true}} {{- end}} }{ {{- range $i, $input := $inputs}}{{if gt $i 0}}, {{end}}{{$input.Name}}{{end}}} {{- end}} @@ -50,7 +50,7 @@ func (c *{{$serviceName}}) {{.Name}}(ctx context.Context{{range $_, $input := $i {{- $outputVar = "&out"}} out := struct { {{- range $i, $output := .Outputs}} - Ret{{$i}} {{template "type" dict "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} `json:"{{$output.Name}}"` + Ret{{$i}} {{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta "JsonTags" true}} {{- end}} }{} {{- end}} diff --git a/field.go.tmpl b/field.go.tmpl new file mode 100644 index 0000000..b8206c1 --- /dev/null +++ b/field.go.tmpl @@ -0,0 +1,66 @@ +{{- define "field" -}} + +{{- $type := .Type -}} +{{- $name := (coalesce .Name "") -}} +{{- $fieldName := $name | firstLetterToUpper -}} +{{- $typePrefix := .TypePrefix -}} +{{- $typeMeta := .TypeMeta -}} +{{- $typeMap := .TypeMap -}} +{{- $optional := .Optional -}} +{{- $printName := .PrintName -}} +{{- $includeJsonTags := .JsonTags -}} +{{- $includeStructTags := .StructTags -}} + +{{- $customType := "" -}} +{{- $jsonTag := printf "json:%q" $name }} +{{- $structTags := array -}} +{{- range $meta := $typeMeta -}} + {{- if exists $meta "json" -}} + {{- $jsonTag = printf "json:%q" (get $meta "json") -}} + {{- end -}} + {{- if exists $meta "go.field.name" -}} + {{- $fieldName = get $meta "go.field.name" -}} + {{- end -}} + {{- if exists $meta "go.field.type" -}} + {{- $customType = get $meta "go.field.type" -}} + {{- end -}} + {{- if exists $meta "go.tag.json" -}} + {{- $jsonTag = printf "json:%q" (get $meta "go.tag.json") -}} + {{- end -}} + {{- range $metaKey, $metaValue := $meta -}} + {{- if and (hasPrefix $metaKey "go.tag.") (ne $metaKey "go.tag.json") -}} + {{- $structTags = append $structTags (printf "%s:%q" (trimPrefix $metaKey "go.tag.") $metaValue) -}} + {{- end -}} + {{- end -}} +{{- end }} + +{{- if $printName -}} +{{$fieldName}}{{" "}} +{{- end -}} +{{- if (ne $customType "") -}} + + {{$customType}} + +{{- else if isMapType $type -}} + + map[{{mapKeyType $type}}]{{template "field" dict "Name" $name "Type" (mapValueType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $typeMeta}} + +{{- else if isListType $type -}} + + []{{template "field" dict "Name" $name "Type" (listElemType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $typeMeta}} + +{{- else if isCoreType $type -}} + + {{if $optional}}*{{end}}{{ get $typeMap $type }} + +{{- else -}}{{- /* structs */ -}} + + *{{$typePrefix}}{{$type}} + +{{- end -}} + +{{- if $includeJsonTags -}} +`{{$jsonTag}}{{if and $includeStructTags (len $structTags)}} {{join (sort $structTags) " "}}{{end}}` +{{- end -}} + +{{- end -}} \ No newline at end of file diff --git a/server.go.tmpl b/server.go.tmpl index 5536070..c3bcefc 100644 --- a/server.go.tmpl +++ b/server.go.tmpl @@ -72,7 +72,7 @@ func (s *{{$serviceName}}) serve{{ .Name | firstLetterToUpper }}JSON(ctx context {{- if .Inputs|len}} reqContent := struct { {{- range $i, $input := .Inputs}} - Arg{{$i}} {{template "type" dict "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} `json:"{{$input.Name}}"` + Arg{{$i}} {{template "field" dict "Name" $input.Name "Type" $input.Type "Optional" $input.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $input.Meta "JsonTags" true}} {{- end}} }{} @@ -94,7 +94,7 @@ func (s *{{$serviceName}}) serve{{ .Name | firstLetterToUpper }}JSON(ctx context // Call service method {{- range $i, $output := .Outputs}} - var ret{{$i}} {{template "type" dict "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} + var ret{{$i}} {{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta}} {{- end}} func() { defer func() { @@ -109,7 +109,7 @@ func (s *{{$serviceName}}) serve{{ .Name | firstLetterToUpper }}JSON(ctx context {{- if .Outputs | len}} respContent := struct { {{- range $i, $output := .Outputs}} - Ret{{$i}} {{template "type" dict "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} `json:"{{$output.Name}}"` + Ret{{$i}} {{template "field" dict "Name" $output.Name "Type" $output.Type "Optional" $output.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $output.Meta "JsonTags" true}} {{- end}} }{ {{- range $i, $_ := .Outputs}}{{if gt $i 0}}, {{end}}ret{{$i}}{{end}}} {{- end}} diff --git a/struct.go.tmpl b/struct.go.tmpl index b0c6850..f3a55c8 100644 --- a/struct.go.tmpl +++ b/struct.go.tmpl @@ -7,30 +7,7 @@ type {{$name}} struct { {{- range $_, $field := $fields -}} - {{- $fieldName := $field.Name | firstLetterToUpper -}} - {{- $customType := "" -}} - {{- $jsonTag := printf "json:%q" $field.Name }} - {{- $structTags := array -}} - {{- range $meta := $field.Meta -}} - {{- if exists $meta "json" -}} - {{- $jsonTag = printf "json:%q" (get $meta "json") -}} - {{- end -}} - {{- if exists $meta "go.field.name" -}} - {{- $fieldName = get $meta "go.field.name" -}} - {{- end -}} - {{- if exists $meta "go.field.type" -}} - {{- $customType = get $meta "go.field.type" -}} - {{- end -}} - {{- if exists $meta "go.tag.json" -}} - {{- $jsonTag = printf "json:%q" (get $meta "go.tag.json") -}} - {{- end -}} - {{- range $metaKey, $metaValue := $meta -}} - {{- if and (hasPrefix $metaKey "go.tag.") (ne $metaKey "go.tag.json") -}} - {{- $structTags = append $structTags (printf "%s:%q" (trimPrefix $metaKey "go.tag.") $metaValue) -}} - {{- end -}} - {{- end -}} - {{- end }} - {{$fieldName}} {{template "type" dict "Type" $field.Type "CustomType" $customType "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix}} `{{$jsonTag}}{{if len $structTags}} {{end}}{{join (sort $structTags) " "}}` -{{- end}} + {{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true}} +{{end}} } {{- end }} diff --git a/type.go.tmpl b/type.go.tmpl deleted file mode 100644 index 47aced2..0000000 --- a/type.go.tmpl +++ /dev/null @@ -1,30 +0,0 @@ -{{- define "type" -}} - -{{- $type := .Type -}} -{{- $typePrefix := .TypePrefix -}} -{{- $customType := (coalesce .CustomType "") -}} -{{- $typeMap := .TypeMap -}} -{{- $optional := .Optional -}} - -{{- if (ne $customType "") -}} - - {{$customType}} - -{{- else if isMapType $type -}} - - map[{{mapKeyType $type}}]{{template "type" dict "Type" (mapValueType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix}} - -{{- else if isListType $type -}} - - []{{template "type" dict "Type" (listElemType $type) "CustomType" $customType "TypeMap" $typeMap "TypePrefix" $typePrefix}} - -{{- else if isCoreType $type -}} - - {{if $optional}}*{{end}}{{ get $typeMap $type }} - -{{- else -}}{{- /* structs */ -}} - - *{{$typePrefix}}{{$type}} - -{{- end -}} -{{- end -}} \ No newline at end of file diff --git a/types.go.tmpl b/types.go.tmpl index 53c5a7e..5333312 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -26,7 +26,7 @@ {{ range $_, $service := $services}} type {{$service.Name}} interface { {{- range $_, $method := $service.Methods}} - {{.Name}}(ctx context.Context{{range $_, $input := $method.Inputs}}, {{$input.Name}} {{template "type" dict "Type" $input.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $input.Optional}}{{end}}) {{if len .Outputs}}({{end}}{{range $i, $output := .Outputs}}{{template "type" dict "Type" $output.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $output.Optional}}{{if lt $i (len $method.Outputs)}}, {{end}}{{end}}error{{if len $method.Outputs}}){{end}} + {{.Name}}(ctx context.Context{{range $_, $input := $method.Inputs}}, {{$input.Name}} {{template "field" dict "Name" $input.Name "Type" $input.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $input.Optional "TypeMeta" $input.Meta}}{{end}}) {{if len .Outputs}}({{end}}{{range $i, $output := .Outputs}}{{template "field" dict "Name" $output.Name "Type" $output.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $output.Optional "TypeMeta" $output.Meta}}{{if lt $i (len $method.Outputs)}}, {{end}}{{end}}error{{if len $method.Outputs}}){{end}} {{- end}} } {{end}} From 92419223067e803f48dcfed77ba7c66531c77d93 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Sat, 12 Aug 2023 22:00:15 -0400 Subject: [PATCH 2/3] update --- struct.go.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/struct.go.tmpl b/struct.go.tmpl index f3a55c8..a83d714 100644 --- a/struct.go.tmpl +++ b/struct.go.tmpl @@ -6,7 +6,7 @@ {{- $typePrefix := .TypePrefix -}} type {{$name}} struct { -{{- range $_, $field := $fields -}} +{{range $_, $field := $fields -}} {{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true}} {{end}} } From 37884f24ac831e59acf7a83ff3b5e2c4441790d5 Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Sat, 12 Aug 2023 22:14:35 -0400 Subject: [PATCH 3/3] update --- _examples/golang-basics/example.gen.go | 112 ++++++++++++------------- _examples/golang-basics/main.go | 2 +- 2 files changed, 56 insertions(+), 58 deletions(-) diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index 2877c8c..a81b62e 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -2,10 +2,9 @@ // -- // Code generated by webrpc-gen@v0.13.0-dev with ../../../gen-golang generator. DO NOT EDIT. // -// webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -out=./example.gen.go -fmt=false -legacyErrors=true +// webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -out=./example.gen.go -legacyErrors=true package main - import ( "bytes" "context" @@ -44,7 +43,7 @@ func WebRPCSchemaHash() string { type Kind uint32 const ( - Kind_USER Kind = 0 + Kind_USER Kind = 0 Kind_ADMIN Kind = 1 ) @@ -54,7 +53,7 @@ var Kind_name = map[uint32]string{ } var Kind_value = map[string]uint32{ - "USER": 0, + "USER": 0, "ADMIN": 1, } @@ -72,19 +71,19 @@ func (x *Kind) UnmarshalText(b []byte) error { } type User struct { - ID uint64 `json:"id" db:"id"` - Uuid uuid.UUID `json:"uuid" db:"id"` - Username string `json:"USERNAME" db:"username"` - Role string `json:"role" db:"-"` + ID uint64 `json:"id" db:"id"` + Uuid uuid.UUID `json:"uuid" db:"id"` + Username string `json:"USERNAME" db:"username"` + Role string `json:"role" db:"-"` Nicknames []Nickname `json:"nicknames" db:"-"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt *time.Time `json:"updatedAt" db:"updated_at"` } type Nickname struct { - ID uint64 `json:"ID" db:"id"` - Nickname string `json:"nickname" db:"nickname"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` + ID uint64 `json:"ID" db:"id"` + Nickname string `json:"nickname" db:"nickname"` + CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt *time.Time `json:"updatedAt" db:"updated_at"` } @@ -95,19 +94,19 @@ type SearchFilter struct { type Version struct { WebrpcVersion string `json:"webrpcVersion"` SchemaVersion string `json:"schemaVersion"` - SchemaHash string `json:"schemaHash"` + SchemaHash string `json:"schemaHash"` } type ComplexType struct { - Meta map[string]interface{} `json:"meta"` + Meta map[string]interface{} `json:"meta"` MetaNestedExample map[string]map[string]uint32 `json:"metaNestedExample"` - NamesList []string `json:"namesList"` - NumsList []int64 `json:"numsList"` - DoubleArray [][]string `json:"doubleArray"` - ListOfMaps []map[string]uint32 `json:"listOfMaps"` - ListOfUsers []*User `json:"listOfUsers"` - MapOfUsers map[string]*User `json:"mapOfUsers"` - User *User `json:"user"` + NamesList []string `json:"namesList"` + NumsList []int64 `json:"numsList"` + DoubleArray [][]string `json:"doubleArray"` + ListOfMaps []map[string]uint32 `json:"listOfMaps"` + ListOfUsers []*User `json:"listOfUsers"` + MapOfUsers map[string]*User `json:"mapOfUsers"` + User *User `json:"user"` } type ExampleService interface { @@ -348,7 +347,7 @@ func (s *exampleServiceServer) serveGetUserJSON(ctx context.Context, w http.Resp ctx = context.WithValue(ctx, MethodNameCtxKey, "GetUser") reqContent := struct { Arg0 map[string]string `json:"header"` - Arg1 uint64 `json:"userID"` + Arg1 uint64 `json:"userID"` }{} reqBody, err := ioutil.ReadAll(r.Body) @@ -451,7 +450,7 @@ func (s *exampleServiceServer) serveFindUserJSON(ctx context.Context, w http.Res }() respContent := struct { Ret0 string `json:"name"` - Ret1 *User `json:"user"` + Ret1 *User `json:"user"` }{ret0, ret1} if err != nil { @@ -491,7 +490,7 @@ const ExampleServicePathPrefix = "/rpc/ExampleService/" type exampleServiceClient struct { client HTTPClient - urls [5]string + urls [5]string } func NewExampleServiceClient(addr string, client HTTPClient) ExampleService { @@ -505,7 +504,7 @@ func NewExampleServiceClient(addr string, client HTTPClient) ExampleService { } return &exampleServiceClient{ client: client, - urls: urls, + urls: urls, } } @@ -536,7 +535,7 @@ func (c *exampleServiceClient) Version(ctx context.Context) (*Version, error) { func (c *exampleServiceClient) GetUser(ctx context.Context, header map[string]string, userID uint64) (*User, error) { in := struct { Arg0 map[string]string `json:"header"` - Arg1 uint64 `json:"userID"` + Arg1 uint64 `json:"userID"` }{header, userID} out := struct { Ret0 *User `json:"user"` @@ -552,7 +551,7 @@ func (c *exampleServiceClient) FindUser(ctx context.Context, s *SearchFilter) (s }{s} out := struct { Ret0 string `json:"name"` - Ret1 *User `json:"user"` + Ret1 *User `json:"user"` }{} err := doJSONRequest(ctx, c.client, c.urls[4], in, &out) @@ -757,13 +756,13 @@ func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError { // Webrpc errors var ( - ErrWebrpcEndpoint = WebRPCError{Code: 0, Name: "WebrpcEndpoint", Message: "endpoint error", HTTPStatus: 400} + ErrWebrpcEndpoint = WebRPCError{Code: 0, Name: "WebrpcEndpoint", Message: "endpoint error", HTTPStatus: 400} ErrWebrpcRequestFailed = WebRPCError{Code: -1, Name: "WebrpcRequestFailed", Message: "request failed", HTTPStatus: 400} - ErrWebrpcBadRoute = WebRPCError{Code: -2, Name: "WebrpcBadRoute", Message: "bad route", HTTPStatus: 404} - ErrWebrpcBadMethod = WebRPCError{Code: -3, Name: "WebrpcBadMethod", Message: "bad method", HTTPStatus: 405} - ErrWebrpcBadRequest = WebRPCError{Code: -4, Name: "WebrpcBadRequest", Message: "bad request", HTTPStatus: 400} - ErrWebrpcBadResponse = WebRPCError{Code: -5, Name: "WebrpcBadResponse", Message: "bad response", HTTPStatus: 500} - ErrWebrpcServerPanic = WebRPCError{Code: -6, Name: "WebrpcServerPanic", Message: "server panic", HTTPStatus: 500} + ErrWebrpcBadRoute = WebRPCError{Code: -2, Name: "WebrpcBadRoute", Message: "bad route", HTTPStatus: 404} + ErrWebrpcBadMethod = WebRPCError{Code: -3, Name: "WebrpcBadMethod", Message: "bad method", HTTPStatus: 405} + ErrWebrpcBadRequest = WebRPCError{Code: -4, Name: "WebrpcBadRequest", Message: "bad request", HTTPStatus: 400} + ErrWebrpcBadResponse = WebRPCError{Code: -5, Name: "WebrpcBadResponse", Message: "bad response", HTTPStatus: 500} + ErrWebrpcServerPanic = WebRPCError{Code: -6, Name: "WebrpcServerPanic", Message: "server panic", HTTPStatus: 500} ErrWebrpcInternalError = WebRPCError{Code: -7, Name: "WebrpcInternalError", Message: "internal error", HTTPStatus: 500} ) @@ -771,9 +770,9 @@ var ( var ( ErrMissingArgument = WebRPCError{Code: 500100, Name: "MissingArgument", Message: "missing argument", HTTPStatus: 400} ErrInvalidUsername = WebRPCError{Code: 500101, Name: "InvalidUsername", Message: "invalid username", HTTPStatus: 400} - ErrMemoryFull = WebRPCError{Code: 400100, Name: "MemoryFull", Message: "system memory is full", HTTPStatus: 400} - ErrUnauthorized = WebRPCError{Code: 400200, Name: "Unauthorized", Message: "unauthorized", HTTPStatus: 401} - ErrUserNotFound = WebRPCError{Code: 400300, Name: "UserNotFound", Message: "user not found", HTTPStatus: 400} + ErrMemoryFull = WebRPCError{Code: 400100, Name: "MemoryFull", Message: "system memory is full", HTTPStatus: 400} + ErrUnauthorized = WebRPCError{Code: 400200, Name: "Unauthorized", Message: "unauthorized", HTTPStatus: 401} + ErrUserNotFound = WebRPCError{Code: 400300, Name: "UserNotFound", Message: "user not found", HTTPStatus: 400} ) // @@ -820,47 +819,46 @@ func ErrorInternal(format string, args ...interface{}) WebRPCError { return Errorf(ErrInternal, format, args...) } -type legacyError struct { WebRPCError } +type legacyError struct{ WebRPCError } // Legacy errors (webrpc v0.10.0 and earlier). Will be removed. var ( // Deprecated. Define errors in RIDL schema. - ErrCanceled = legacyError{WebRPCError{Code: -10000, Name: "ErrCanceled", Message: "canceled", HTTPStatus: 408 /* RequestTimeout */ }} + ErrCanceled = legacyError{WebRPCError{Code: -10000, Name: "ErrCanceled", Message: "canceled", HTTPStatus: 408 /* RequestTimeout */}} // Deprecated. Define errors in RIDL schema. - ErrUnknown = legacyError{WebRPCError{Code: -10001, Name: "ErrUnknown", Message: "unknown", HTTPStatus: 400 /* Bad Request */ }} + ErrUnknown = legacyError{WebRPCError{Code: -10001, Name: "ErrUnknown", Message: "unknown", HTTPStatus: 400 /* Bad Request */}} // Deprecated. Define errors in RIDL schema. - ErrFail = legacyError{WebRPCError{Code: -10002, Name: "ErrFail", Message: "fail", HTTPStatus: 422 /* Unprocessable Entity */ }} + ErrFail = legacyError{WebRPCError{Code: -10002, Name: "ErrFail", Message: "fail", HTTPStatus: 422 /* Unprocessable Entity */}} // Deprecated. Define errors in RIDL schema. - ErrInvalidArgument = legacyError{WebRPCError{Code: -10003, Name: "ErrInvalidArgument", Message: "invalid argument", HTTPStatus: 400 /* BadRequest */ }} + ErrInvalidArgument = legacyError{WebRPCError{Code: -10003, Name: "ErrInvalidArgument", Message: "invalid argument", HTTPStatus: 400 /* BadRequest */}} // Deprecated. Define errors in RIDL schema. - ErrDeadlineExceeded = legacyError{WebRPCError{Code: -10004, Name: "ErrDeadlineExceeded", Message: "deadline exceeded", HTTPStatus: 408 /* RequestTimeout */ }} + ErrDeadlineExceeded = legacyError{WebRPCError{Code: -10004, Name: "ErrDeadlineExceeded", Message: "deadline exceeded", HTTPStatus: 408 /* RequestTimeout */}} // Deprecated. Define errors in RIDL schema. - ErrNotFound = legacyError{WebRPCError{Code: -10005, Name: "ErrNotFound", Message: "not found", HTTPStatus: 404 /* Not Found */ }} + ErrNotFound = legacyError{WebRPCError{Code: -10005, Name: "ErrNotFound", Message: "not found", HTTPStatus: 404 /* Not Found */}} // Deprecated. Define errors in RIDL schema. - ErrBadRoute = legacyError{WebRPCError{Code: -10006, Name: "ErrBadRoute", Message: "bad route", HTTPStatus: 404 /* Not Found */ }} + ErrBadRoute = legacyError{WebRPCError{Code: -10006, Name: "ErrBadRoute", Message: "bad route", HTTPStatus: 404 /* Not Found */}} // Deprecated. Define errors in RIDL schema. - ErrAlreadyExists = legacyError{WebRPCError{Code: -10007, Name: "ErrAlreadyExists", Message: "already exists", HTTPStatus: 409 /* Conflict */ }} + ErrAlreadyExists = legacyError{WebRPCError{Code: -10007, Name: "ErrAlreadyExists", Message: "already exists", HTTPStatus: 409 /* Conflict */}} // Deprecated. Define errors in RIDL schema. - ErrPermissionDenied = legacyError{WebRPCError{Code: -10008, Name: "ErrPermissionDenied", Message: "permission denied", HTTPStatus: 403 /* Forbidden */ }} + ErrPermissionDenied = legacyError{WebRPCError{Code: -10008, Name: "ErrPermissionDenied", Message: "permission denied", HTTPStatus: 403 /* Forbidden */}} // Deprecated. Define errors in RIDL schema. - ErrUnauthenticated = legacyError{WebRPCError{Code: -10009, Name: "ErrUnauthenticated", Message: "unauthenticated", HTTPStatus: 401 /* Unauthorized */ }} + ErrUnauthenticated = legacyError{WebRPCError{Code: -10009, Name: "ErrUnauthenticated", Message: "unauthenticated", HTTPStatus: 401 /* Unauthorized */}} // Deprecated. Define errors in RIDL schema. - ErrResourceExhausted = legacyError{WebRPCError{Code: -10010, Name: "ErrResourceExhausted", Message: "resource exhausted", HTTPStatus: 403 /* Forbidden */ }} + ErrResourceExhausted = legacyError{WebRPCError{Code: -10010, Name: "ErrResourceExhausted", Message: "resource exhausted", HTTPStatus: 403 /* Forbidden */}} // Deprecated. Define errors in RIDL schema. - ErrFailedPrecondition = legacyError{WebRPCError{Code: -10011, Name: "ErrFailedPrecondition", Message: "failed precondition", HTTPStatus: 412 /* Precondition Failed */ }} + ErrFailedPrecondition = legacyError{WebRPCError{Code: -10011, Name: "ErrFailedPrecondition", Message: "failed precondition", HTTPStatus: 412 /* Precondition Failed */}} // Deprecated. Define errors in RIDL schema. - ErrAborted = legacyError{WebRPCError{Code: -10012, Name: "ErrAborted", Message: "aborted", HTTPStatus: 409 /* Conflict */ }} + ErrAborted = legacyError{WebRPCError{Code: -10012, Name: "ErrAborted", Message: "aborted", HTTPStatus: 409 /* Conflict */}} // Deprecated. Define errors in RIDL schema. - ErrOutOfRange = legacyError{WebRPCError{Code: -10013, Name: "ErrOutOfRange", Message: "out of range", HTTPStatus: 400 /* Bad Request */ }} + ErrOutOfRange = legacyError{WebRPCError{Code: -10013, Name: "ErrOutOfRange", Message: "out of range", HTTPStatus: 400 /* Bad Request */}} // Deprecated. Define errors in RIDL schema. - ErrUnimplemented = legacyError{WebRPCError{Code: -10014, Name: "ErrUnimplemented", Message: "unimplemented", HTTPStatus: 501 /* Not Implemented */ }} + ErrUnimplemented = legacyError{WebRPCError{Code: -10014, Name: "ErrUnimplemented", Message: "unimplemented", HTTPStatus: 501 /* Not Implemented */}} // Deprecated. Define errors in RIDL schema. - ErrInternal = legacyError{WebRPCError{Code: -10015, Name: "ErrInternal", Message: "internal", HTTPStatus: 500 /* Internal Server Error */ }} + ErrInternal = legacyError{WebRPCError{Code: -10015, Name: "ErrInternal", Message: "internal", HTTPStatus: 500 /* Internal Server Error */}} // Deprecated. Define errors in RIDL schema. - ErrUnavailable = legacyError{WebRPCError{Code: -10016, Name: "ErrUnavailable", Message: "unavailable", HTTPStatus: 503 /* Service Unavailable */ }} + ErrUnavailable = legacyError{WebRPCError{Code: -10016, Name: "ErrUnavailable", Message: "unavailable", HTTPStatus: 503 /* Service Unavailable */}} // Deprecated. Define errors in RIDL schema. - ErrDataLoss = legacyError{WebRPCError{Code: -10017, Name: "ErrDataLoss", Message: "data loss", HTTPStatus: 500 /* Internal Server Error */ }} + ErrDataLoss = legacyError{WebRPCError{Code: -10017, Name: "ErrDataLoss", Message: "data loss", HTTPStatus: 500 /* Internal Server Error */}} // Deprecated. Define errors in RIDL schema. - ErrNone = legacyError{WebRPCError{Code: -10018, Name: "ErrNone", Message: "", HTTPStatus: 200 /* OK */ }} + ErrNone = legacyError{WebRPCError{Code: -10018, Name: "ErrNone", Message: "", HTTPStatus: 200 /* OK */}} ) - diff --git a/_examples/golang-basics/main.go b/_examples/golang-basics/main.go index 28c8743..923826a 100644 --- a/_examples/golang-basics/main.go +++ b/_examples/golang-basics/main.go @@ -1,4 +1,4 @@ -//go:generate webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -out=./example.gen.go -fmt=false -legacyErrors=true +//go:generate webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -out=./example.gen.go -legacyErrors=true package main import (