A minimal, opinionated scaffold for Go microservices and web apps. Use this as a starting point for new projects. It provides a clean directory layout, placeholders for common layers, and folders for configs, templates, static files, and logs.
Module name (from
go.mod):github.com/dariubs/micro— update this to your own module path when you start a new project.
micro/
├─ app/
│ ├─ exe/ # Executables (entrypoints). Put your `package main` here.
│ ├─ handler/ # Transport layer (HTTP/RPC) handlers/controllers.
│ ├─ model/ # Domain and data access models.
│ ├─ types/ # Shared types, DTOs, response/request structs.
│ └─ util/ # Utilities and helpers (logging, errors, etc.).
├─ config/ # Configuration files (YAML/JSON/TOML) and env examples.
├─ static/ # Public/static assets (css, js, images, fonts).
├─ view/ # Server-side templates if using HTML rendering.
├─ log/ # Log output directory (git-ignored in real projects).
├─ build/ # Optional build artifacts/out directory.
└─ go.mod # Go module definition (currently set to Go 1.15).
Each empty folder includes a .keep file so the directory structure is tracked in version control.
- Create a new project from this template (copy or fork), then update the module path:
# In the project root
$Env:GO111MODULE = "on"
go mod edit -module github.com/youruser/yourproject
# Optionally update the Go version in go.mod
# Example: set to 1.22 (recommended)
go mod edit -go=1.22
go mod tidy- Add an entrypoint in
app/exe/main.go:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "ok")
})
fmt.Println("listening on :8080")
_ = http.ListenAndServe(":8080", nil)
}- Run it:
go run ./app/exe- Build it:
go build -o build/app.exe ./app/exe- Packages: Keep
package mainonly inapp/exe. All other code should be library packages. - Handlers in
app/handlershould be thin; push business logic intoapp/modelor dedicated services. - Types in
app/typesare shared DTOs; avoid circular dependencies withmodelandhandler. - Utilities in
app/utilshould be generic and reusable. - Configuration: Load from
config/and/or environment variables. Consider providing aconfig.example.yaml. - Logging: Write to stdout in development; optional file sink to
log/in production (rotate logs externally).
The template uses go 1.15 in go.mod. Update to a modern version for new projects:
go mod edit -go=1.22Ensure your local toolchain matches:
go version- Choose an HTTP router/framework (e.g., standard library, Gin, Echo, Fiber) and add it under
app/handler. - Add configuration loading (Viper or env parsing) and define config structs.
- Implement application logging (zap, zerolog, slog) in
app/util. - Add CI, tests, and a release workflow.
Add your preferred license (MIT, Apache-2.0, etc.) to LICENSE.