This is a skeleton HTTP API server app written in Go.
Docker : docker run -p 8080:8080 -it jecklgamis/go-webapp-example:main
Features:
- Uses gorilla mux request router
- Uses spf13/viper for config management
- Exposes Prometheus metrics endpoint and instrumented handlers
- Ubuntu-based Docker image
- Exposes /buildInfo, /probe/ready, /probe/live, /metrics handlers
- Starts HTTP/HTTPS listeners
- Uses environment specific config in YAML format
make build
This will:
- Run all tests
- Build server binary in
bin(one for the OS you're building on and one for Linux AMD64 platform to be used inside the Docker image) - Build Docker image
go-webapp-example:<current-branch>
Explore the Makefile or simply type make in the current directory for commonly used tasks.
Run the server using the native binary:
$ bin/server
Run the server using Docker:
make run
Verify the endpoints:
curl http://localhost:8080/
curl http://localhost:8080/buildInfo
curl http://localhost:8080/probe/ready
curl http://localhost:8080/probe/live
curl http://localhost:8080/api
curl http://localhost:8080/metrics
The config/config-<env>.yml contains the environment specific configuration. The config file is selected based on
the APP_ENV variable and is dev by default.
The Docker image uses Ubuntu base image. It has the following directory namespace:
/appis the base app directory/app/bincontains the server binary/app/configcontains the environment-specific config files in YAML format
The rebuilder directory contains helper scripts for automatically building the app on file changes. It depends
on fswatchfor detecting file system changes in pkg and cmd directories.
Install fswatch (Mac OS):
brew install fswatch
Run the rebuilder:
make rebuilder
make lint
This wil run golint on all the Go sources it can find.
make test
This will run all *_test.go files it can find.
`
- Program execution starts from
cmd/server/server.go, it then starts the server inpkg/server/server.go server.goloads environment-specific configuration underconfig.
- Replace all
go-webapp-examplereferences - Replace Go module import names in the Go sources
Example:
import (
"github.com/<your-user-name>/<your-app-name>/pkg/server"
)
Sure, send pull request?