You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Go code with [chi](https://github.com/go-chi/chi) http router, [zerolog](https://github.com/rs/zerolog) logging, [knadh/koanf](github.com/knadh/koanf) config library and [testify](github.com/stretchr/testify). Basic code infra with http setup and request and response logger (configurable), logging setup, config setup and graceful shutdown.
* Basic code infra with http setup and request and response logger (configurable), logging setup, config setup and graceful shutdown.
10
+
* Optional verbose logging of http traffic, with payload,
5
11
* Makefile targets for local installation of external tools (`staticcheck`, `golangci-lint`, `goimports`, `gofumpt`, `gojq`, `air`).
6
12
* Makefile targets for linting (installing all necessary tools locally), building, testing, and local run (docker compose or native).
7
13
*[GitHub Actions](https://github.com/features/actions) for linter checks and tests on each pr.
8
14
*[Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates) setup for updating dependencies.
9
15
*[Visual Studio Code](https://code.visualstudio.com/) settings, tasks and launch configuration for building, debugging and testing the code.
10
16
* Docker compose and development Dockerfile with hot-rebuild (using [air](https://github.com/air-verse/air)) and dlv debug server.
11
-
* Production Dockerfile
17
+
* Production Dockerfile.
12
18
13
19
## How to use
14
20
1. Click `Use this template` from this repo github page, and choose your destination repo/name (e.g. `github.com/glendale/service`)
@@ -17,6 +23,7 @@ The boilerplate consists of:
17
23
18
24
19
25
## Go package and file structure
26
+
The project structure attempts to be on a par with [golang-standards/project-layout](https://github.com/golang-standards/project-layout).
20
27
21
28
> Every local package that collides with a golang std package is named with `x` postfix. For example `.../internal/httpx` or `.../internal/logx`. By doing this cheat you can avoid putting aliases when you need both of those and you can take advantage of package autocomplete/autoimport features more easily than having colliding names.
22
29
@@ -26,125 +33,12 @@ The boilerplate consists of:
26
33
|`internal/exec.go`| the `Main` struct that wraps the long running / signal handling / graceful shutdown of the service |
27
34
|`internal/config`| this package contain the initialization of `koanf` config. |
28
35
|`internal/httpx`| this package contains: the setup of the `chi` router, some helpers functions for parsing/writing http request and http response and some middlewares like for logging each request/response. |
29
-
|`internal/logx`| this package contains the setup/init function for `zerolog` logger. |
36
+
|`internal/logx`| this package contains the setup/init function for `slog` logger. |
|`deployments`| this folder is intended to hold everything regarding deployment (e.g. helm/kubernetes etc). Inside `compose` directory a `docker-compose.yml` file is included that is intended for local development. |
40
+
|`deployments`| this folder is intended to hold everything regarding deployment (e.g. helm/kubernetes etc). Inside `local` directory a `docker-compose.yml` file is included that is intended for local development. |
34
41
|`build/docker`| this folder contains production-like docker file as well as a local development one. |
35
42
36
-
37
-
38
-
39
-
## Make file targets
40
-
41
-
42
-
### Build, Debug and Local Deploy Targets
43
-
44
-
#### `build`
45
-
Builds all binaries under `./cmd` (one for each directory) and outputs the binaries into `./output` folder using this patter `./cmd/<directory name> -> ./output/<directory name>`.
46
-
___
47
-
48
-
#### `cmd.<directory name>`
49
-
Builds a specific cmd directory `<directory name>` and outputs the binary into `./output` folder using this pattern `./cmd/<directory name> -> ./output/<directory name>`.
50
-
___
51
-
52
-
#### `clean`
53
-
Deletes `./output` folder.
54
-
___
55
-
56
-
#### `compose-up`
57
-
Deploys (rebuilds and recreates) the docker compose file `deployments/compose/docker-compose.yml` in attached mode. This docker compose file is intended for local development.<br>
58
-
It uses the docker file `build/docker/debug.Dockerfile` and runs `air` target (see below), including hot-reload (rebuild on changes) and debug server.
59
-
___
60
-
61
-
#### `compose-down`
62
-
Stops (if started) the containers specified by the docker compose file `deployments/compose/docker-compose.yml` removes containers, cleans up the volumes and delete local docker images.
63
-
___
64
-
65
-
#### `air`
66
-
Installs (if needed) [air](https://github.com/air-verse/air) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `air -c .air.toml`. <br>
67
-
Air watches for code file changes and rebuilds the binary according to the configuration `.air.toml`. <br>
68
-
Current air configuration executes `cmd.goboilerplate` target (on each file change) and then runs the `./build/dlv` that starts the debug server (`dlv exec`) with the produced binary.
69
-
___
70
-
71
-
#### `image`
72
-
Builds the docker image using the docker file `./build/docker/Dockerfile`. <br>
73
-
This docker file is intended to be used as a production image. <br>
74
-
Image name and tag are specified by `IMAGE_NAME` and `IMAGE_TAG`. Default values can be overwritten during execution (eg `make IMAGE_NAME=myimage IMAGE_TAG=1.0.0 image`).
75
-
___
76
-
77
-
78
-
### Util Targets
79
-
80
-
#### `mod`
81
-
Runs go mod [tidy](https://go.dev/ref/mod#go-mod-tidy) and [verify](https://go.dev/ref/mod#go-mod-verify).
82
-
___
83
-
84
-
#### `vendor`
85
-
Runs [go mod vendor](https://go.dev/ref/mod#go-mod-vendor) that downloads all dependencies into `./vendor` folder.
86
-
___
87
-
88
-
#### `env`
89
-
Prints information regarding the local environment. More specifically: go env, all go packages and folders, and the specified tools bin directory.
90
-
___
91
-
92
-
#### `git-reset`
93
-
Full hard reset to HEAD. Cleans up all untracked files and restore all staged and un-staged changes.
94
-
___
95
-
96
-
97
-
### Tests and Linters Targets
98
-
99
-
#### `test`
100
-
Runs go [test](https://pkg.go.dev/cmd/go/internal/test) with race conditions and prints cover report.
101
-
___
102
-
103
-
#### `tools`
104
-
Installs (if needed) all tools (goimports, staticcheck, gofumpt, etc) under `TOOLS_BIN` folder (default is `./.tools/bin`).
105
-
___
106
-
107
-
#### `checks`
108
-
Runs all default checks (`vet`, `staticcheck`, `gofumpt`, `goimports`, `golangci-lint`).
109
-
___
110
-
111
-
#### `vet`
112
-
Runs go [vet](https://pkg.go.dev/cmd/vet).
113
-
___
114
-
115
-
#### `gofumpt`
116
-
Installs (if needed) [gofumpt](https://github.com/mvdan/gofumpt) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `gofumpt` for each folder. <br>
117
-
If `gofumpt` finds files that need fix/format it displays those files as list and the target fails (_exit 1_).
118
-
___
119
-
120
-
#### `gofumpt.display`
121
-
In case of `gofumpt` fails this target can be used to display the necessary changes. It runs `gofumpt -d` to display the needed changes that can be applied with `make gofumpt.fix`.
122
-
___
123
-
124
-
#### `gofumpt.fix`
125
-
Runs `gofumpt -w` to fix/format files (that need fix).
126
-
___
127
-
128
-
#### `goimports`
129
-
Installs (if needed) [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `goimports` for each folder. <br>
130
-
If `goimports` finds files that need fix/format it displays those files as list and the target fails (_exit 1_).
131
-
___
132
-
133
-
#### `goimports.display`
134
-
In case of `goimports` fails this target can be used to display the necessary changes. It runs `goimports -d` to display the needed changes that can be applied with `make goimports.fix`.
135
-
___
136
-
137
-
#### `goimports.fix`
138
-
Runs `goimports -w` to fix files (that need fix).
139
-
___
140
-
141
-
#### `staticcheck`
142
-
Installs (if needed) [staticcheck](https://staticcheck.io/) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `staticcheck` using all [checks](https://staticcheck.io/docs/checks) excluding [ST1000](https://staticcheck.io/docs/checks/#ST1000). <br>
143
-
If issues are found the target fails (due to `staticcheck` exit status).
144
-
___
145
-
146
-
#### `golangci-lint`
147
-
Installs (if needed) [golangci-lint](https://golangci-lint.run/) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `golangci-lint`. <br>
148
-
If issues are found the target fails (due to `golangci-lint` exit status).
149
-
___
150
-
43
+
## Makefile targets
44
+
Makefile targets can be found in [docs/makefile_targets.md](docs/makefile_targets.md) file.
|`mod`| Runs go mod [tidy](https://go.dev/ref/mod#go-mod-tidy) and [verify](https://go.dev/ref/mod#go-mod-verify). |
6
+
|`vendor`| Runs [go mod vendor](https://go.dev/ref/mod#go-mod-vendor) that downloads all dependencies into `./vendor` folder. |
7
+
|`go-deps-upgrade`| Runs updates all `go.mod` dependencies. |
8
+
|`env`| Prints information regarding the local environment. More specifically: go env, all go packages and folders, and the specified tools bin directory. |
9
+
|`git-reset`| Full hard reset to HEAD. Cleans up all untracked files and restore all staged and un-staged changes. |
10
+
|`build`| Builds all binaries under `./cmd` (one for each directory) and outputs the binaries into `./output` folder using this pattern: `./cmd/<directory name> -> ./output/<directory name>`. |
11
+
| `cmd.<cmd dir name>` | Builds a specific cmd directory `<directory name>` and outputs the binary into `./output` folder using this pattern: `./cmd/<directory name> -> ./output/<directory name>`.
12
+
| `dbg.<cmd dir name>` | Builds a specific cmd directory `<directory name>` (keeping debug symbols) and outputs the binary into `./output` folder using this pattern: `./cmd/<directory name> -> ./output/<directory name>`.
13
+
| `clean` | Deletes `./output` folder.
14
+
| `compose-up` | Deploys (rebuilds and recreates) the docker compose file `deployments/compose/docker-compose.yml` in attached mode. This docker compose file is intended for local development.<br>It uses the docker file `build/docker/debug.Dockerfile` and runs `air` target (see below), including hot-reload (rebuild on changes) and debug server.
15
+
| `compose-down` | Stops (if started) the containers specified by the docker compose file `deployments/compose/docker-compose.yml` removes containers, cleans up the volumes and delete local docker images.
16
+
| `air` | Installs (if needed) [air](https://github.com/air-verse/air) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `air -c .air.toml`.<br>Air watches for code file changes and rebuilds the binary according to the configuration `.air.toml`.<br>Current air configuration executes `cmd.goboilerplate` target (on each file change) and then runs the `./build/dlv` that starts the debug server (`dlv exec`) with the produced binary.
17
+
| `image` | Builds the docker image using the docker file `./build/docker/Dockerfile`.<br>This docker file is intended to be used as a production image.<br>Image name and tag are specified by `IMAGE_NAME` and `IMAGE_TAG`. Default values can be overwritten during execution (eg `make IMAGE_NAME=myimage IMAGE_TAG=1.0.0 image`).
18
+
| `test` | Runs go [test](https://pkg.go.dev/cmd/go/internal/test) with race conditions and prints cover report.
19
+
| `tools` | Installs (if needed) all tools (goimports, staticcheck, gofumpt, etc) under `TOOLS_BIN` folder (default is `./.tools/bin`).
| `vet` | Runs go [vet](https://pkg.go.dev/cmd/vet).
22
+
| `gofumpt` | Installs (if needed) [gofumpt](https://github.com/mvdan/gofumpt) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `gofumpt` for each folder.<br>If `gofumpt` finds files that need fix/format it displays those files as list and the target fails (_exit 1_).
23
+
| `gofumpt.fix` | Runs `gofumpt -w` to fix/format files (that need fix).
24
+
| `goimports` | Installs (if needed) [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `goimports` for each folder.<br>If `goimports` finds files that need fix/format it displays those files as list and the target fails (_exit 1_).
25
+
| `goimports.fix` | Runs `goimports -w` to fix files (that need fix).
26
+
| `staticcheck` | Installs (if needed) [staticcheck](https://staticcheck.io/) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `staticcheck` using all [checks](https://staticcheck.io/docs/checks) excluding [ST1000](https://staticcheck.io/docs/checks/#ST1000).<br>If issues are found the target fails (due to `staticcheck` exit status).
27
+
| `golangci-lint` | Installs (if needed) [golangci-lint](https://golangci-lint.run/) under `TOOLS_BIN` folder (default is `./.tools/bin`) and runs `golangci-lint`. <br>If issues are found the target fails (due to `golangci-lint` exit status).
0 commit comments