Skip to content

Commit

Permalink
Update swaggo/swag to v1.7.4; Add go-critic; Fix swaggo/swag issue fo…
Browse files Browse the repository at this point in the history
…r docs gen (go1.17+)
  • Loading branch information
koddr committed Oct 26, 2021
1 parent 7880444 commit f218cf7
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ DATABASE_URL = postgres://postgres:password@cgapp-postgres/postgres?sslmode=disa
clean:
rm -rf ./build

critic:
gocritic check -enableAll ./...

security:
gosec -quiet ./...
gosec ./...

linter:
golangci-lint run
lint:
golangci-lint run ./...

test: security
test: clean critic security lint
go test -v -timeout 30s -coverprofile=cover.out -cover ./...
go tool cover -func=cover.out

build: clean test
build: test
CGO_ENABLED=0 go build -ldflags="-w -s" -o $(BUILD_DIR)/$(APP_NAME) main.go

run: swag build
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ cgapp create
- [golang-migrate/migrate](https://github.com/golang-migrate/migrate#cli-usage) for apply migrations
- [github.com/swaggo/swag](https://github.com/swaggo/swag) for auto-generating Swagger API docs
- [github.com/securego/gosec](https://github.com/securego/gosec) for checking Go security issues
- [github.com/go-critic/go-critic](https://github.com/go-critic/go-critic) for checking Go the best practice issues
- [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) for checking Go linter issues

4. Run project by this command:

Expand All @@ -48,7 +50,7 @@ make docker.run
| [joho/godotenv](https://github.com/joho/godotenv) | `v1.4.0` | config |
| [jmoiron/sqlx](https://github.com/jmoiron/sqlx) | `v1.3.4` | database |
| [jackc/pgx](https://github.com/jackc/pgx) | `v4.13.0` | database |
| [swaggo/swag](https://github.com/swaggo/swag) | `v1.7.3` | utils |
| [swaggo/swag](https://github.com/swaggo/swag) | `v1.7.4` | utils |
| [google/uuid](https://github.com/google/uuid) | `v1.3.0` | utils |
| [go-playground/validator](https://github.com/go-playground/validator) | `v10.9.0` | utils |

Expand Down
19 changes: 12 additions & 7 deletions docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/create-go-app/net_http-go-template
go 1.17

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/auth0/go-jwt-middleware v1.0.1
github.com/go-playground/validator/v10 v10.9.0
github.com/golang-jwt/jwt/v4 v4.1.0
Expand All @@ -13,7 +12,7 @@ require (
github.com/jmoiron/sqlx v1.3.4
github.com/joho/godotenv v1.4.0
github.com/swaggo/http-swagger v1.1.2
github.com/swaggo/swag v1.7.3
github.com/swaggo/swag v1.7.4
)

require (
Expand All @@ -39,8 +38,8 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e // indirect
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/auth0/go-jwt-middleware v1.0.1 h1:/fsQ4vRr4zod1wKReUH+0A3ySRjGiT9G34kypO/EKwI=
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
Expand Down Expand Up @@ -197,8 +196,8 @@ github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9J
github.com/swaggo/http-swagger v1.1.2 h1:ikcSD+EUOx+2oNZ2N6u8IYa8ScOsAvE7Jh+E1dW6i94=
github.com/swaggo/http-swagger v1.1.2/go.mod h1:mX5nhypDmoSt4iw2mc5aKXxRFvp1CLLcCiog2B9M+Ro=
github.com/swaggo/swag v1.7.0/go.mod h1:BdPIL73gvS9NBsdi7M1JOxLvlbfvNRaBP8m6WT6Aajo=
github.com/swaggo/swag v1.7.3 h1:ucB7irEdRrhjmW+Z1Ss4GjO68oPKQFjSgOR8BCAvcbU=
github.com/swaggo/swag v1.7.3/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
github.com/swaggo/swag v1.7.4 h1:up+ixy8yOqJKiFcuhMgkuYuF4xnevuhnFAXXF8OSfNg=
github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
Expand Down Expand Up @@ -245,8 +244,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e h1:Xj+JO91noE97IN6F/7WZxzC5QE6yENAQPrwIYhW3bsA=
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309 h1:A0lJIi+hcTR6aajJH4YqKWwohY4aW9RO7oRMcdv+HKI=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -268,8 +267,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/jwt_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ func GenerateNewJWTAccessToken(credentials []string, id string) (string, error)
// GenerateNewJWTRefreshToken func for generate a new JWT refresh (public) token.
func GenerateNewJWTRefreshToken() (string, error) {
// Create a new SHA256 hash.
sha256 := sha256.New()
hash := sha256.New()

// Create a new now date and time string with salt.
refresh := os.Getenv("JWT_REFRESH_KEY") + time.Now().String()

// See: https://pkg.go.dev/io#Writer.Write
_, err := sha256.Write([]byte(refresh))
_, err := hash.Write([]byte(refresh))
if err != nil {
// Return error, it refresh token generation failed.
return "", err
}

return hex.EncodeToString(sha256.Sum(nil)), nil
return hex.EncodeToString(hash.Sum(nil)), nil
}
1 change: 0 additions & 1 deletion pkg/utils/start_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ func StartServerWithGracefulShutdown(server *http.Server) {
// <-ctx.Done() if your application should wait for other services
// to finalize based on context cancellation.
log.Println("Server is shutting down...")
os.Exit(0)
}
9 changes: 6 additions & 3 deletions platform/database/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ func PostgreSQLConnection() (*sqlx.DB, error) {
}

// Set database connection settings:
db.SetMaxOpenConns(maxConn) // the default is 0 (unlimited)
db.SetMaxIdleConns(maxIdleConn) // defaultMaxIdleConns = 2
db.SetConnMaxLifetime(time.Duration(maxLifetimeConn)) // 0, connections are reused forever
// - SetMaxOpenConns: the default is 0 (unlimited)
// - SetMaxIdleConns: defaultMaxIdleConns = 2
// - SetConnMaxLifetime: 0, connections are reused forever
db.SetMaxOpenConns(maxConn)
db.SetMaxIdleConns(maxIdleConn)
db.SetConnMaxLifetime(time.Duration(maxLifetimeConn))

// Try to ping database.
if err := db.Ping(); err != nil {
Expand Down

0 comments on commit f218cf7

Please sign in to comment.