Compare commits

..

1 Commits

Author SHA1 Message Date
王性驊 b3cfd0afaa add code third party code (#5)
Co-authored-by: daniel.w <daniel.w@intteam.net>
Reviewed-on: #5
2024-08-27 14:25:45 +00:00
12 changed files with 68 additions and 76 deletions

View File

@ -117,14 +117,6 @@ issues:
- gocognit
- contextcheck
exclude-dirs:
- internal/model
exclude-files:
- .*_test.go
linters-settings:
gci:
sections:

View File

@ -18,7 +18,6 @@ test: # 進行測試
fmt: # 格式優化
$(GOFMT) -w $(GOFILES)
goimports -w ./
golangci-lint run
.PHONY: gen-rpc
gen-rpc: # 建立 rpc code

View File

@ -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...)
}

View File

@ -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);
}

View File

@ -1,6 +1,7 @@
package domain
import (
"fmt"
"strings"
"code.30cm.net/digimon/library-go/errs"
@ -23,13 +24,14 @@ const (
// SendMailError ...
func SendMailError(s ...string) *errs.LibError {
return errs.NewError(code.CloudEPNotification, code.ThirdParty,
SendMailErrorCode.ToUint32(), strings.Join(s, " "))
SendMailErrorCode.ToUint32(),
fmt.Sprintf("%s", 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())
@ -40,13 +42,14 @@ 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(), strings.Join(s, " "))
SendSMSErrorCode.ToUint32(),
fmt.Sprintf("%s", 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())

View File

@ -1,31 +0,0 @@
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 &notification.OKResp{}, nil
}

View File

@ -0,0 +1,29 @@
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 &notification.OKResp{}, nil
}

View File

@ -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(_ *notification.SendByTemplateIDReq) (*notification.OKResp, error) {
// SendSmsByTemplateId 寄送模板簡訊
func (l *SendSmsByTemplateIdLogic) SendSmsByTemplateId(in *notification.SendByTemplateIDReq) (*notification.OKResp, error) {
// todo: add your logic here and delete this line
return &notification.OKResp{}, nil

View File

@ -8,6 +8,7 @@ import (
"app-cloudep-notification-service/gen_result/pb/notification"
senderservicelogic "app-cloudep-notification-service/internal/logic/senderservice"
"app-cloudep-notification-service/internal/svc"
)
@ -34,14 +35,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)
}

View File

@ -21,7 +21,6 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext {
errs.Scope = code.CloudEPNotification
return &ServiceContext{
Config: c,
MailSender: usecase.MustMailgunUseCase(usecase.MailUseCaseParam{Conf: c}),

View File

@ -26,7 +26,6 @@ func (s *SMSUseCase) SendSMS(_ context.Context, req usecase.SMSReq) error {
if err != nil {
return err
}
return nil
}

View File

@ -1,12 +1,13 @@
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"
@ -33,6 +34,6 @@ func main() {
})
defer s.Stop()
log.Printf("Starting rpc server at %s...\n", c.ListenOn)
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}