Skip to content

Commit 3192b5d

Browse files
authored
Merge pull request #20 from dung13890/develop
Upgrade version v1.2.0
2 parents c3dafa3 + 8e1e3ce commit 3192b5d

File tree

94 files changed

+2904
-1210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2904
-1210
lines changed

.docker/local/go/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ RUN go mod download
1414
RUN go install github.com/cosmtrek/air@latest
1515
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
1616
RUN go install github.com/golang/mock/mockgen@v1.6.0
17+
RUN go install github.com/dung13890/go-base-gen@latest

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ APP_ENV=local
22
APP_ALLOWED_ORIGIN=*,localhost
33
APP_HOST=0.0.0.0:8080
44
APP_JWT_KEY=go-clean-architecture
5+
APP_TIME_ZONE=Asia/Ho_Chi_Minh
56

67
DB_CONNECTION=postgres
78
DB_HOST=db
@@ -12,6 +13,16 @@ DB_PASSWORD=secret
1213
DB_SSLMODE=disable
1314
DB_DEBUG=true
1415

16+
REDIS_HOST=redis
17+
REDIS_PASSWORD=null
18+
REDIS_PORT=6379
19+
20+
MAIL_HOST=mailpit
21+
MAIL_PORT=1025
22+
MAIL_USERNAME=null
23+
MAIL_PASSWORD=null
24+
MAIL_FROM_ADDRESS=hello@example.com
25+
1526
DOCKER_UID=USER_ID
1627
DOCKER_GID=GROUP_ID
1728

.golangci.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ linters:
1616
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
1717
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
1818
- unused # checks for unused constants, variables, functions and types
19+
- revive # fast, configurable, extensible, flexible, and beautiful linter for go. drop-in replacement of golint.
1920
## disabled by default
2021
- asasalint # checks for pass []any as any in variadic func(...any)
2122
- asciicheck # checks that your code does not contain non-ASCII identifiers
2223
- bidichk # checks for dangerous unicode character sequences
2324
- bodyclose # checks whether HTTP response body is closed successfully
2425
- cyclop # checks function and package cyclomatic complexity
25-
- dupl # tool for code clone detection
26+
# - dupl # tool for code clone detection
27+
- goerr113 # go linter to check the errors handling expressions
2628
- durationcheck # checks for two durations multiplied together
2729
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
2830
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
@@ -71,9 +73,23 @@ linters:
7173
- whitespace # detects leading and trailing whitespace
7274

7375
linters-settings:
76+
gomnd:
77+
ignored-files:
78+
'errors/code.go'
79+
revive:
80+
ignore-generated-header: true
81+
severity: error
82+
rules:
83+
# https://github.com/mgechev/revive#available-rules
84+
- name: exported
85+
- name: unused-parameter
86+
- name: unused-receiver
87+
- name: waitgroup-by-value
88+
7489
funlen:
7590
lines: 270
7691
statements: 50
92+
7793
gocognit:
7894
# minimal code complexity to report, 30 by default (but we recommend 10-20)
7995
min-complexity: 35
@@ -106,6 +122,7 @@ issues:
106122
- path: _test\.go
107123
linters:
108124
- bodyclose
125+
- revive
109126
- scopelint
110127
- funlen
111128
- gocognit

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Dũng
3+
Copyright (c) 2022 dung13890
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ test: ### run test
1010
go test -v -race -coverprofile=cover.out -coverpkg=./... ./...
1111
go tool cover -func cover.out
1212

13-
.PHONY: build-mock
13+
.PHONY: go-gen lint test
1414
# put the files with interfaces you'd like to mock in prerequisites
1515
# wildcards are allowed
1616

1717
go-gen:
1818
@echo "Generating mocks..."
19+
rm -rf internal/domain/mock/*_mock.go
1920
go generate -x ./internal/...
21+
@echo "Generating pkg mocks..."
22+
rm -rf pkg/*/mock/*_mock.go
23+
go generate -x ./pkg/...
24+
25+
dev:
26+
air -c cmd/app/.air.toml

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# go-clean-architecture
22
![workflow status](https://github.com/dung13890/go-clean-architecture/actions/workflows/go-ci.yml/badge.svg)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
34

45
Codebase for golang use clean architecture.
56

@@ -20,6 +21,7 @@ More at [https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture
2021
- [Quick start](#quick-start)
2122
- [Project structure](#project-structure)
2223
- [Tools Used](#tools-used)
24+
- [Tools Generate](#tool-generate)
2325

2426
## Quick start
2527
Below are some modules included in this project:
@@ -36,6 +38,9 @@ docker compose build
3638

3739
Start development:
3840
```bash
41+
# Install dependencies
42+
go mod tidy
43+
3944
# Copy env
4045
cp .env.example .env
4146

@@ -90,6 +95,31 @@ curl -X POST 'localhost:8080/api/login' \
9095
}'
9196
```
9297

98+
## Tool Generate
99+
If you need to generate a code base like this architecture, you can use [go-base-gen](https://github.com/dung13890/go-base-gen) tool.
100+
You can read more about the tool at [README](https://github.com/dung13890/go-base-gen/blob/master/README.md#usage)
101+
```bash
102+
NAME:
103+
go-base-gen - Use this tool to generate base code
104+
105+
USAGE:
106+
go-base-gen [global options] command [command options] [arguments...]
107+
108+
VERSION:
109+
v1.0.0
110+
111+
COMMANDS:
112+
project Generate base code for go project use clean architecture
113+
domain Create new domain in project
114+
help, h Shows a list of commands or help for one command
115+
116+
GLOBAL OPTIONS:
117+
--help, -h show help
118+
--version, -v print only the version (default: false)
119+
```
120+
121+
The [go-base-gen](https://github.com/dung13890/go-base-gen) tool was created with the purpose to help developers save their time in creating a project with a clean architecture. The tool will generate the code base for you, you just need to focus on the business logic.
122+
93123
## Project structure
94124
![Clean Architecture](CleanArchitecture.jpeg)
95125

@@ -193,3 +223,6 @@ func (hl *roleHandler) Index(c echo.Context) error {
193223
- [Echo](https://echo.labstack.com)
194224
- [JWT](https://golang-jwt.github.io/jwt)
195225
- [cosmtrek/air](https://github.com/cosmtrek/air)
226+
- [go-base-gen](https://github.com/dung13890/go-base-gen)
227+
228+
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/dung13890)

cmd/app/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"go-app/config"
55
"go-app/internal/app"
66
"go-app/pkg/logger"
7+
"time"
78
)
89

910
func main() {
@@ -13,6 +14,12 @@ func main() {
1314
}
1415

1516
conf := config.GetAppConfig()
17+
// Set timezone
18+
loc, err := time.LoadLocation(conf.AppTimeZone)
19+
if err != nil {
20+
logger.Error().Fatal(err)
21+
}
22+
time.Local = loc
1623

1724
if err := app.Run(conf); err != nil {
1825
logger.Error().Fatal(err)

cmd/migrate/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"go-app/config"
55
"go-app/pkg/logger"
66
"go-app/pkg/postgres"
7+
"time"
78
)
89

910
func main() {
@@ -12,6 +13,15 @@ func main() {
1213
logger.Error().Fatal(err)
1314
}
1415

16+
conf := config.GetAppConfig()
17+
18+
// Set timezone
19+
loc, err := time.LoadLocation(conf.AppTimeZone)
20+
if err != nil {
21+
logger.Error().Fatal(err)
22+
}
23+
time.Local = loc
24+
1525
db := config.GetDBConfig()
1626

1727
if err := postgres.Migrate(db); err != nil {

cmd/seed/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"go-app/config"
55
"go-app/internal/app"
66
"go-app/pkg/logger"
7+
"time"
78
)
89

910
func main() {
@@ -12,6 +13,15 @@ func main() {
1213
logger.Error().Fatal(err)
1314
}
1415

16+
conf := config.GetAppConfig()
17+
18+
// Set timezone
19+
loc, err := time.LoadLocation(conf.AppTimeZone)
20+
if err != nil {
21+
logger.Error().Fatal(err)
22+
}
23+
time.Local = loc
24+
1525
dbConfig := config.GetDBConfig()
1626
if err := app.Seed(dbConfig); err != nil {
1727
logger.Error().Fatal(err)

config/app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ type AppConfig struct {
1313
AllowedOrigin string `mapstructure:"APP_ALLOWED_ORIGIN"`
1414
AppHost string `mapstructure:"APP_HOST"`
1515
AppJWTKey string `mapstructure:"APP_JWT_KEY"`
16+
AppTimeZone string `mapstructure:"APP_TIME_ZONE"`
1617
}
1718

1819
// LoadConfig config setting from .env.
1920
func LoadConfig() error {
2021
viper.SetConfigFile(".env")
2122

2223
if err := viper.ReadInConfig(); err != nil {
23-
return errors.Wrap(err)
24+
return errors.ErrInternalServerError.Wrap(err)
2425
}
2526

2627
return nil

0 commit comments

Comments
 (0)