From 8580c6ab33974eb48b14759f3166b072bc52b241 Mon Sep 17 00:00:00 2001 From: ItsNotGoodName Date: Sun, 2 Jan 2022 18:02:32 -0800 Subject: [PATCH] refactor: rename domain -> core --- app/app.go | 30 +++++++++++++-------------- app/message.go | 20 +++++++++--------- app/message_send.go | 4 ++-- cmd/server.go | 4 ++-- {domain => core}/attachment.go | 2 +- {domain => core}/auth.go | 2 +- {domain => core}/bridge.go | 2 +- {domain => core}/database.go | 2 +- {domain => core}/endpoint.go | 2 +- {domain => core}/error.go | 2 +- {domain => core}/filter.go | 6 +++--- {domain => core}/filter_test.go | 2 +- {domain => core}/message.go | 2 +- right/endpoint/end_mock.go | 4 ++-- right/endpoint/end_telegram.go | 4 ++-- right/endpoint/factory.go | 10 ++++----- right/endpoint/repository.go | 12 +++++------ right/repository/attachment.go | 32 ++++++++++++++--------------- right/repository/database.go | 6 +++--- right/repository/message.go | 22 ++++++++++---------- right/repository/mock.go | 6 +++--- right/repository/mock_attachment.go | 18 ++++++++-------- right/repository/mock_message.go | 16 +++++++-------- service/auth.go | 4 ++-- service/bridge.go | 18 ++++++++-------- service/endpoint.go | 18 ++++++++-------- service/message.go | 24 +++++++++++----------- 27 files changed, 137 insertions(+), 137 deletions(-) rename {domain => core}/attachment.go (98%) rename {domain => core}/auth.go (91%) rename {domain => core}/bridge.go (98%) rename {domain => core}/database.go (90%) rename {domain => core}/endpoint.go (98%) rename {domain => core}/error.go (82%) rename {domain => core}/filter.go (89%) rename {domain => core}/filter_test.go (98%) rename {domain => core}/message.go (99%) diff --git a/app/app.go b/app/app.go index 024f3a33..302675d3 100644 --- a/app/app.go +++ b/app/app.go @@ -1,25 +1,25 @@ package app -import "github.com/ItsNotGoodName/smtpbridge/domain" +import "github.com/ItsNotGoodName/smtpbridge/core" type App struct { - attachmentREPO domain.AttachmentRepositoryPort - messageREPO domain.MessageRepositoryPort - endpointREPO domain.EndpointRepositoryPort - authSVC domain.AuthServicePort - bridgeSVC domain.BridgeServicePort - endpointSVC domain.EndpointServicePort - messageSVC domain.MessageServicePort + attachmentREPO core.AttachmentRepositoryPort + messageREPO core.MessageRepositoryPort + endpointREPO core.EndpointRepositoryPort + authSVC core.AuthServicePort + bridgeSVC core.BridgeServicePort + endpointSVC core.EndpointServicePort + messageSVC core.MessageServicePort } func New( - attachmentREPO domain.AttachmentRepositoryPort, - messageREPO domain.MessageRepositoryPort, - endpointREPO domain.EndpointRepositoryPort, - authSVC domain.AuthServicePort, - bridgeSVC domain.BridgeServicePort, - endpointSVC domain.EndpointServicePort, - messageSVC domain.MessageServicePort, + attachmentREPO core.AttachmentRepositoryPort, + messageREPO core.MessageRepositoryPort, + endpointREPO core.EndpointRepositoryPort, + authSVC core.AuthServicePort, + bridgeSVC core.BridgeServicePort, + endpointSVC core.EndpointServicePort, + messageSVC core.MessageServicePort, ) *App { return &App{ attachmentREPO, diff --git a/app/message.go b/app/message.go index 8dabd450..a2a233d3 100644 --- a/app/message.go +++ b/app/message.go @@ -3,21 +3,21 @@ package app import ( "time" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Message struct { - UUID string `json:"uuid"` - Status domain.Status `json:"status"` - From string `json:"from"` - To []string `json:"to"` - Subject string `json:"subject"` - Text string `json:"text"` - CreatedAt string `json:"created_at"` - Attachments []Attachment `json:"attachments"` + UUID string `json:"uuid"` + Status core.Status `json:"status"` + From string `json:"from"` + To []string `json:"to"` + Subject string `json:"subject"` + Text string `json:"text"` + CreatedAt string `json:"created_at"` + Attachments []Attachment `json:"attachments"` } -func NewMessage(msg *domain.Message) *Message { +func NewMessage(msg *core.Message) *Message { var attachments []Attachment for _, attachment := range msg.Attachments { attachments = append(attachments, Attachment{ diff --git a/app/message_send.go b/app/message_send.go index 983d734a..c02f011c 100644 --- a/app/message_send.go +++ b/app/message_send.go @@ -3,11 +3,11 @@ package app import ( "fmt" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type messageSendRequest struct { - Message *domain.Message + Message *core.Message } func (a *App) messageSend(req *messageSendRequest) error { diff --git a/cmd/server.go b/cmd/server.go index ca3bc306..ea1f6bbb 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -24,7 +24,7 @@ package cmd import ( "github.com/ItsNotGoodName/smtpbridge/app" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" "github.com/ItsNotGoodName/smtpbridge/left/router" "github.com/ItsNotGoodName/smtpbridge/left/smtp" "github.com/ItsNotGoodName/smtpbridge/left/web" @@ -47,7 +47,7 @@ var serverCmd = &cobra.Command{ serverConfig.Load() // Init database - var db domain.Database + var db core.Database if serverConfig.DB.IsBolt() { db = repository.NewDatabase(serverConfig) } else { diff --git a/domain/attachment.go b/core/attachment.go similarity index 98% rename from domain/attachment.go rename to core/attachment.go index 72c8f709..d2b3375f 100644 --- a/domain/attachment.go +++ b/core/attachment.go @@ -1,4 +1,4 @@ -package domain +package core import ( "fmt" diff --git a/domain/auth.go b/core/auth.go similarity index 91% rename from domain/auth.go rename to core/auth.go index 650f7704..3622e611 100644 --- a/domain/auth.go +++ b/core/auth.go @@ -1,4 +1,4 @@ -package domain +package core import "fmt" diff --git a/domain/bridge.go b/core/bridge.go similarity index 98% rename from domain/bridge.go rename to core/bridge.go index 60c226e8..24bf935c 100644 --- a/domain/bridge.go +++ b/core/bridge.go @@ -1,4 +1,4 @@ -package domain +package core import "fmt" diff --git a/domain/database.go b/core/database.go similarity index 90% rename from domain/database.go rename to core/database.go index 6b3c99ec..e4a44df7 100644 --- a/domain/database.go +++ b/core/database.go @@ -1,4 +1,4 @@ -package domain +package core type Database interface { Close() error diff --git a/domain/endpoint.go b/core/endpoint.go similarity index 98% rename from domain/endpoint.go rename to core/endpoint.go index ebf29190..edcda7ec 100644 --- a/domain/endpoint.go +++ b/core/endpoint.go @@ -1,4 +1,4 @@ -package domain +package core import "fmt" diff --git a/domain/error.go b/core/error.go similarity index 82% rename from domain/error.go rename to core/error.go index c48cf07c..1cba85e0 100644 --- a/domain/error.go +++ b/core/error.go @@ -1,4 +1,4 @@ -package domain +package core import "errors" diff --git a/domain/filter.go b/core/filter.go similarity index 89% rename from domain/filter.go rename to core/filter.go index 0ff44203..c923ae9b 100644 --- a/domain/filter.go +++ b/core/filter.go @@ -1,4 +1,4 @@ -package domain +package core import ( "log" @@ -19,13 +19,13 @@ func NewFilter(to, from, toRegex, fromRegex string) Filter { if toRegex != "" { toRegexp, err = regexp.Compile(toRegex) if err != nil { - log.Fatalln("domain.NewFilter: bad to regex:", err) + log.Fatalln("core.NewFilter: bad to regex:", err) } } if fromRegex != "" { fromRegexp, err = regexp.Compile(fromRegex) if err != nil { - log.Fatalln("domain.NewFilter: bad from regex:", err) + log.Fatalln("core.NewFilter: bad from regex:", err) } } diff --git a/domain/filter_test.go b/core/filter_test.go similarity index 98% rename from domain/filter_test.go rename to core/filter_test.go index f3b57993..af21fd18 100644 --- a/domain/filter_test.go +++ b/core/filter_test.go @@ -1,4 +1,4 @@ -package domain +package core import "testing" diff --git a/domain/message.go b/core/message.go similarity index 99% rename from domain/message.go rename to core/message.go index 5d2a1f82..2b9914d2 100644 --- a/domain/message.go +++ b/core/message.go @@ -1,4 +1,4 @@ -package domain +package core import ( "fmt" diff --git a/right/endpoint/end_mock.go b/right/endpoint/end_mock.go index bc97f5a9..137ca094 100644 --- a/right/endpoint/end_mock.go +++ b/right/endpoint/end_mock.go @@ -3,7 +3,7 @@ package endpoint import ( "fmt" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Mock struct{} @@ -12,7 +12,7 @@ func NewMock() (*Mock, error) { return &Mock{}, nil } -func (m *Mock) Send(message *domain.EndpointMessage) error { +func (m *Mock) Send(message *core.EndpointMessage) error { fmt.Printf("endpoint.Mock.Send: %+v\n", message) return nil } diff --git a/right/endpoint/end_telegram.go b/right/endpoint/end_telegram.go index 9b5bf4bf..b52a0aa3 100644 --- a/right/endpoint/end_telegram.go +++ b/right/endpoint/end_telegram.go @@ -8,7 +8,7 @@ import ( "net/http" "net/url" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Telegram struct { @@ -28,7 +28,7 @@ type TelegramResponse struct { Description string `json:"description"` } -func (t *Telegram) Send(msg *domain.EndpointMessage) error { +func (t *Telegram) Send(msg *core.EndpointMessage) error { if len(msg.Attachments) == 0 { return t.sendMessage(msg.Text) } diff --git a/right/endpoint/factory.go b/right/endpoint/factory.go index fed3f6ee..6bc7e101 100644 --- a/right/endpoint/factory.go +++ b/right/endpoint/factory.go @@ -3,7 +3,7 @@ package endpoint import ( "fmt" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) const ( @@ -11,7 +11,7 @@ const ( NameMock = "mock" ) -func factory(endpointType string, config map[string]string) (domain.EndpointPort, error) { +func factory(endpointType string, config map[string]string) (core.EndpointPort, error) { switch endpointType { case NameTelegram: return telegramFactory(config) @@ -19,18 +19,18 @@ func factory(endpointType string, config map[string]string) (domain.EndpointPort return NewMock() } - return nil, fmt.Errorf("%v: %s", domain.ErrEndpointInvalidType, endpointType) + return nil, fmt.Errorf("%v: %s", core.ErrEndpointInvalidType, endpointType) } func telegramFactory(config map[string]string) (*Telegram, error) { token, ok := config["token"] if !ok { - return nil, fmt.Errorf("%v: %s: token not found", domain.ErrEndpointInvalidConfig, NameTelegram) + return nil, fmt.Errorf("%v: %s: token not found", core.ErrEndpointInvalidConfig, NameTelegram) } chatID, ok := config["chat_id"] if !ok { - return nil, fmt.Errorf("%v: %s: chat_id not found", domain.ErrEndpointInvalidConfig, NameTelegram) + return nil, fmt.Errorf("%v: %s: chat_id not found", core.ErrEndpointInvalidConfig, NameTelegram) } return NewTelegram(token, chatID), nil diff --git a/right/endpoint/repository.go b/right/endpoint/repository.go index 7cde4ee0..3b903725 100644 --- a/right/endpoint/repository.go +++ b/right/endpoint/repository.go @@ -6,17 +6,17 @@ import ( "sync" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Repository struct { endpointMu sync.RWMutex - endpointMap map[string]domain.EndpointPort + endpointMap map[string]core.EndpointPort } func NewRepository(cfg *config.Config) *Repository { r := Repository{ - endpointMap: make(map[string]domain.EndpointPort), + endpointMap: make(map[string]core.EndpointPort), endpointMu: sync.RWMutex{}, } @@ -30,13 +30,13 @@ func NewRepository(cfg *config.Config) *Repository { return &r } -func (r *Repository) Get(name string) (domain.EndpointPort, error) { +func (r *Repository) Get(name string) (core.EndpointPort, error) { r.endpointMu.RLock() defer r.endpointMu.RUnlock() endpoint, ok := r.endpointMap[name] if !ok { - return nil, fmt.Errorf("%v: %s", domain.ErrEndpointNotFound, name) + return nil, fmt.Errorf("%v: %s", core.ErrEndpointNotFound, name) } return endpoint, nil @@ -47,7 +47,7 @@ func (r *Repository) Create(name, endpointType string, config map[string]string) defer r.endpointMu.Unlock() if _, ok := r.endpointMap[name]; ok { - return fmt.Errorf("%v: %s", domain.ErrEndpointNameConflict, name) + return fmt.Errorf("%v: %s", core.ErrEndpointNameConflict, name) } endpoint, err := factory(endpointType, config) diff --git a/right/repository/attachment.go b/right/repository/attachment.go index 4afc5a68..49df26e5 100644 --- a/right/repository/attachment.go +++ b/right/repository/attachment.go @@ -7,19 +7,19 @@ import ( "path" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" "github.com/asdine/storm" "github.com/asdine/storm/q" ) type attachmentModel struct { - UUID string `storm:"id"` - Name string `` - Type domain.AttachmentType `` - MessageUUID string `` + UUID string `storm:"id"` + Name string `` + Type core.AttachmentType `` + MessageUUID string `` } -func convertAttachmentD(att *domain.Attachment) *attachmentModel { +func convertAttachmentD(att *core.Attachment) *attachmentModel { return &attachmentModel{ UUID: att.UUID, Name: att.Name, @@ -28,8 +28,8 @@ func convertAttachmentD(att *domain.Attachment) *attachmentModel { } } -func convertAttachmentM(attM *attachmentModel) *domain.Attachment { - return &domain.Attachment{ +func convertAttachmentM(attM *attachmentModel) *core.Attachment { + return &core.Attachment{ UUID: attM.UUID, Name: attM.Name, Type: attM.Type, @@ -56,7 +56,7 @@ func NewAttachment(cfg *config.Config, db *storm.DB) *Attachment { } } -func (a *Attachment) Create(att *domain.Attachment) error { +func (a *Attachment) Create(att *core.Attachment) error { err := a.db.Save(convertAttachmentD(att)) if err != nil { return err @@ -66,7 +66,7 @@ func (a *Attachment) Create(att *domain.Attachment) error { } // getAttachmentPath returns the path to the attachment file on the file system. -func (a *Attachment) getPath(att *domain.Attachment) string { +func (a *Attachment) getPath(att *core.Attachment) string { return path.Join(a.attDir, att.File()) } @@ -74,7 +74,7 @@ func (a *Attachment) GetFS() fs.FS { return a.fs } -func (a *Attachment) Get(uuid string) (*domain.Attachment, error) { +func (a *Attachment) Get(uuid string) (*core.Attachment, error) { var attM *attachmentModel err := a.db.One("UUID", uuid, attM) if err != nil { @@ -84,7 +84,7 @@ func (a *Attachment) Get(uuid string) (*domain.Attachment, error) { return convertAttachmentM(attM), nil } -func (a *Attachment) GetData(att *domain.Attachment) ([]byte, error) { +func (a *Attachment) GetData(att *core.Attachment) ([]byte, error) { data, err := os.ReadFile(a.getPath(att)) if err != nil { return nil, err @@ -93,17 +93,17 @@ func (a *Attachment) GetData(att *domain.Attachment) ([]byte, error) { return data, nil } -func (a *Attachment) ListByMessage(msg *domain.Message) ([]domain.Attachment, error) { +func (a *Attachment) ListByMessage(msg *core.Message) ([]core.Attachment, error) { var attsM []attachmentModel err := a.db.Select(q.Eq("MessageUUID", msg.UUID)).Find(&attsM) if err != nil { if err == storm.ErrNotFound { - return []domain.Attachment{}, nil + return []core.Attachment{}, nil } return nil, err } - var atts []domain.Attachment + var atts []core.Attachment for _, attM := range attsM { atts = append(atts, *convertAttachmentM(&attM)) } @@ -111,6 +111,6 @@ func (a *Attachment) ListByMessage(msg *domain.Message) ([]domain.Attachment, er return atts, nil } -func (a *Attachment) DeleteData(att *domain.Attachment) error { +func (a *Attachment) DeleteData(att *core.Attachment) error { return os.Remove(a.getPath(att)) } diff --git a/right/repository/database.go b/right/repository/database.go index 1314e2cf..252d836d 100644 --- a/right/repository/database.go +++ b/right/repository/database.go @@ -4,7 +4,7 @@ import ( "log" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" "github.com/asdine/storm" ) @@ -34,10 +34,10 @@ func (d Database) Close() error { return d.db.Close() } -func (d Database) AttachmentRepository() domain.AttachmentRepositoryPort { +func (d Database) AttachmentRepository() core.AttachmentRepositoryPort { return d.attachment } -func (d Database) MessageRepository() domain.MessageRepositoryPort { +func (d Database) MessageRepository() core.MessageRepositoryPort { return d.message } diff --git a/right/repository/message.go b/right/repository/message.go index c3f1b782..7c484eae 100644 --- a/right/repository/message.go +++ b/right/repository/message.go @@ -4,7 +4,7 @@ import ( "log" "time" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" "github.com/asdine/storm" "github.com/asdine/storm/q" ) @@ -15,12 +15,12 @@ type messageModel struct { To map[string]struct{} `` // To is the email addresses of the recipients. Subject string `` // Subject of the message. Text string `` // Text is the message body. - Status domain.Status `` // Status is the status of the message. + Status core.Status `` // Status is the status of the message. CreatedAt time.Time `` // Time message was received. } -func convertMessageM(msg *messageModel) *domain.Message { - return &domain.Message{ +func convertMessageM(msg *messageModel) *core.Message { + return &core.Message{ UUID: msg.UUID, From: msg.From, To: msg.To, @@ -31,7 +31,7 @@ func convertMessageM(msg *messageModel) *domain.Message { } } -func convertMessageD(msg *domain.Message) *messageModel { +func convertMessageD(msg *core.Message) *messageModel { return &messageModel{ UUID: msg.UUID, From: msg.From, @@ -55,11 +55,11 @@ func NewMessage(db *storm.DB, attachmentREPO *Attachment) *Message { } } -func (m *Message) Create(msg *domain.Message) error { +func (m *Message) Create(msg *core.Message) error { return m.db.Save(convertMessageD(msg)) } -func (m *Message) Get(uuid string) (*domain.Message, error) { +func (m *Message) Get(uuid string) (*core.Message, error) { var msgM messageModel err := m.db.One("UUID", uuid, &msgM) if err != nil { @@ -69,7 +69,7 @@ func (m *Message) Get(uuid string) (*domain.Message, error) { return convertMessageM(&msgM), nil } -func (m *Message) Update(msg *domain.Message, updateFN func(msg *domain.Message) (*domain.Message, error)) error { +func (m *Message) Update(msg *core.Message, updateFN func(msg *core.Message) (*core.Message, error)) error { tx, err := m.db.Begin(true) if err != nil { return err @@ -94,14 +94,14 @@ func (m *Message) Update(msg *domain.Message, updateFN func(msg *domain.Message) return tx.Commit() } -func (m *Message) List(limit, offset int) ([]domain.Message, error) { +func (m *Message) List(limit, offset int) ([]core.Message, error) { var msgsM []messageModel err := m.db.Select().OrderBy("CreatedAt").Limit(limit).Skip(offset).Reverse().Find(&msgsM) if err != nil && err != storm.ErrNotFound { return nil, err } - var msgs []domain.Message + var msgs []core.Message for _, msgM := range msgsM { msgs = append(msgs, *convertMessageM(&msgM)) } @@ -118,7 +118,7 @@ func (m *Message) Count() (int, error) { return count, err } -func (m *Message) Delete(msg *domain.Message) error { +func (m *Message) Delete(msg *core.Message) error { tx, err := m.db.Begin(true) if err != nil { return err diff --git a/right/repository/mock.go b/right/repository/mock.go index db8788ba..864ae786 100644 --- a/right/repository/mock.go +++ b/right/repository/mock.go @@ -1,6 +1,6 @@ package repository -import "github.com/ItsNotGoodName/smtpbridge/domain" +import "github.com/ItsNotGoodName/smtpbridge/core" type Mock struct{} @@ -12,10 +12,10 @@ func (Mock) Close() error { return nil } -func (Mock) AttachmentRepository() domain.AttachmentRepositoryPort { +func (Mock) AttachmentRepository() core.AttachmentRepositoryPort { return NewAttachmentMock() } -func (Mock) MessageRepository() domain.MessageRepositoryPort { +func (Mock) MessageRepository() core.MessageRepositoryPort { return NewMessageMock() } diff --git a/right/repository/mock_attachment.go b/right/repository/mock_attachment.go index d01ee70d..b88ce084 100644 --- a/right/repository/mock_attachment.go +++ b/right/repository/mock_attachment.go @@ -3,7 +3,7 @@ package repository import ( "io/fs" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type AttachmentMock struct{} @@ -12,30 +12,30 @@ func NewAttachmentMock() *AttachmentMock { return &AttachmentMock{} } -func (AttachmentMock) Create(att *domain.Attachment) error { +func (AttachmentMock) Create(att *core.Attachment) error { return nil } -func (AttachmentMock) Get(uuid string) (*domain.Attachment, error) { - return nil, domain.ErrNotImplemented +func (AttachmentMock) Get(uuid string) (*core.Attachment, error) { + return nil, core.ErrNotImplemented } -func (AttachmentMock) GetData(att *domain.Attachment) ([]byte, error) { - return nil, domain.ErrNotImplemented +func (AttachmentMock) GetData(att *core.Attachment) ([]byte, error) { + return nil, core.ErrNotImplemented } func (a AttachmentMock) GetFS() fs.FS { return a } -func (AttachmentMock) ListByMessage(msg *domain.Message) ([]domain.Attachment, error) { - return []domain.Attachment{}, nil +func (AttachmentMock) ListByMessage(msg *core.Message) ([]core.Attachment, error) { + return []core.Attachment{}, nil } func (AttachmentMock) Open(name string) (fs.File, error) { return nil, fs.ErrNotExist } -func (AttachmentMock) DeleteData(att *domain.Attachment) error { +func (AttachmentMock) DeleteData(att *core.Attachment) error { return nil } diff --git a/right/repository/mock_message.go b/right/repository/mock_message.go index f9145f86..074bb2f2 100644 --- a/right/repository/mock_message.go +++ b/right/repository/mock_message.go @@ -1,6 +1,6 @@ package repository -import "github.com/ItsNotGoodName/smtpbridge/domain" +import "github.com/ItsNotGoodName/smtpbridge/core" type MessageMock struct{} @@ -8,7 +8,7 @@ func NewMessageMock() *MessageMock { return &MessageMock{} } -func (MessageMock) Create(msg *domain.Message) error { +func (MessageMock) Create(msg *core.Message) error { return nil } @@ -16,18 +16,18 @@ func (MessageMock) Count() (int, error) { return 0, nil } -func (MessageMock) Get(uuid string) (*domain.Message, error) { - return nil, domain.ErrNotImplemented +func (MessageMock) Get(uuid string) (*core.Message, error) { + return nil, core.ErrNotImplemented } -func (MessageMock) List(limit, offset int) ([]domain.Message, error) { - return []domain.Message{}, nil +func (MessageMock) List(limit, offset int) ([]core.Message, error) { + return []core.Message{}, nil } -func (MessageMock) Update(msg *domain.Message, updateFN func(msg *domain.Message) (*domain.Message, error)) error { +func (MessageMock) Update(msg *core.Message, updateFN func(msg *core.Message) (*core.Message, error)) error { return nil } -func (MessageMock) Delete(msg *domain.Message) error { +func (MessageMock) Delete(msg *core.Message) error { return nil } diff --git a/service/auth.go b/service/auth.go index 12444aaf..06bc0d2e 100644 --- a/service/auth.go +++ b/service/auth.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Auth struct { @@ -27,7 +27,7 @@ func (m *Auth) Login(username, password string) error { } if strings.ToLower(username) != m.username || password != m.password { - return domain.ErrAuthInvalid + return core.ErrAuthInvalid } return nil diff --git a/service/bridge.go b/service/bridge.go index c753e984..f93b5acf 100644 --- a/service/bridge.go +++ b/service/bridge.go @@ -4,15 +4,15 @@ import ( "log" "github.com/ItsNotGoodName/smtpbridge/config" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Bridge struct { - bridges []*domain.Bridge + bridges []*core.Bridge } -func NewBridge(cfg *config.Config, endpointREPO domain.EndpointRepositoryPort) *Bridge { - var bridges []*domain.Bridge +func NewBridge(cfg *config.Config, endpointREPO core.EndpointRepositoryPort) *Bridge { + var bridges []*core.Bridge for _, bridge := range cfg.Bridges { for _, endpoint := range bridge.Endpoints { @@ -21,19 +21,19 @@ func NewBridge(cfg *config.Config, endpointREPO domain.EndpointRepositoryPort) * } } - filters := make([]domain.Filter, len(bridge.Filters)) + filters := make([]core.Filter, len(bridge.Filters)) for i := range bridge.Filters { - filters[i] = domain.NewFilter(bridge.Filters[i].To, bridge.Filters[i].From, bridge.Filters[i].ToRegex, bridge.Filters[i].FromRegex) + filters[i] = core.NewFilter(bridge.Filters[i].To, bridge.Filters[i].From, bridge.Filters[i].ToRegex, bridge.Filters[i].FromRegex) } - bridges = append(bridges, domain.NewBridge(bridge.Name, bridge.Endpoints, bridge.OnlyText, bridge.OnlyAttachments, filters)) + bridges = append(bridges, core.NewBridge(bridge.Name, bridge.Endpoints, bridge.OnlyText, bridge.OnlyAttachments, filters)) } return &Bridge{bridges: bridges} } -func (b *Bridge) ListByMessage(msg *domain.Message) []*domain.Bridge { - var bridges []*domain.Bridge +func (b *Bridge) ListByMessage(msg *core.Message) []*core.Bridge { + var bridges []*core.Bridge for _, bridge := range b.bridges { if !bridge.Match(msg) { continue diff --git a/service/endpoint.go b/service/endpoint.go index 3fc3cddf..1d0dedac 100644 --- a/service/endpoint.go +++ b/service/endpoint.go @@ -3,22 +3,22 @@ package service import ( "log" - "github.com/ItsNotGoodName/smtpbridge/domain" + "github.com/ItsNotGoodName/smtpbridge/core" ) type Endpoint struct { - endpointREPO domain.EndpointRepositoryPort + endpointREPO core.EndpointRepositoryPort } -func NewEndpoint(endpointREPO domain.EndpointRepositoryPort) *Endpoint { +func NewEndpoint(endpointREPO core.EndpointRepositoryPort) *Endpoint { return &Endpoint{endpointREPO: endpointREPO} } -func (e *Endpoint) SendBridges(msg *domain.Message, bridges []*domain.Bridge) (domain.Status, error) { +func (e *Endpoint) SendBridges(msg *core.Message, bridges []*core.Bridge) (core.Status, error) { // TODO: refactor entire method if len(bridges) == 0 { log.Println("app.messageSend: no valid bridges: skipped message", msg.UUID) - return domain.StatusSkipped, nil + return core.StatusSkipped, nil } var errGet error @@ -32,7 +32,7 @@ func (e *Endpoint) SendBridges(msg *domain.Message, bridges []*domain.Bridge) (d } for _, name := range bridge.Endpoints { - var endpoint domain.EndpointPort + var endpoint core.EndpointPort endpoint, errGet = e.endpointREPO.Get(name) if errGet != nil { break @@ -49,13 +49,13 @@ func (e *Endpoint) SendBridges(msg *domain.Message, bridges []*domain.Bridge) (d if sent > 0 { log.Println("app.messageSend: sent message", msg.UUID) - return domain.StatusSent, errGet + return core.StatusSent, errGet } if skipped > 0 { log.Println("app.messageSend: only_* produced empty message: skipped message", msg.UUID) - return domain.StatusSkipped, errGet + return core.StatusSkipped, errGet } - return domain.StatusFailed, errGet + return core.StatusFailed, errGet } diff --git a/service/message.go b/service/message.go index d53d6953..bc12b5a3 100644 --- a/service/message.go +++ b/service/message.go @@ -1,15 +1,15 @@ package service -import "github.com/ItsNotGoodName/smtpbridge/domain" +import "github.com/ItsNotGoodName/smtpbridge/core" type Message struct { - attachmentREPO domain.AttachmentRepositoryPort - messageREPO domain.MessageRepositoryPort + attachmentREPO core.AttachmentRepositoryPort + messageREPO core.MessageRepositoryPort } func NewMessage( - attachmentREPO domain.AttachmentRepositoryPort, - messageREPO domain.MessageRepositoryPort, + attachmentREPO core.AttachmentRepositoryPort, + messageREPO core.MessageRepositoryPort, ) *Message { return &Message{ attachmentREPO: attachmentREPO, @@ -17,7 +17,7 @@ func NewMessage( } } -func (m *Message) Get(uuid string) (*domain.Message, error) { +func (m *Message) Get(uuid string) (*core.Message, error) { msg, err := m.messageREPO.Get(uuid) if err != nil { return nil, err @@ -31,7 +31,7 @@ func (m *Message) Get(uuid string) (*domain.Message, error) { return msg, nil } -func (m *Message) List(limit, offset int) ([]domain.Message, error) { +func (m *Message) List(limit, offset int) ([]core.Message, error) { messages, err := m.messageREPO.List(limit, offset) if err != nil { return nil, err @@ -47,8 +47,8 @@ func (m *Message) List(limit, offset int) ([]domain.Message, error) { return messages, nil } -func (m *Message) Create(subject, from string, to map[string]struct{}, text string) (*domain.Message, error) { - msg := domain.NewMessage(subject, from, to, text) +func (m *Message) Create(subject, from string, to map[string]struct{}, text string) (*core.Message, error) { + msg := core.NewMessage(subject, from, to, text) err := m.messageREPO.Create(msg) if err != nil { @@ -58,7 +58,7 @@ func (m *Message) Create(subject, from string, to map[string]struct{}, text stri return msg, nil } -func (m *Message) CreateAttachment(msg *domain.Message, name string, data []byte) (*domain.Attachment, error) { +func (m *Message) CreateAttachment(msg *core.Message, name string, data []byte) (*core.Attachment, error) { att, err := msg.NewAttachment(name, data) if err != nil { return nil, err @@ -72,8 +72,8 @@ func (m *Message) CreateAttachment(msg *domain.Message, name string, data []byte return att, nil } -func (m *Message) UpdateStatus(msg *domain.Message, status domain.Status) error { - return m.messageREPO.Update(msg, func(msg *domain.Message) (*domain.Message, error) { +func (m *Message) UpdateStatus(msg *core.Message, status core.Status) error { + return m.messageREPO.Update(msg, func(msg *core.Message) (*core.Message, error) { msg.Status = status return msg, nil })