From d3478eea7cc6ccb9f871bdca1dfad5e8497e1ef5 Mon Sep 17 00:00:00 2001 From: rogerogers Date: Thu, 4 Jan 2024 13:36:23 +0800 Subject: [PATCH] style(payment): fix payment lint Signed-off-by: rogerogers --- gomall/app/payment/biz/dal/init.go | 2 +- gomall/app/payment/biz/dal/mysql/init.go | 2 +- gomall/app/payment/biz/dal/redis/init.go | 4 +--- gomall/app/payment/biz/model/payment.go | 3 ++- gomall/app/payment/biz/service/charge.go | 3 +++ gomall/app/payment/biz/service/charge_test.go | 4 ++-- gomall/app/payment/conf/conf.go | 3 +-- gomall/app/payment/handler.go | 1 + gomall/app/payment/infra/mtl/log.go | 2 +- gomall/app/payment/infra/mtl/metric.go | 4 ++-- gomall/app/payment/infra/mtl/tracing.go | 3 ++- gomall/app/payment/rpc/payment/payment_client.go | 1 + gomall/app/payment/rpc/payment/payment_default.go | 1 + 13 files changed, 19 insertions(+), 14 deletions(-) diff --git a/gomall/app/payment/biz/dal/init.go b/gomall/app/payment/biz/dal/init.go index 362fe159..f1cf0aee 100644 --- a/gomall/app/payment/biz/dal/init.go +++ b/gomall/app/payment/biz/dal/init.go @@ -19,6 +19,6 @@ import ( ) func Init() { - //redis.Init() + // redis.Init() mysql.Init() } diff --git a/gomall/app/payment/biz/dal/mysql/init.go b/gomall/app/payment/biz/dal/mysql/init.go index f20b6982..d1c78b5c 100644 --- a/gomall/app/payment/biz/dal/mysql/init.go +++ b/gomall/app/payment/biz/dal/mysql/init.go @@ -41,7 +41,7 @@ func Init() { panic(err) } if os.Getenv("GO_ENV") != "online" { - DB.AutoMigrate( + DB.AutoMigrate( //nolint:errcheck &model.PaymentLog{}, ) } diff --git a/gomall/app/payment/biz/dal/redis/init.go b/gomall/app/payment/biz/dal/redis/init.go index 0ddae2a8..aa422a3c 100644 --- a/gomall/app/payment/biz/dal/redis/init.go +++ b/gomall/app/payment/biz/dal/redis/init.go @@ -21,9 +21,7 @@ import ( "github.com/redis/go-redis/v9" ) -var ( - RedisClient *redis.Client -) +var RedisClient *redis.Client func Init() { RedisClient = redis.NewClient(&redis.Options{ diff --git a/gomall/app/payment/biz/model/payment.go b/gomall/app/payment/biz/model/payment.go index fad95fdd..ffb9c8e9 100644 --- a/gomall/app/payment/biz/model/payment.go +++ b/gomall/app/payment/biz/model/payment.go @@ -16,8 +16,9 @@ package model import ( "context" - "gorm.io/gorm" "time" + + "gorm.io/gorm" ) type PaymentLog struct { diff --git a/gomall/app/payment/biz/service/charge.go b/gomall/app/payment/biz/service/charge.go index 81d3816d..4cf8848c 100644 --- a/gomall/app/payment/biz/service/charge.go +++ b/gomall/app/payment/biz/service/charge.go @@ -50,6 +50,9 @@ func (s *ChargeService) Run(req *payment.ChargeRequest) (resp *payment.ChargeRes } translationId, err := uuid.NewRandom() + if err != nil { + return nil, err + } err = model.CreatePaymentLog(mysql.DB, s.ctx, &model.PaymentLog{ UserId: req.UserId, OrderId: req.OrderId, diff --git a/gomall/app/payment/biz/service/charge_test.go b/gomall/app/payment/biz/service/charge_test.go index 397cce40..c160be4f 100644 --- a/gomall/app/payment/biz/service/charge_test.go +++ b/gomall/app/payment/biz/service/charge_test.go @@ -16,8 +16,9 @@ package service import ( "context" - payment "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment" "testing" + + payment "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment" ) func TestCharge_Run(t *testing.T) { @@ -34,5 +35,4 @@ func TestCharge_Run(t *testing.T) { t.Errorf("unexpected nil response") } // todo: edit your unit test - } diff --git a/gomall/app/payment/conf/conf.go b/gomall/app/payment/conf/conf.go index 343f6a70..917fe67e 100644 --- a/gomall/app/payment/conf/conf.go +++ b/gomall/app/payment/conf/conf.go @@ -15,7 +15,6 @@ package conf import ( - "io/ioutil" "os" "path/filepath" "sync" @@ -79,7 +78,7 @@ func GetConf() *Config { func initConf() { prefix := "conf" confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml")) - content, err := ioutil.ReadFile(confFileRelPath) + content, err := os.ReadFile(confFileRelPath) if err != nil { panic(err) } diff --git a/gomall/app/payment/handler.go b/gomall/app/payment/handler.go index 46aad647..0239c0ab 100644 --- a/gomall/app/payment/handler.go +++ b/gomall/app/payment/handler.go @@ -16,6 +16,7 @@ package main import ( "context" + "github.com/cloudwego/biz-demo/gomall/app/payment/biz/service" payment "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment" ) diff --git a/gomall/app/payment/infra/mtl/log.go b/gomall/app/payment/infra/mtl/log.go index 116347d0..489f3711 100644 --- a/gomall/app/payment/infra/mtl/log.go +++ b/gomall/app/payment/infra/mtl/log.go @@ -39,7 +39,7 @@ func initLog() { FlushInterval: time.Minute, } server.RegisterShutdownHook(func() { - output.Sync() + output.Sync() //nolint:errcheck }) } log := kitexzap.NewLogger(opts...) diff --git a/gomall/app/payment/infra/mtl/metric.go b/gomall/app/payment/infra/mtl/metric.go index c54979b1..d63025c3 100644 --- a/gomall/app/payment/infra/mtl/metric.go +++ b/gomall/app/payment/infra/mtl/metric.go @@ -48,9 +48,9 @@ func initMetric() { _ = r.Register(registryInfo) server.RegisterShutdownHook(func() { - r.Deregister(registryInfo) + r.Deregister(registryInfo) //nolint:errcheck }) http.Handle("/metrics", promhttp.HandlerFor(Registry, promhttp.HandlerOpts{})) - go http.ListenAndServe(conf.GetConf().Kitex.MetricsPort, nil) + go http.ListenAndServe(conf.GetConf().Kitex.MetricsPort, nil) //nolint:errcheck } diff --git a/gomall/app/payment/infra/mtl/tracing.go b/gomall/app/payment/infra/mtl/tracing.go index 873406dc..b4fb0ee0 100644 --- a/gomall/app/payment/infra/mtl/tracing.go +++ b/gomall/app/payment/infra/mtl/tracing.go @@ -16,6 +16,7 @@ package mtl import ( "context" + "github.com/cloudwego/kitex/server" "github.com/cloudwego/biz-demo/gomall/app/payment/conf" @@ -34,7 +35,7 @@ func initTracing() { panic(err) } server.RegisterShutdownHook(func() { - exporter.Shutdown(context.Background()) + exporter.Shutdown(context.Background()) //nolint:errcheck }) processor := tracesdk.NewBatchSpanProcessor(exporter) res, err := resource.New(context.Background(), resource.WithAttributes(semconv.ServiceNameKey.String(conf.GetConf().Kitex.Service))) diff --git a/gomall/app/payment/rpc/payment/payment_client.go b/gomall/app/payment/rpc/payment/payment_client.go index 191658ea..b07e5b81 100644 --- a/gomall/app/payment/rpc/payment/payment_client.go +++ b/gomall/app/payment/rpc/payment/payment_client.go @@ -16,6 +16,7 @@ package payment import ( "context" + payment "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment" "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment/paymentservice" diff --git a/gomall/app/payment/rpc/payment/payment_default.go b/gomall/app/payment/rpc/payment/payment_default.go index 447f038b..0c78be82 100644 --- a/gomall/app/payment/rpc/payment/payment_default.go +++ b/gomall/app/payment/rpc/payment/payment_default.go @@ -16,6 +16,7 @@ package payment import ( "context" + payment "github.com/cloudwego/biz-demo/gomall/app/payment/kitex_gen/payment" "github.com/cloudwego/kitex/client/callopt" "github.com/cloudwego/kitex/pkg/klog"