Skip to content

Commit

Permalink
fix: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Aug 13, 2024
1 parent f8c2de3 commit d232def
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions internal/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ import "google.golang.org/protobuf/reflect/protoreflect"
type ValType int8

const (
ValTypeString ValType = iota
ValTypeInt ValType = iota
ValTypeFloat ValType = iota
ValTypeBool ValType = iota
ValTypeUndefined ValType = iota
ValTypeString ValType = iota
ValTypeInt ValType = iota
ValTypeFloat ValType = iota
ValTypeBool ValType = iota
)

func createValType(t protoreflect.Kind) ValType {
switch t {
switch t { //nolint: exhaustive // not need
case protoreflect.StringKind:
return ValTypeString
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind,
protoreflect.Sint64Kind, protoreflect.Sfixed64Kind, protoreflect.Uint32Kind, protoreflect.Fixed32Kind,
protoreflect.Uint64Kind:
return ValTypeInt
case protoreflect.FloatKind, protoreflect.DoubleKind:
case protoreflect.FloatKind, protoreflect.DoubleKind, protoreflect.Fixed64Kind:
return ValTypeFloat
case protoreflect.BoolKind:
return ValTypeBool
default:
return ValTypeString
return ValTypeUndefined
}
}
4 changes: 2 additions & 2 deletions templates/handler.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (srv *{{.Service.Name}}) {{.Handler.MethodName }} (

{{if eq .Params.RequestValidator "ozzo"}}
func (srv *{{.Service.Name}}) validate{{.Handler.MethodName }}Request(req *{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsg.Name }}) error {
return validation.Errors{ {{ range .Handler.InputMsg.Properties.Required }}
"{{ .GoName }}" : validation.Validate(req.{{ .GoName }}, validation.Required),{{ end }}
return validation.Errors{ {{ range .Handler.InputMsg.Properties.Required }}{{ if ne .Type 0 }}
"{{ .GoName }}" : validation.Validate(req.{{ .GoName }}, validation.Required),{{ end }}{{ end }}
}.Filter()
}
{{end}}
6 changes: 3 additions & 3 deletions templates/handler_test.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
func Test{{.Handler.MethodName }}(t *testing.T) {
tEnv := newTestEnv()

resp, err := tEnv.service.{{.Handler.MethodName }}(tEnv.ctx, &{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsgStructName }}{ {{ range .Handler.InputMsg.Properties.Required }}
{{ .GoName }}: {{ if eq .Type 0 }}"{{ .ExampleValue }}"{{ else }}{{ .ExampleValue }}{{ end }},{{ end }}
})
resp, err := tEnv.service.{{.Handler.MethodName }}(tEnv.ctx, &{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsgStructName }}{ {{ range .Handler.InputMsg.Properties.Required }}{{ if ne .Type 0 }}
{{ .GoName }}: {{ if eq .Type 1 }}"{{ .ExampleValue }}"{{ else }}{{ .ExampleValue }}{{ end }},{{ end }}
{{ end }}})
require.NoError(t, err)
assert.Equal(t, &{{.Service.APIImportPackage.Alias}}.{{.Handler.InputMsgStructName }}{}, resp)
}

0 comments on commit d232def

Please sign in to comment.