From b8b64302d67f8b740cfe8a5be8f3cdf3c85dd918 Mon Sep 17 00:00:00 2001 From: "daniel.w" Date: Thu, 5 Sep 2024 03:09:48 +0800 Subject: [PATCH] golint --- .golangci.yaml | 8 +++++ Makefile | 1 + client/senderservice/sender_service.go | 20 ++++++------ generate/protobuf/notification.proto | 8 ++--- internal/domain/errors.go | 11 +++---- .../send_mail_by_template_i_d_logic.go | 31 +++++++++++++++++++ .../send_mail_by_template_id_logic.go | 29 ----------------- ...c.go => send_sms_by_template_i_d_logic.go} | 10 +++--- .../senderservice/sender_service_server.go | 17 +++++----- internal/svc/service_context.go | 1 + internal/usecase/mitake.go | 1 + notification.go | 7 ++--- 12 files changed, 76 insertions(+), 68 deletions(-) create mode 100644 internal/logic/senderservice/send_mail_by_template_i_d_logic.go delete mode 100644 internal/logic/senderservice/send_mail_by_template_id_logic.go rename internal/logic/senderservice/{send_sms_by_template_id_logic.go => send_sms_by_template_i_d_logic.go} (55%) diff --git a/.golangci.yaml b/.golangci.yaml index 5518484..c9726ca 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -117,6 +117,14 @@ issues: - gocognit - contextcheck + exclude-dirs: + - internal/model + + exclude-files: + - .*_test.go + + + linters-settings: gci: sections: diff --git a/Makefile b/Makefile index 785dc15..61fc00b 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ test: # 進行測試 fmt: # 格式優化 $(GOFMT) -w $(GOFILES) goimports -w ./ + golangci-lint run .PHONY: gen-rpc gen-rpc: # 建立 rpc code diff --git a/client/senderservice/sender_service.go b/client/senderservice/sender_service.go index bbc3d18..47179be 100644 --- a/client/senderservice/sender_service.go +++ b/client/senderservice/sender_service.go @@ -24,10 +24,10 @@ type ( SendMail(ctx context.Context, in *SendMailReq, opts ...grpc.CallOption) (*OKResp, error) // SendSms 寄簡訊 SendSms(ctx context.Context, in *SendSMSReq, opts ...grpc.CallOption) (*OKResp, error) - // SendMailByTemplateId 寄送模板信件 - SendMailByTemplateId(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) - // SendSmsByTemplateId 寄送模板簡訊 - SendSmsByTemplateId(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) + // SendMailByTemplateID 寄送模板信件 + SendMailByTemplateID(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) + // SendSmsByTemplateID 寄送模板簡訊 + SendSmsByTemplateID(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) } defaultSenderService struct { @@ -53,14 +53,14 @@ func (m *defaultSenderService) SendSms(ctx context.Context, in *SendSMSReq, opts return client.SendSms(ctx, in, opts...) } -// SendMailByTemplateId 寄送模板信件 -func (m *defaultSenderService) SendMailByTemplateId(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) { +// SendMailByTemplateID 寄送模板信件 +func (m *defaultSenderService) SendMailByTemplateID(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) { client := notification.NewSenderServiceClient(m.cli.Conn()) - return client.SendMailByTemplateId(ctx, in, opts...) + return client.SendMailByTemplateID(ctx, in, opts...) } -// SendSmsByTemplateId 寄送模板簡訊 -func (m *defaultSenderService) SendSmsByTemplateId(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) { +// SendSmsByTemplateID 寄送模板簡訊 +func (m *defaultSenderService) SendSmsByTemplateID(ctx context.Context, in *SendByTemplateIDReq, opts ...grpc.CallOption) (*OKResp, error) { client := notification.NewSenderServiceClient(m.cli.Conn()) - return client.SendSmsByTemplateId(ctx, in, opts...) + return client.SendSmsByTemplateID(ctx, in, opts...) } diff --git a/generate/protobuf/notification.proto b/generate/protobuf/notification.proto index e3d5304..c62b619 100644 --- a/generate/protobuf/notification.proto +++ b/generate/protobuf/notification.proto @@ -35,10 +35,10 @@ service SenderService { rpc SendMail(SendMailReq) returns(OKResp); // SendSms 寄簡訊 rpc SendSms(SendSMSReq) returns(OKResp); - // SendMailByTemplateId 寄送模板信件 - rpc SendMailByTemplateId(SendByTemplateIDReq) returns(OKResp); - // SendSmsByTemplateId 寄送模板簡訊 - rpc SendSmsByTemplateId(SendByTemplateIDReq) returns(OKResp); + // SendMailByTemplateID 寄送模板信件 + rpc SendMailByTemplateID(SendByTemplateIDReq) returns(OKResp); + // SendSmsByTemplateID 寄送模板簡訊 + rpc SendSmsByTemplateID(SendByTemplateIDReq) returns(OKResp); } diff --git a/internal/domain/errors.go b/internal/domain/errors.go index b6d54f0..6d55c93 100644 --- a/internal/domain/errors.go +++ b/internal/domain/errors.go @@ -1,7 +1,6 @@ package domain import ( - "fmt" "strings" "code.30cm.net/digimon/library-go/errs" @@ -24,14 +23,13 @@ const ( // SendMailError ... func SendMailError(s ...string) *errs.LibError { return errs.NewError(code.CloudEPNotification, code.ThirdParty, - SendMailErrorCode.ToUint32(), - fmt.Sprintf("%s", strings.Join(s, " "))) + SendMailErrorCode.ToUint32(), strings.Join(s, " ")) } // SendMailErrorL logs error message and returns Err func SendMailErrorL(l logx.Logger, filed []logx.LogField, s ...string) *errs.LibError { e := SendMailError(s...) - if filed != nil || len(filed) >= 0 { + if filed != nil || len(filed) > 0 { l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) } l.WithCallerSkip(1).Error(e.Error()) @@ -42,14 +40,13 @@ func SendMailErrorL(l logx.Logger, filed []logx.LogField, s ...string) *errs.Lib // SendSMSError ... func SendSMSError(s ...string) *errs.LibError { return errs.NewError(code.CloudEPNotification, code.ThirdParty, - SendSMSErrorCode.ToUint32(), - fmt.Sprintf("%s", strings.Join(s, " "))) + SendSMSErrorCode.ToUint32(), strings.Join(s, " ")) } // SendSMSErrorL logs error message and returns Err func SendSMSErrorL(l logx.Logger, filed []logx.LogField, s ...string) *errs.LibError { e := SendSMSError(s...) - if filed != nil || len(filed) >= 0 { + if filed != nil || len(filed) > 0 { l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) } l.WithCallerSkip(1).Error(e.Error()) diff --git a/internal/logic/senderservice/send_mail_by_template_i_d_logic.go b/internal/logic/senderservice/send_mail_by_template_i_d_logic.go new file mode 100644 index 0000000..9fb59e5 --- /dev/null +++ b/internal/logic/senderservice/send_mail_by_template_i_d_logic.go @@ -0,0 +1,31 @@ +package senderservicelogic + +import ( + "context" + + "app-cloudep-notification-service/gen_result/pb/notification" + "app-cloudep-notification-service/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type SendMailByTemplateIDLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewSendMailByTemplateIDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendMailByTemplateIDLogic { + return &SendMailByTemplateIDLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// SendMailByTemplateID 寄送模板信件 +func (l *SendMailByTemplateIDLogic) SendMailByTemplateID(_ *notification.SendByTemplateIDReq) (*notification.OKResp, error) { + // todo: add your logic here and delete this line + + return ¬ification.OKResp{}, nil +} diff --git a/internal/logic/senderservice/send_mail_by_template_id_logic.go b/internal/logic/senderservice/send_mail_by_template_id_logic.go deleted file mode 100644 index 08f53ae..0000000 --- a/internal/logic/senderservice/send_mail_by_template_id_logic.go +++ /dev/null @@ -1,29 +0,0 @@ -package senderservicelogic - -import ( - "app-cloudep-notification-service/gen_result/pb/notification" - "app-cloudep-notification-service/internal/svc" - "context" - - "github.com/zeromicro/go-zero/core/logx" -) - -type SendMailByTemplateIdLogic struct { - ctx context.Context - svcCtx *svc.ServiceContext - logx.Logger -} - -func NewSendMailByTemplateIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendMailByTemplateIdLogic { - return &SendMailByTemplateIdLogic{ - ctx: ctx, - svcCtx: svcCtx, - Logger: logx.WithContext(ctx), - } -} - -// SendMailByTemplateId 寄送模板信件 -func (l *SendMailByTemplateIdLogic) SendMailByTemplateId(in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { - - return ¬ification.OKResp{}, nil -} diff --git a/internal/logic/senderservice/send_sms_by_template_id_logic.go b/internal/logic/senderservice/send_sms_by_template_i_d_logic.go similarity index 55% rename from internal/logic/senderservice/send_sms_by_template_id_logic.go rename to internal/logic/senderservice/send_sms_by_template_i_d_logic.go index 0ec19d2..ee22dd3 100644 --- a/internal/logic/senderservice/send_sms_by_template_id_logic.go +++ b/internal/logic/senderservice/send_sms_by_template_i_d_logic.go @@ -9,22 +9,22 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type SendSmsByTemplateIdLogic struct { +type SendSmsByTemplateIDLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } -func NewSendSmsByTemplateIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsByTemplateIdLogic { - return &SendSmsByTemplateIdLogic{ +func NewSendSmsByTemplateIDLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsByTemplateIDLogic { + return &SendSmsByTemplateIDLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } -// SendSmsByTemplateId 寄送模板簡訊 -func (l *SendSmsByTemplateIdLogic) SendSmsByTemplateId(in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { +// SendSmsByTemplateID 寄送模板簡訊 +func (l *SendSmsByTemplateIDLogic) SendSmsByTemplateID(_ *notification.SendByTemplateIDReq) (*notification.OKResp, error) { // todo: add your logic here and delete this line return ¬ification.OKResp{}, nil diff --git a/internal/server/senderservice/sender_service_server.go b/internal/server/senderservice/sender_service_server.go index 6c1ead4..51f85f5 100644 --- a/internal/server/senderservice/sender_service_server.go +++ b/internal/server/senderservice/sender_service_server.go @@ -8,7 +8,6 @@ import ( "app-cloudep-notification-service/gen_result/pb/notification" senderservicelogic "app-cloudep-notification-service/internal/logic/senderservice" - "app-cloudep-notification-service/internal/svc" ) @@ -35,14 +34,14 @@ func (s *SenderServiceServer) SendSms(ctx context.Context, in *notification.Send return l.SendSms(in) } -// SendMailByTemplateId 寄送模板信件 -func (s *SenderServiceServer) SendMailByTemplateId(ctx context.Context, in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { - l := senderservicelogic.NewSendMailByTemplateIdLogic(ctx, s.svcCtx) - return l.SendMailByTemplateId(in) +// SendMailByTemplateID 寄送模板信件 +func (s *SenderServiceServer) SendMailByTemplateID(ctx context.Context, in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { + l := senderservicelogic.NewSendMailByTemplateIDLogic(ctx, s.svcCtx) + return l.SendMailByTemplateID(in) } -// SendSmsByTemplateId 寄送模板簡訊 -func (s *SenderServiceServer) SendSmsByTemplateId(ctx context.Context, in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { - l := senderservicelogic.NewSendSmsByTemplateIdLogic(ctx, s.svcCtx) - return l.SendSmsByTemplateId(in) +// SendSmsByTemplateID 寄送模板簡訊 +func (s *SenderServiceServer) SendSmsByTemplateID(ctx context.Context, in *notification.SendByTemplateIDReq) (*notification.OKResp, error) { + l := senderservicelogic.NewSendSmsByTemplateIDLogic(ctx, s.svcCtx) + return l.SendSmsByTemplateID(in) } diff --git a/internal/svc/service_context.go b/internal/svc/service_context.go index d5a59dc..40c0510 100644 --- a/internal/svc/service_context.go +++ b/internal/svc/service_context.go @@ -21,6 +21,7 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { errs.Scope = code.CloudEPNotification + return &ServiceContext{ Config: c, MailSender: usecase.MustMailgunUseCase(usecase.MailUseCaseParam{Conf: c}), diff --git a/internal/usecase/mitake.go b/internal/usecase/mitake.go index ac332bc..2d93d8c 100644 --- a/internal/usecase/mitake.go +++ b/internal/usecase/mitake.go @@ -26,6 +26,7 @@ func (s *SMSUseCase) SendSMS(_ context.Context, req usecase.SMSReq) error { if err != nil { return err } + return nil } diff --git a/notification.go b/notification.go index b35a92c..3e1f99f 100644 --- a/notification.go +++ b/notification.go @@ -1,13 +1,12 @@ package main import ( - "flag" - "fmt" - "app-cloudep-notification-service/gen_result/pb/notification" "app-cloudep-notification-service/internal/config" senderserviceServer "app-cloudep-notification-service/internal/server/senderservice" "app-cloudep-notification-service/internal/svc" + "flag" + "log" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/core/service" @@ -34,6 +33,6 @@ func main() { }) defer s.Stop() - fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) + log.Printf("Starting rpc server at %s...\n", c.ListenOn) s.Start() }