From b50f0fbcdc14fc8d66e40f5d0c90f4a7fca44258 Mon Sep 17 00:00:00 2001 From: Iman Tumorang Date: Mon, 30 Apr 2018 11:10:14 +0700 Subject: [PATCH] V2 (#8) * refactor: moving to a new structure folder * fix test * move to godep * Update README.md * updatereadme --- Gopkg.lock | 164 +++++++++++++----- Gopkg.toml | 34 +++- README.md | 10 +- article/article.go | 13 -- article/delivery/http/article_handler.go | 4 +- article/delivery/http/article_test.go | 6 +- .../mocks/ArticleRepository.go | 43 ++--- article/{usecase => }/mocks/ArticleUsecase.go | 47 ++--- article/{repository => }/repository.go | 4 +- article/repository/mysql_article.go | 7 +- article/repository/mysqlarticle_test.go | 8 +- article/usecase.go | 14 ++ article/usecase/articleucase_test.go | 18 +- article/usecase/artilce_ucase.go | 40 ++--- .../mocks/AuthorRepository.go | 11 +- author/repository.go | 7 + author/repository/mysql_repository.go | 9 +- author/repository/repository.go | 7 - config/env/config.go | 51 ------ glide.lock | 100 ----------- glide.yaml | 27 --- main.go | 37 ++-- .../middleware => middleware}/middleware.go | 0 .../middleware_test.go | 2 +- models/article.go | 14 ++ {author => models}/author.go | 2 +- {article => models}/errors.go | 2 +- 27 files changed, 307 insertions(+), 374 deletions(-) delete mode 100644 article/article.go rename article/{repository => }/mocks/ArticleRepository.go (63%) rename article/{usecase => }/mocks/ArticleUsecase.go (55%) rename article/{repository => }/repository.go (81%) create mode 100644 article/usecase.go rename author/{repository => }/mocks/AuthorRepository.go (62%) create mode 100644 author/repository.go delete mode 100644 author/repository/repository.go delete mode 100644 config/env/config.go delete mode 100644 glide.lock delete mode 100644 glide.yaml rename {config/middleware => middleware}/middleware.go (100%) rename {config/middleware => middleware}/middleware_test.go (90%) create mode 100644 models/article.go rename {author => models}/author.go (91%) rename {article => models}/errors.go (93%) diff --git a/Gopkg.lock b/Gopkg.lock index 7168186..7331c2e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,20 +3,39 @@ [[projects]] name = "github.com/bxcodec/faker" - packages = ["."] - revision = "7c5fff7ed02e14ac848ef83aee45b95627c96ae2" - version = "v1.1.1" + packages = [ + ".", + "support/slice" + ] + revision = "f78d28265eded9944373b1aa9cc510057fb8cb7f" + version = "v1.4.2" [[projects]] name = "github.com/davecgh/go-spew" packages = ["spew"] - revision = "6d212800a42e8ab5c146b8ace3490ee17e5225f9" + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" [[projects]] - branch = "master" name = "github.com/fsnotify/fsnotify" packages = ["."] - revision = "4da3e2cfbabc9f751898f250b49f2439785783a1" + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" + +[[projects]] + name = "github.com/go-playground/locales" + packages = [ + ".", + "currency" + ] + revision = "f63010822830b6fe52288ee52d5a1151088ce039" + version = "v0.12.1" + +[[projects]] + name = "github.com/go-playground/universal-translator" + packages = ["."] + revision = "b32fa301c9fe55953584134cb6853a13c87ec0a1" + version = "v0.16.0" [[projects]] name = "github.com/go-sql-driver/mysql" @@ -27,95 +46,124 @@ [[projects]] branch = "master" name = "github.com/hashicorp/hcl" - packages = [".","hcl/ast","hcl/parser","hcl/scanner","hcl/strconv","hcl/token","json/parser","json/scanner","json/token"] - revision = "392dba7d905ed5d04a5794ba89f558b27e2ba1ca" + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/printer", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token" + ] + revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168" [[projects]] name = "github.com/labstack/echo" packages = ["."] - revision = "1049c9613cd371b7ea8f219404c9a821734781ed" - version = "v3.1.0" + revision = "6d227dfea4d2e52cb76856120b3c17f758139b4e" + version = "3.3.5" [[projects]] name = "github.com/labstack/gommon" - packages = ["color","log"] - revision = "1121fd3e243c202482226a7afe4dcd07ffc4139a" - version = "v0.2.1" + packages = [ + "color", + "log" + ] + revision = "588f4e8bddc6cb45c27b448e925c7fd6a5545434" + version = "0.2.5" [[projects]] name = "github.com/magiconair/properties" packages = ["."] - revision = "be5ece7dd465ab0765a9682137865547526d1dfb" - version = "v1.7.3" + revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6" + version = "v1.7.6" [[projects]] name = "github.com/mattn/go-colorable" packages = ["."] - revision = "165c32261890df3bfb1fb678e8096729abdad5d2" + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" [[projects]] name = "github.com/mattn/go-isatty" packages = ["."] - revision = "fc9e8d8ef48496124e79ae0df75490096eccf6fe" - version = "v0.0.2" + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" [[projects]] branch = "master" name = "github.com/mitchellh/mapstructure" packages = ["."] - revision = "d0303fe809921458f417bcf828397a65db30a7e4" + revision = "00c29f56e2386353d58c599509e8dc3801b0d716" [[projects]] - branch = "master" name = "github.com/pelletier/go-toml" packages = ["."] - revision = "69d355db5304c0f7f809a2edc054553e7142f016" + revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" + version = "v1.1.0" [[projects]] name = "github.com/pmezard/go-difflib" packages = ["difflib"] - revision = "d8ed2627bdf02c080bf22230dbb337003b7aba2d" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + name = "github.com/sirupsen/logrus" + packages = ["."] + revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc" + version = "v1.0.5" [[projects]] - branch = "master" name = "github.com/spf13/afero" - packages = [".","mem"] - revision = "9be650865eab0c12963d8753212f4f9c66cdcf12" + packages = [ + ".", + "mem" + ] + revision = "63644898a8da0bc22138abf860edaf5277b6102e" + version = "v1.1.0" [[projects]] name = "github.com/spf13/cast" packages = ["."] - revision = "acbeb36b902d72a7a4c18e8f3241075e7ab763e4" - version = "v1.1.0" + revision = "8965335b8c7107321228e3e3702cab9832751bac" + version = "v1.2.0" [[projects]] branch = "master" name = "github.com/spf13/jwalterweatherman" packages = ["."] - revision = "0efa5202c04663c757d84f90f5219c1250baf94f" + revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394" [[projects]] - branch = "master" name = "github.com/spf13/pflag" packages = ["."] - revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" + revision = "583c0c0531f06d5278b7d917446061adc344b5cd" + version = "v1.0.1" [[projects]] - branch = "master" name = "github.com/spf13/viper" packages = ["."] - revision = "c1de95864d73a5465492829d7cb2dd422b19ac96" + revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736" + version = "v1.0.2" [[projects]] name = "github.com/stretchr/objx" packages = ["."] - revision = "cbeaeb16a013161a98496fad62933b1d21786672" + revision = "facf9a85c22f48d2f52f2380e4efce1768749a89" + version = "v0.1" [[projects]] name = "github.com/stretchr/testify" - packages = ["assert","mock"] - revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" - version = "v1.1.4" + packages = [ + "assert", + "mock" + ] + revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" + version = "v1.2.1" [[projects]] branch = "master" @@ -130,36 +178,58 @@ revision = "dcecefd839c4193db0d35b88ec65b4c12d360ab0" [[projects]] + branch = "master" name = "golang.org/x/crypto" - packages = ["acme","acme/autocert"] - revision = "3627ff35f31987174dbee61d9d1dcc1c643e7174" + packages = [ + "acme", + "acme/autocert", + "ssh/terminal" + ] + revision = "b49d69b5da943f7ef3c9cf91c8777c1f78a0cc3c" [[projects]] branch = "master" name = "golang.org/x/sys" - packages = ["unix"] - revision = "abf9c25f54453410d0c6668e519582a9e1115027" + packages = [ + "unix", + "windows" + ] + revision = "cbbc999da32df943dac6cd71eb3ee39e1d7838b9" [[projects]] - branch = "master" name = "golang.org/x/text" - packages = ["internal/gen","internal/triegen","internal/ucd","transform","unicode/cldr","unicode/norm"] - revision = "cfdf022e86b4ecfb646e1efbd7db175dd623a8fa" + packages = [ + "internal/gen", + "internal/triegen", + "internal/ucd", + "transform", + "unicode/cldr", + "unicode/norm" + ] + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" [[projects]] name = "gopkg.in/DATA-DOG/go-sqlmock.v1" packages = ["."] - revision = "b983233bc0bbea4dc6e8ec8c8c923d935765ffec" - version = "v1.2.0" + revision = "d76b18b42f285b792bf985118980ce9eacea9d10" + version = "v1.3.0" + +[[projects]] + name = "gopkg.in/go-playground/validator.v9" + packages = ["."] + revision = "14984d91328f9612b58443cbdf4a077d4fd71091" + version = "v9.15.0" [[projects]] name = "gopkg.in/yaml.v2" packages = ["."] - revision = "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b" + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + version = "v2.2.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d9f3c65e282ca33c5948284a8d708b337636005a47e88412f18e18e8d8dcb457" + inputs-digest = "c018e15cd876ffd14de55718c53b9d7e8f0ae2ce5772083807f37e8ec6e9c53c" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index a017114..71f90a7 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,4 +1,3 @@ - # Gopkg.toml example # # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md @@ -17,13 +16,18 @@ # source = "github.com/myfork/project2" # # [[override]] -# name = "github.com/x/y" -# version = "2.4.0" +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true [[constraint]] name = "github.com/bxcodec/faker" - version = "~1.1.0" + version = "1.4.2" [[constraint]] name = "github.com/go-sql-driver/mysql" @@ -31,12 +35,28 @@ [[constraint]] name = "github.com/labstack/echo" - version = "3.1.0" + version = "3.3.5" + +[[constraint]] + name = "github.com/sirupsen/logrus" + version = "1.0.5" [[constraint]] - branch = "master" name = "github.com/spf13/viper" + version = "1.0.2" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.1" [[constraint]] name = "gopkg.in/DATA-DOG/go-sqlmock.v1" - version = "1.2.0" + version = "1.3.0" + +[[constraint]] + name = "gopkg.in/go-playground/validator.v9" + version = "9.15.0" + +[prune] + go-tests = true + unused-packages = true diff --git a/README.md b/README.md index 65a2e5a..2a653dc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # go-clean-arch +## Looking for the old code ? +If you are looking for the old code, you can checkout to the [v1 branch](https://github.com/bxcodec/go-clean-arch/tree/v1) + +_Last Updated: April 30th 2018_ + +## Description This is an example of implementation of Clean Architecture in Go (Golang) projects. Rule of Clean Architecture by Uncle Bob @@ -32,7 +38,7 @@ git clone https://github.com/bxcodec/go-clean-arch.git cd go-clean-arch # Install Dependencies -glide install -v +dep ensure # Make File make @@ -53,7 +59,7 @@ go get github.com/bxcodec/go-clean-arch cd $GOPATH/src/github.com/bxcodec/go-clean-arch # Install Dependencies -glide install -v +dep ensure # Make File make diff --git a/article/article.go b/article/article.go deleted file mode 100644 index 927c5c9..0000000 --- a/article/article.go +++ /dev/null @@ -1,13 +0,0 @@ -package article - -import "time" -import "github.com/bxcodec/go-clean-arch/author" - -type Article struct { - ID int64 `json:"id"` - Title string `json:"title" validate:"required"` - Content string `json:"content" validate:"required"` - Author author.Author `json:"author"` - UpdatedAt time.Time `json:"updated_at"` - CreatedAt time.Time `json:"created_at"` -} diff --git a/article/delivery/http/article_handler.go b/article/delivery/http/article_handler.go index 9eab2dd..864432c 100644 --- a/article/delivery/http/article_handler.go +++ b/article/delivery/http/article_handler.go @@ -6,9 +6,9 @@ import ( "github.com/sirupsen/logrus" - models "github.com/bxcodec/go-clean-arch/article" + models "github.com/bxcodec/go-clean-arch/models" - articleUcase "github.com/bxcodec/go-clean-arch/article/usecase" + articleUcase "github.com/bxcodec/go-clean-arch/article" "github.com/labstack/echo" validator "gopkg.in/go-playground/validator.v9" diff --git a/article/delivery/http/article_test.go b/article/delivery/http/article_test.go index 1e70ed7..5c5dff7 100644 --- a/article/delivery/http/article_test.go +++ b/article/delivery/http/article_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - models "github.com/bxcodec/go-clean-arch/article" articleHttp "github.com/bxcodec/go-clean-arch/article/delivery/http" - "github.com/bxcodec/go-clean-arch/article/usecase/mocks" + "github.com/bxcodec/go-clean-arch/article/mocks" + models "github.com/bxcodec/go-clean-arch/models" "github.com/labstack/echo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -116,7 +116,7 @@ func TestStore(t *testing.T) { j, err := json.Marshal(tempMockArticle) assert.NoError(t, err) - mockUCase.On("Store", mock.AnythingOfType("*article.Article")).Return(&mockArticle, nil) + mockUCase.On("Store", mock.AnythingOfType("*models.Article")).Return(&mockArticle, nil) e := echo.New() req, err := http.NewRequest(echo.POST, "/article", strings.NewReader(string(j))) diff --git a/article/repository/mocks/ArticleRepository.go b/article/mocks/ArticleRepository.go similarity index 63% rename from article/repository/mocks/ArticleRepository.go rename to article/mocks/ArticleRepository.go index c8dd4ea..7e68ef4 100644 --- a/article/repository/mocks/ArticleRepository.go +++ b/article/mocks/ArticleRepository.go @@ -1,7 +1,8 @@ +// Code generated by mockery v1.0.0 package mocks -import article "github.com/bxcodec/go-clean-arch/article" import mock "github.com/stretchr/testify/mock" +import models "github.com/bxcodec/go-clean-arch/models" // ArticleRepository is an autogenerated mock type for the ArticleRepository type type ArticleRepository struct { @@ -30,15 +31,15 @@ func (_m *ArticleRepository) Delete(id int64) (bool, error) { } // Fetch provides a mock function with given fields: cursor, num -func (_m *ArticleRepository) Fetch(cursor string, num int64) ([]*article.Article, error) { +func (_m *ArticleRepository) Fetch(cursor string, num int64) ([]*models.Article, error) { ret := _m.Called(cursor, num) - var r0 []*article.Article - if rf, ok := ret.Get(0).(func(string, int64) []*article.Article); ok { + var r0 []*models.Article + if rf, ok := ret.Get(0).(func(string, int64) []*models.Article); ok { r0 = rf(cursor, num) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*article.Article) + r0 = ret.Get(0).([]*models.Article) } } @@ -53,15 +54,15 @@ func (_m *ArticleRepository) Fetch(cursor string, num int64) ([]*article.Article } // GetByID provides a mock function with given fields: id -func (_m *ArticleRepository) GetByID(id int64) (*article.Article, error) { +func (_m *ArticleRepository) GetByID(id int64) (*models.Article, error) { ret := _m.Called(id) - var r0 *article.Article - if rf, ok := ret.Get(0).(func(int64) *article.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(int64) *models.Article); ok { r0 = rf(id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*article.Article) + r0 = ret.Get(0).(*models.Article) } } @@ -76,15 +77,15 @@ func (_m *ArticleRepository) GetByID(id int64) (*article.Article, error) { } // GetByTitle provides a mock function with given fields: title -func (_m *ArticleRepository) GetByTitle(title string) (*article.Article, error) { +func (_m *ArticleRepository) GetByTitle(title string) (*models.Article, error) { ret := _m.Called(title) - var r0 *article.Article - if rf, ok := ret.Get(0).(func(string) *article.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(string) *models.Article); ok { r0 = rf(title) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*article.Article) + r0 = ret.Get(0).(*models.Article) } } @@ -99,18 +100,18 @@ func (_m *ArticleRepository) GetByTitle(title string) (*article.Article, error) } // Store provides a mock function with given fields: a -func (_m *ArticleRepository) Store(a *article.Article) (int64, error) { +func (_m *ArticleRepository) Store(a *models.Article) (int64, error) { ret := _m.Called(a) var r0 int64 - if rf, ok := ret.Get(0).(func(*article.Article) int64); ok { + if rf, ok := ret.Get(0).(func(*models.Article) int64); ok { r0 = rf(a) } else { r0 = ret.Get(0).(int64) } var r1 error - if rf, ok := ret.Get(1).(func(*article.Article) error); ok { + if rf, ok := ret.Get(1).(func(*models.Article) error); ok { r1 = rf(a) } else { r1 = ret.Error(1) @@ -120,20 +121,20 @@ func (_m *ArticleRepository) Store(a *article.Article) (int64, error) { } // Update provides a mock function with given fields: _a0 -func (_m *ArticleRepository) Update(_a0 *article.Article) (*article.Article, error) { +func (_m *ArticleRepository) Update(_a0 *models.Article) (*models.Article, error) { ret := _m.Called(_a0) - var r0 *article.Article - if rf, ok := ret.Get(0).(func(*article.Article) *article.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(*models.Article) *models.Article); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*article.Article) + r0 = ret.Get(0).(*models.Article) } } var r1 error - if rf, ok := ret.Get(1).(func(*article.Article) error); ok { + if rf, ok := ret.Get(1).(func(*models.Article) error); ok { r1 = rf(_a0) } else { r1 = ret.Error(1) diff --git a/article/usecase/mocks/ArticleUsecase.go b/article/mocks/ArticleUsecase.go similarity index 55% rename from article/usecase/mocks/ArticleUsecase.go rename to article/mocks/ArticleUsecase.go index 2ad583c..78f1d81 100644 --- a/article/usecase/mocks/ArticleUsecase.go +++ b/article/mocks/ArticleUsecase.go @@ -1,7 +1,8 @@ +// Code generated by mockery v1.0.0 package mocks -import go_clean_archarticle "github.com/bxcodec/go-clean-arch/article" import mock "github.com/stretchr/testify/mock" +import models "github.com/bxcodec/go-clean-arch/models" // ArticleUsecase is an autogenerated mock type for the ArticleUsecase type type ArticleUsecase struct { @@ -30,15 +31,15 @@ func (_m *ArticleUsecase) Delete(id int64) (bool, error) { } // Fetch provides a mock function with given fields: cursor, num -func (_m *ArticleUsecase) Fetch(cursor string, num int64) ([]*go_clean_archarticle.Article, string, error) { +func (_m *ArticleUsecase) Fetch(cursor string, num int64) ([]*models.Article, string, error) { ret := _m.Called(cursor, num) - var r0 []*go_clean_archarticle.Article - if rf, ok := ret.Get(0).(func(string, int64) []*go_clean_archarticle.Article); ok { + var r0 []*models.Article + if rf, ok := ret.Get(0).(func(string, int64) []*models.Article); ok { r0 = rf(cursor, num) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*go_clean_archarticle.Article) + r0 = ret.Get(0).([]*models.Article) } } @@ -60,15 +61,15 @@ func (_m *ArticleUsecase) Fetch(cursor string, num int64) ([]*go_clean_archartic } // GetByID provides a mock function with given fields: id -func (_m *ArticleUsecase) GetByID(id int64) (*go_clean_archarticle.Article, error) { +func (_m *ArticleUsecase) GetByID(id int64) (*models.Article, error) { ret := _m.Called(id) - var r0 *go_clean_archarticle.Article - if rf, ok := ret.Get(0).(func(int64) *go_clean_archarticle.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(int64) *models.Article); ok { r0 = rf(id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*go_clean_archarticle.Article) + r0 = ret.Get(0).(*models.Article) } } @@ -83,15 +84,15 @@ func (_m *ArticleUsecase) GetByID(id int64) (*go_clean_archarticle.Article, erro } // GetByTitle provides a mock function with given fields: title -func (_m *ArticleUsecase) GetByTitle(title string) (*go_clean_archarticle.Article, error) { +func (_m *ArticleUsecase) GetByTitle(title string) (*models.Article, error) { ret := _m.Called(title) - var r0 *go_clean_archarticle.Article - if rf, ok := ret.Get(0).(func(string) *go_clean_archarticle.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(string) *models.Article); ok { r0 = rf(title) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*go_clean_archarticle.Article) + r0 = ret.Get(0).(*models.Article) } } @@ -106,20 +107,20 @@ func (_m *ArticleUsecase) GetByTitle(title string) (*go_clean_archarticle.Articl } // Store provides a mock function with given fields: _a0 -func (_m *ArticleUsecase) Store(_a0 *go_clean_archarticle.Article) (*go_clean_archarticle.Article, error) { +func (_m *ArticleUsecase) Store(_a0 *models.Article) (*models.Article, error) { ret := _m.Called(_a0) - var r0 *go_clean_archarticle.Article - if rf, ok := ret.Get(0).(func(*go_clean_archarticle.Article) *go_clean_archarticle.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(*models.Article) *models.Article); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*go_clean_archarticle.Article) + r0 = ret.Get(0).(*models.Article) } } var r1 error - if rf, ok := ret.Get(1).(func(*go_clean_archarticle.Article) error); ok { + if rf, ok := ret.Get(1).(func(*models.Article) error); ok { r1 = rf(_a0) } else { r1 = ret.Error(1) @@ -129,20 +130,20 @@ func (_m *ArticleUsecase) Store(_a0 *go_clean_archarticle.Article) (*go_clean_ar } // Update provides a mock function with given fields: ar -func (_m *ArticleUsecase) Update(ar *go_clean_archarticle.Article) (*go_clean_archarticle.Article, error) { +func (_m *ArticleUsecase) Update(ar *models.Article) (*models.Article, error) { ret := _m.Called(ar) - var r0 *go_clean_archarticle.Article - if rf, ok := ret.Get(0).(func(*go_clean_archarticle.Article) *go_clean_archarticle.Article); ok { + var r0 *models.Article + if rf, ok := ret.Get(0).(func(*models.Article) *models.Article); ok { r0 = rf(ar) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*go_clean_archarticle.Article) + r0 = ret.Get(0).(*models.Article) } } var r1 error - if rf, ok := ret.Get(1).(func(*go_clean_archarticle.Article) error); ok { + if rf, ok := ret.Get(1).(func(*models.Article) error); ok { r1 = rf(ar) } else { r1 = ret.Error(1) diff --git a/article/repository/repository.go b/article/repository.go similarity index 81% rename from article/repository/repository.go rename to article/repository.go index f65cdbd..efc836b 100644 --- a/article/repository/repository.go +++ b/article/repository.go @@ -1,6 +1,6 @@ -package repository +package article -import models "github.com/bxcodec/go-clean-arch/article" +import "github.com/bxcodec/go-clean-arch/models" type ArticleRepository interface { Fetch(cursor string, num int64) ([]*models.Article, error) diff --git a/article/repository/mysql_article.go b/article/repository/mysql_article.go index 82a537d..76f299f 100644 --- a/article/repository/mysql_article.go +++ b/article/repository/mysql_article.go @@ -4,18 +4,19 @@ import ( "database/sql" "fmt" - "github.com/bxcodec/go-clean-arch/author" + author "github.com/bxcodec/go-clean-arch/models" "github.com/sirupsen/logrus" - models "github.com/bxcodec/go-clean-arch/article" + article "github.com/bxcodec/go-clean-arch/article" + models "github.com/bxcodec/go-clean-arch/models" ) type mysqlArticleRepository struct { Conn *sql.DB } -func NewMysqlArticleRepository(Conn *sql.DB) ArticleRepository { +func NewMysqlArticleRepository(Conn *sql.DB) article.ArticleRepository { return &mysqlArticleRepository{Conn} } diff --git a/article/repository/mysqlarticle_test.go b/article/repository/mysqlarticle_test.go index 12ccf90..8a0cc96 100644 --- a/article/repository/mysqlarticle_test.go +++ b/article/repository/mysqlarticle_test.go @@ -4,10 +4,8 @@ import ( "testing" "time" - "github.com/bxcodec/go-clean-arch/author" - - models "github.com/bxcodec/go-clean-arch/article" articleRepo "github.com/bxcodec/go-clean-arch/article/repository" + models "github.com/bxcodec/go-clean-arch/models" "github.com/stretchr/testify/assert" sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1" ) @@ -60,7 +58,7 @@ func TestStore(t *testing.T) { Content: "Content", CreatedAt: now, UpdatedAt: now, - Author: author.Author{ + Author: models.Author{ ID: 1, Name: "Iman Tumorang", }, @@ -130,7 +128,7 @@ func TestUpdate(t *testing.T) { Content: "Content", CreatedAt: now, UpdatedAt: now, - Author: author.Author{ + Author: models.Author{ ID: 1, Name: "Iman Tumorang", }, diff --git a/article/usecase.go b/article/usecase.go new file mode 100644 index 0000000..61ad75c --- /dev/null +++ b/article/usecase.go @@ -0,0 +1,14 @@ +package article + +import ( + model "github.com/bxcodec/go-clean-arch/models" +) + +type ArticleUsecase interface { + Fetch(cursor string, num int64) ([]*model.Article, string, error) + GetByID(id int64) (*model.Article, error) + Update(ar *model.Article) (*model.Article, error) + GetByTitle(title string) (*model.Article, error) + Store(*model.Article) (*model.Article, error) + Delete(id int64) (bool, error) +} diff --git a/article/usecase/articleucase_test.go b/article/usecase/articleucase_test.go index 18df3f0..4a15d55 100644 --- a/article/usecase/articleucase_test.go +++ b/article/usecase/articleucase_test.go @@ -5,12 +5,10 @@ import ( "strconv" "testing" - "github.com/bxcodec/go-clean-arch/author" - - models "github.com/bxcodec/go-clean-arch/article" - "github.com/bxcodec/go-clean-arch/article/repository/mocks" + "github.com/bxcodec/go-clean-arch/article/mocks" ucase "github.com/bxcodec/go-clean-arch/article/usecase" - _authorMock "github.com/bxcodec/go-clean-arch/author/repository/mocks" + _authorMock "github.com/bxcodec/go-clean-arch/author/mocks" + models "github.com/bxcodec/go-clean-arch/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -25,7 +23,7 @@ func TestFetch(t *testing.T) { mockListArtilce := make([]*models.Article, 0) mockListArtilce = append(mockListArtilce, mockArticle) mockArticleRepo.On("Fetch", mock.AnythingOfType("string"), mock.AnythingOfType("int64")).Return(mockListArtilce, nil) - mockAuthor := &author.Author{ + mockAuthor := &models.Author{ ID: 1, Name: "Iman Tumorang", } @@ -73,7 +71,7 @@ func TestGetByID(t *testing.T) { mockArticleRepo.On("GetByID", mock.AnythingOfType("int64")).Return(&mockArticle, nil) defer mockArticleRepo.AssertCalled(t, "GetByID", mock.AnythingOfType("int64")) - mockAuthor := &author.Author{ + mockAuthor := &models.Author{ ID: 1, Name: "Iman Tumorang", } @@ -99,9 +97,7 @@ func TestStore(t *testing.T) { tempMockArticle.ID = 0 mockArticleRepo.On("GetByTitle", mock.AnythingOfType("string")).Return(nil, models.NOT_FOUND_ERROR) - mockArticleRepo.On("Store", mock.AnythingOfType("*article.Article")).Return(mockArticle.ID, nil) - defer mockArticleRepo.AssertCalled(t, "GetByTitle", mock.AnythingOfType("string")) - defer mockArticleRepo.AssertCalled(t, "Store", mock.AnythingOfType("*article.Article")) + mockArticleRepo.On("Store", mock.AnythingOfType("*models.Article")).Return(mockArticle.ID, nil) mockAuthorrepo := new(_authorMock.AuthorRepository) u := ucase.NewArticleUsecase(mockArticleRepo, mockAuthorrepo) @@ -111,7 +107,7 @@ func TestStore(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, a) assert.Equal(t, mockArticle.Title, tempMockArticle.Title) - + mockArticleRepo.AssertExpectations(t) } func TestDelete(t *testing.T) { diff --git a/article/usecase/artilce_ucase.go b/article/usecase/artilce_ucase.go index f2e5345..faabb5a 100644 --- a/article/usecase/artilce_ucase.go +++ b/article/usecase/artilce_ucase.go @@ -4,41 +4,31 @@ import ( "strconv" "time" - "github.com/bxcodec/go-clean-arch/author" + "github.com/bxcodec/go-clean-arch/models" "github.com/sirupsen/logrus" "github.com/bxcodec/go-clean-arch/article" - "github.com/bxcodec/go-clean-arch/article/repository" - _authorRepo "github.com/bxcodec/go-clean-arch/author/repository" + _authorRepo "github.com/bxcodec/go-clean-arch/author" ) -type ArticleUsecase interface { - Fetch(cursor string, num int64) ([]*article.Article, string, error) - GetByID(id int64) (*article.Article, error) - Update(ar *article.Article) (*article.Article, error) - GetByTitle(title string) (*article.Article, error) - Store(*article.Article) (*article.Article, error) - Delete(id int64) (bool, error) -} - type articleUsecase struct { - articleRepos repository.ArticleRepository + articleRepos article.ArticleRepository authorRepo _authorRepo.AuthorRepository } type authorChanel struct { - Author *author.Author + Author *models.Author Error error } -func NewArticleUsecase(a repository.ArticleRepository, ar _authorRepo.AuthorRepository) ArticleUsecase { +func NewArticleUsecase(a article.ArticleRepository, ar _authorRepo.AuthorRepository) article.ArticleUsecase { return &articleUsecase{ articleRepos: a, authorRepo: ar, } } -func (a *articleUsecase) getAuthorDetail(item *article.Article, authorChan chan authorChanel) { +func (a *articleUsecase) getAuthorDetail(item *models.Article, authorChan chan authorChanel) { defer func() { if r := recover(); r != nil { logrus.Debug("Recovered in ", r) @@ -52,7 +42,7 @@ func (a *articleUsecase) getAuthorDetail(item *article.Article, authorChan chan } authorChan <- holder } -func (a *articleUsecase) getAuthorDetails(data []*article.Article) ([]*article.Article, error) { +func (a *articleUsecase) getAuthorDetails(data []*models.Article) ([]*models.Article, error) { chAuthor := make(chan authorChanel) defer close(chAuthor) existingAuthorMap := make(map[int64]bool) @@ -65,7 +55,7 @@ func (a *articleUsecase) getAuthorDetails(data []*article.Article) ([]*article.A totalCall++ } - mapAuthor := make(map[int64]*author.Author) + mapAuthor := make(map[int64]*models.Author) totalGorutineCalled := len(existingAuthorMap) for i := 0; i < totalGorutineCalled; i++ { select { @@ -89,7 +79,7 @@ func (a *articleUsecase) getAuthorDetails(data []*article.Article) ([]*article.A return data, nil } -func (a *articleUsecase) Fetch(cursor string, num int64) ([]*article.Article, string, error) { +func (a *articleUsecase) Fetch(cursor string, num int64) ([]*models.Article, string, error) { if num == 0 { num = 10 } @@ -114,7 +104,7 @@ func (a *articleUsecase) Fetch(cursor string, num int64) ([]*article.Article, st return listArticle, nextCursor, nil } -func (a *articleUsecase) GetByID(id int64) (*article.Article, error) { +func (a *articleUsecase) GetByID(id int64) (*models.Article, error) { res, err := a.articleRepos.GetByID(id) if err != nil { @@ -129,12 +119,12 @@ func (a *articleUsecase) GetByID(id int64) (*article.Article, error) { return res, nil } -func (a *articleUsecase) Update(ar *article.Article) (*article.Article, error) { +func (a *articleUsecase) Update(ar *models.Article) (*models.Article, error) { ar.UpdatedAt = time.Now() return a.articleRepos.Update(ar) } -func (a *articleUsecase) GetByTitle(title string) (*article.Article, error) { +func (a *articleUsecase) GetByTitle(title string) (*models.Article, error) { res, err := a.articleRepos.GetByTitle(title) if err != nil { @@ -150,11 +140,11 @@ func (a *articleUsecase) GetByTitle(title string) (*article.Article, error) { return res, nil } -func (a *articleUsecase) Store(m *article.Article) (*article.Article, error) { +func (a *articleUsecase) Store(m *models.Article) (*models.Article, error) { existedArticle, _ := a.GetByTitle(m.Title) if existedArticle != nil { - return nil, article.CONFLIT_ERROR + return nil, models.CONFLIT_ERROR } id, err := a.articleRepos.Store(m) @@ -171,7 +161,7 @@ func (a *articleUsecase) Delete(id int64) (bool, error) { logrus.Info("Masuk Sini") if existedArticle == nil { logrus.Info("Masuk Sini2") - return false, article.NOT_FOUND_ERROR + return false, models.NOT_FOUND_ERROR } logrus.Info("Masuk Sini3") diff --git a/author/repository/mocks/AuthorRepository.go b/author/mocks/AuthorRepository.go similarity index 62% rename from author/repository/mocks/AuthorRepository.go rename to author/mocks/AuthorRepository.go index a4954f1..0219cc7 100644 --- a/author/repository/mocks/AuthorRepository.go +++ b/author/mocks/AuthorRepository.go @@ -1,7 +1,8 @@ +// Code generated by mockery v1.0.0 package mocks -import author "github.com/bxcodec/go-clean-arch/author" import mock "github.com/stretchr/testify/mock" +import models "github.com/bxcodec/go-clean-arch/models" // AuthorRepository is an autogenerated mock type for the AuthorRepository type type AuthorRepository struct { @@ -9,15 +10,15 @@ type AuthorRepository struct { } // GetByID provides a mock function with given fields: id -func (_m *AuthorRepository) GetByID(id int64) (*author.Author, error) { +func (_m *AuthorRepository) GetByID(id int64) (*models.Author, error) { ret := _m.Called(id) - var r0 *author.Author - if rf, ok := ret.Get(0).(func(int64) *author.Author); ok { + var r0 *models.Author + if rf, ok := ret.Get(0).(func(int64) *models.Author); ok { r0 = rf(id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*author.Author) + r0 = ret.Get(0).(*models.Author) } } diff --git a/author/repository.go b/author/repository.go new file mode 100644 index 0000000..1df32fe --- /dev/null +++ b/author/repository.go @@ -0,0 +1,7 @@ +package author + +import "github.com/bxcodec/go-clean-arch/models" + +type AuthorRepository interface { + GetByID(id int64) (*models.Author, error) +} diff --git a/author/repository/mysql_repository.go b/author/repository/mysql_repository.go index 180f113..7172d1a 100644 --- a/author/repository/mysql_repository.go +++ b/author/repository/mysql_repository.go @@ -6,20 +6,21 @@ import ( "github.com/sirupsen/logrus" "github.com/bxcodec/go-clean-arch/author" + "github.com/bxcodec/go-clean-arch/models" ) type mysqlAuthorRepo struct { DB *sql.DB } -func NewMysqlAuthorRepository(db *sql.DB) AuthorRepository { +func NewMysqlAuthorRepository(db *sql.DB) author.AuthorRepository { return &mysqlAuthorRepo{ DB: db, } } -func (m *mysqlAuthorRepo) getOne(query string, args ...interface{}) (*author.Author, error) { +func (m *mysqlAuthorRepo) getOne(query string, args ...interface{}) (*models.Author, error) { stmt, err := m.DB.Prepare(query) if err != nil { @@ -27,7 +28,7 @@ func (m *mysqlAuthorRepo) getOne(query string, args ...interface{}) (*author.Aut return nil, err } row := stmt.QueryRow(args...) - a := &author.Author{} + a := &models.Author{} err = row.Scan( &a.ID, @@ -43,7 +44,7 @@ func (m *mysqlAuthorRepo) getOne(query string, args ...interface{}) (*author.Aut return a, nil } -func (m *mysqlAuthorRepo) GetByID(id int64) (*author.Author, error) { +func (m *mysqlAuthorRepo) GetByID(id int64) (*models.Author, error) { query := `SELECT id, name, created_at, updated_at FROM author WHERE id=?` return m.getOne(query, id) } diff --git a/author/repository/repository.go b/author/repository/repository.go deleted file mode 100644 index 8a41e03..0000000 --- a/author/repository/repository.go +++ /dev/null @@ -1,7 +0,0 @@ -package repository - -import "github.com/bxcodec/go-clean-arch/author" - -type AuthorRepository interface { - GetByID(id int64) (*author.Author, error) -} diff --git a/config/env/config.go b/config/env/config.go deleted file mode 100644 index 9acc7c1..0000000 --- a/config/env/config.go +++ /dev/null @@ -1,51 +0,0 @@ -package env - -import ( - "strings" - - "github.com/spf13/viper" -) - -type Config interface { - GetString(key string) string - GetInt(key string) int - GetBool(key string) bool - Init() -} - -type viperConfig struct { -} - -func (v *viperConfig) Init() { - viper.SetEnvPrefix(`go-clean`) - viper.AutomaticEnv() - - replacer := strings.NewReplacer(`.`, `_`) - viper.SetEnvKeyReplacer(replacer) - viper.SetConfigType(`json`) - viper.SetConfigFile(`config.json`) - err := viper.ReadInConfig() - - if err != nil { - panic(err) - } - -} - -func (v *viperConfig) GetString(key string) string { - return viper.GetString(key) -} - -func (v *viperConfig) GetInt(key string) int { - return viper.GetInt(key) -} - -func (v *viperConfig) GetBool(key string) bool { - return viper.GetBool(key) -} - -func NewViperConfig() Config { - v := &viperConfig{} - v.Init() - return v -} diff --git a/glide.lock b/glide.lock deleted file mode 100644 index 52620c3..0000000 --- a/glide.lock +++ /dev/null @@ -1,100 +0,0 @@ -hash: b877db15acca9c939d4be64b2668b07ab415c2568f947d2fe433fdcde86c7173 -updated: 2018-02-01T07:31:55.232886+07:00 -imports: -- name: github.com/bxcodec/faker - version: 7c5fff7ed02e14ac848ef83aee45b95627c96ae2 -- name: github.com/davecgh/go-spew - version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 - subpackages: - - spew -- name: github.com/fsnotify/fsnotify - version: c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9 -- name: github.com/go-playground/locales - version: e4cbcb5d0652150d40ad0646651076b6bd2be4f6 - subpackages: - - currency -- name: github.com/go-playground/universal-translator - version: b32fa301c9fe55953584134cb6853a13c87ec0a1 -- name: github.com/go-sql-driver/mysql - version: a0583e0143b1624142adab07e0e97fe106d99561 -- name: github.com/hashicorp/hcl - version: 23c074d0eceb2b8a5bfdbb271ab780cde70f05a8 - subpackages: - - hcl/ast - - hcl/parser - - hcl/printer - - hcl/scanner - - hcl/strconv - - hcl/token - - json/parser - - json/scanner - - json/token -- name: github.com/labstack/echo - version: 1049c9613cd371b7ea8f219404c9a821734781ed -- name: github.com/labstack/gommon - version: 1121fd3e243c202482226a7afe4dcd07ffc4139a - subpackages: - - color - - log -- name: github.com/magiconair/properties - version: 49d762b9817ba1c2e9d0c69183c2b4a8b8f1d934 -- name: github.com/mattn/go-colorable - version: 6cc8b475d4682021d75d2cbe2bc481bec4ce98e5 -- name: github.com/mattn/go-isatty - version: 6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c -- name: github.com/mitchellh/mapstructure - version: b4575eea38cca1123ec2dc90c26529b5c5acfcff -- name: github.com/pelletier/go-toml - version: acdc4509485b587f5e675510c4f2c63e90ff68a8 -- name: github.com/pmezard/go-difflib - version: d8ed2627bdf02c080bf22230dbb337003b7aba2d - subpackages: - - difflib -- name: github.com/sirupsen/logrus - version: d682213848ed68c0a260ca37d6dd5ace8423f5ba -- name: github.com/spf13/afero - version: bb8f1927f2a9d3ab41c9340aa034f6b803f4359c - subpackages: - - mem -- name: github.com/spf13/cast - version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 -- name: github.com/spf13/jwalterweatherman - version: 7c0cea34c8ece3fbeb2b27ab9b59511d360fb394 -- name: github.com/spf13/pflag - version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea -- name: github.com/spf13/viper - version: aafc9e6bc7b7bb53ddaa75a5ef49a17d6e654be5 -- name: github.com/stretchr/objx - version: cbeaeb16a013161a98496fad62933b1d21786672 -- name: github.com/stretchr/testify - version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 - subpackages: - - assert - - mock -- name: github.com/valyala/bytebufferpool - version: e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7 -- name: github.com/valyala/fasttemplate - version: dcecefd839c4193db0d35b88ec65b4c12d360ab0 -- name: golang.org/x/crypto - version: 1875d0a70c90e57f11972aefd42276df65e895b9 - subpackages: - - acme - - acme/autocert - - ssh/terminal -- name: golang.org/x/sys - version: 3dbebcf8efb6a5011a60c2b4591c1022a759af8a - subpackages: - - unix - - windows -- name: golang.org/x/text - version: e19ae1496984b1c655b8044a65c0300a3c878dd3 - subpackages: - - transform - - unicode/norm -- name: gopkg.in/DATA-DOG/go-sqlmock.v1 - version: b983233bc0bbea4dc6e8ec8c8c923d935765ffec -- name: gopkg.in/go-playground/validator.v9 - version: 48a433ba4bcadc5be9aa16d4bdcb383d3f57a741 -- name: gopkg.in/yaml.v2 - version: d670f9405373e636a5a2765eea47fac0c9bc91a4 -testImports: [] diff --git a/glide.yaml b/glide.yaml deleted file mode 100644 index ca93aeb..0000000 --- a/glide.yaml +++ /dev/null @@ -1,27 +0,0 @@ -package: github.com/bxcodec/go-clean-arch -import: -- package: github.com/stretchr/testify - version: v1.1.4 - subpackages: - - mock - - assert -- package: github.com/labstack/echo - version: v3.1.0 -- package: github.com/labstack/gommon - version: v0.2.1 - subpackages: - - log -- package: github.com/spf13/viper -- package: github.com/spf13/afero -- package: github.com/go-sql-driver/mysql - version: v1.3 -- package: github.com/bxcodec/faker - version: ~1.1.0 -- package: gopkg.in/DATA-DOG/go-sqlmock.v1 - version: v1.2.0 -- package: gopkg.in/go-playground/validator.v9 - version: ^9.8.0 -- package: github.com/go-playground/universal-translator - version: ^0.16.0 -- package: github.com/sirupsen/logrus - version: ^1.0.4 diff --git a/main.go b/main.go index bf4a310..01f73ed 100644 --- a/main.go +++ b/main.go @@ -3,24 +3,29 @@ package main import ( "database/sql" "fmt" + "log" "net/url" + "os" httpDeliver "github.com/bxcodec/go-clean-arch/article/delivery/http" articleRepo "github.com/bxcodec/go-clean-arch/article/repository" articleUcase "github.com/bxcodec/go-clean-arch/article/usecase" _authorRepo "github.com/bxcodec/go-clean-arch/author/repository" - cfg "github.com/bxcodec/go-clean-arch/config/env" - "github.com/bxcodec/go-clean-arch/config/middleware" + "github.com/bxcodec/go-clean-arch/middleware" _ "github.com/go-sql-driver/mysql" "github.com/labstack/echo" + "github.com/spf13/viper" ) -var config cfg.Config - func init() { - config = cfg.NewViperConfig() + viper.SetConfigFile(`config.json`) + err := viper.ReadInConfig() + + if err != nil { + panic(err) + } - if config.GetBool(`debug`) { + if viper.GetBool(`debug`) { fmt.Println("Service RUN on DEBUG mode") } @@ -28,20 +33,26 @@ func init() { func main() { - dbHost := config.GetString(`database.host`) - dbPort := config.GetString(`database.port`) - dbUser := config.GetString(`database.user`) - dbPass := config.GetString(`database.pass`) - dbName := config.GetString(`database.name`) + dbHost := viper.GetString(`database.host`) + dbPort := viper.GetString(`database.port`) + dbUser := viper.GetString(`database.user`) + dbPass := viper.GetString(`database.pass`) + dbName := viper.GetString(`database.name`) connection := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", dbUser, dbPass, dbHost, dbPort, dbName) val := url.Values{} val.Add("parseTime", "1") val.Add("loc", "Asia/Jakarta") dsn := fmt.Sprintf("%s?%s", connection, val.Encode()) dbConn, err := sql.Open(`mysql`, dsn) - if err != nil && config.GetBool("debug") { + if err != nil && viper.GetBool("debug") { fmt.Println(err) } + err = dbConn.Ping() + if err != nil { + log.Fatal(err) + os.Exit(1) + } + defer dbConn.Close() e := echo.New() middL := middleware.InitMiddleware() @@ -52,5 +63,5 @@ func main() { httpDeliver.NewArticleHttpHandler(e, au) - e.Start(config.GetString("server.address")) + e.Start(viper.GetString("server.address")) } diff --git a/config/middleware/middleware.go b/middleware/middleware.go similarity index 100% rename from config/middleware/middleware.go rename to middleware/middleware.go diff --git a/config/middleware/middleware_test.go b/middleware/middleware_test.go similarity index 90% rename from config/middleware/middleware_test.go rename to middleware/middleware_test.go index 2661cea..10bd4e3 100644 --- a/config/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/bxcodec/go-clean-arch/config/middleware" + "github.com/bxcodec/go-clean-arch/middleware" "github.com/labstack/echo" test "net/http/httptest" diff --git a/models/article.go b/models/article.go new file mode 100644 index 0000000..e66eb36 --- /dev/null +++ b/models/article.go @@ -0,0 +1,14 @@ +package models + +import ( + "time" +) + +type Article struct { + ID int64 `json:"id"` + Title string `json:"title" validate:"required"` + Content string `json:"content" validate:"required"` + Author Author `json:"author"` + UpdatedAt time.Time `json:"updated_at"` + CreatedAt time.Time `json:"created_at"` +} diff --git a/author/author.go b/models/author.go similarity index 91% rename from author/author.go rename to models/author.go index 28df97d..a4e57a0 100644 --- a/author/author.go +++ b/models/author.go @@ -1,4 +1,4 @@ -package author +package models type Author struct { ID int64 `json:"id"` diff --git a/article/errors.go b/models/errors.go similarity index 93% rename from article/errors.go rename to models/errors.go index dad7712..79d50df 100644 --- a/article/errors.go +++ b/models/errors.go @@ -1,4 +1,4 @@ -package article +package models import "errors"