style: add gosimple linter and gofmt linter (#1242)

pull/1247/head
喵喵大人 3 years ago committed by GitHub
parent f872ec4685
commit d09ba5e3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .golangci.yml
  2. 2
      cmd/kratos/internal/change/change.go
  3. 4
      examples/http/echo/main.go
  4. 2
      examples/i18n/internal/pkg/middleware/localize/localize.go
  5. 6
      examples/i18n/internal/service/greeter.go
  6. 2
      examples/registry/etcd/client/main.go
  7. 2
      metadata/metadata.go
  8. 2
      transport/http/binding/encode.go

@ -8,4 +8,6 @@ linters:
enable: enable:
- revive - revive
- staticcheck - staticcheck
- govet - govet
- gosimple
- gofmt

@ -40,4 +40,4 @@ func run(cmd *cobra.Command, args []string) {
info := api.GetReleaseInfo(version) info := api.GetReleaseInfo(version)
fmt.Print(base.ParseReleaseInfo(info)) fmt.Print(base.ParseReleaseInfo(info))
} }
} }

@ -10,7 +10,7 @@ import (
func main() { func main() {
router := echo.New() router := echo.New()
router.GET("/home", func(ctx echo.Context) error { router.GET("/home", func(ctx echo.Context) error {
return ctx.JSON(200,"Hello echo") return ctx.JSON(200, "Hello echo")
}) })
httpSrv := http.NewServer(http.Address(":8000")) httpSrv := http.NewServer(http.Address(":8000"))
@ -25,4 +25,4 @@ func main() {
if err := app.Run(); err != nil { if err := app.Run(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

@ -32,4 +32,4 @@ func I18N() middleware.Middleware {
func FromContext(ctx context.Context) *i18n.Localizer { func FromContext(ctx context.Context) *i18n.Localizer {
return ctx.Value(localizerKey{}).(*i18n.Localizer) return ctx.Value(localizerKey{}).(*i18n.Localizer)
} }

@ -34,9 +34,9 @@ func (s *GreeterService) SayHello(ctx context.Context, in *v1.HelloRequest) (*v1
helloMsg, err := localizer.Localize(&i18n.LocalizeConfig{ helloMsg, err := localizer.Localize(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{ DefaultMessage: &i18n.Message{
Description: "sayhello", Description: "sayhello",
ID: "sayHello", ID: "sayHello",
One: "Hello {{.Name}}", One: "Hello {{.Name}}",
Other: "Hello {{.Name}}", Other: "Hello {{.Name}}",
}, },
TemplateData: map[string]interface{}{ TemplateData: map[string]interface{}{
"Name": in.Name, "Name": in.Name,

@ -56,4 +56,4 @@ func callHTTP(r *registry.Registry) {
log.Fatal(err) log.Fatal(err)
} }
log.Printf("[http] SayHello %+v\n", reply) log.Printf("[http] SayHello %+v\n", reply)
} }

@ -47,7 +47,7 @@ func (m Metadata) Set(key string, value string) {
func (m Metadata) Range(f func(k, v string) bool) { func (m Metadata) Range(f func(k, v string) bool) {
for k, v := range m { for k, v := range m {
ret := f(k, v) ret := f(k, v)
if ret == false { if !ret {
break break
} }
} }

@ -28,7 +28,7 @@ func EncodeURL(pathTemplate string, msg proto.Message, needQuery bool) string {
if reg == nil { if reg == nil {
return pathTemplate return pathTemplate
} }
pathParams := make(map[string]struct{}, 0) pathParams := make(map[string]struct{})
path := reg.ReplaceAllStringFunc(pathTemplate, func(in string) string { path := reg.ReplaceAllStringFunc(pathTemplate, func(in string) string {
if len(in) < 4 { if len(in) < 4 {
return in return in

Loading…
Cancel
Save