This Repository is a base Golang HTTP(s) Server with a bunch of default boilerplate (Fx, PostgreSQL, Mocks, MakeFile, etc).
This can be used as a scaffold for future HTTP(s) Golang Servers.
You can read a more detailed explanation of this Scaffold on Medium, including a step by step instruction set.
This server is built on the Uber-Go Fx Dependency Management system.
This server is setup similar to how internal Uber services are setup, as well as a few minor changes.
| Directory | Usage |
|---|---|
| .gen | This Directory is used to contain any generated code (ie. Mocks). |
| app | This Directory is used to define any Fx Options. |
| canned-requests | This directory contains a simple python script ( 'request.py' ) that can be modified slightly to hit HTTP endpoints during testing. The corrolary of this for YARPC services is Yabs. |
| config | This Directory is used to define static YAML configurations. |
| constants | This Directory is used to define any constants (metric fields, error messages, etc). |
| controller | This Directory is used to build actual code logic. Try to break your logic flows into controllers that you can call from the handler(s). |
| db | This Directory is used to for any logic related to your database. Initially provided is a PostgreSQL DB setup. |
| entity | This Directory is used to any structures used in your service. |
| gateway | This Directory is used to define any functions to interact with external services, applications, etc. |
| handler | This Directory is used to define endpoint handlers (ie. Request comes in one type, and needs to leave the same type). |
| observability | This Directory is used to define any Observability Options/Setup. This would be things like Loggers, M3 Metric Scopes, etc |
| scaffold | This Directory contains the script to convert this go.base to your actual application. This directory will be deleted after you convert the go.base application to your own. |
| secrets | This Directory is used to store your application secrets. The secrets.go file is looking for a YAML file called 'secrets.yaml' in this directory. |
| server | This Directory is used to setup your HTTP server. |
| utils | This Directory is used to define any Utilities. |
cd $GOPATH/src/github.com/- Create a directory with your GitHub name if it doesn't exist (
mkdir Javin-Ambridge) - Navigate into your GitHub directory (
cd $GOPATH/src/github.com/GITHUB_NAME/) - Clone this repository (
git clone https://github.com/Javin-Ambridge/go.base.git) - Go into this new repository (
cd go.base) - Run the scaffold script (
go run scaffold/main.go) - Fill in the input
- Push to your new repository.
Usually it's best to install the Golang Dependencies first:
make install-golang
After that, just use the built in util:
make run
Feel free to put issues if you would like any more boilerplate added (or add a PR), can easily be achievable.