sniplate is for building secure, scalable, HTTP services with Go. This
template uses text snippets (snips) as the initial API model to get started,
hence the name sniplate. There will also be a user model, you can de-couple
these and build out micro services as well, but I feel this is a good starting
point as a modular monolith.
The initial project set up has been completed, and includes the following features so far.
- 100% Go standard library
- CLI flags for custom server config
- Structured logging
- Centralized error handling
- Middleware
- Security enhancements
- Docker infrastructure
| Method | URL Pattern | Handler | Action |
|---|---|---|---|
| GET | /v1/healthcheck | healthcheckHandler | Show application information |
| POST | /v1/snips | createSnipHandler | Add snip |
| GET | /v1/snips/{id} | showSnipHandler | Show specific snip |
To get started locally, make sure you have Git and Go installed, then pull the repository.
Pull repository with Git.
git pull https://github.com/pwilliams-ck/sniplateYou can use make to build and run the docker environment, the migrating part
is a work in progress. You should be able to run make migrate to migrate up,
stick with the CLI for migrating down. You can check out the infra/ folder for
more info.
cd into the project root directory and execute the following to compile and
run with a single command. Further down there is a
Build for Remote Server section as well. The database setup is
a work in progress, and will use Make as well.
go run ./cmd/api -env=local-buildYou should now be able to run curl commands against localhost:4200.
curl -i localhost:4200/v1/healthcheckFor server configuration info, try running go run ./cmd/api -help.
There is an option to run the server with TLS enabled. If you want to create a
development TLS certificate and key, and have Go installed, they include a handy
tool to create self-signed certificates with the crypto/tls package. cd into
the project root, mkdir tls, and cd again.
cd sniplate
mkdir tls
cd tlsNext, find the generate_cert.go tool's path on your local machine, and run it
from the tls directory. Here is the path for MacOS, and probably Linux. The
CLI flags are there for convenience, copy/pasta away.
go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhostThen cd back into the root directory, build, and run the application.
cd ..
go run ./cmd/api -tls=trueIf you are using a reverse proxy like nginx or HAProxy then this will encrypt the traffic. between the proxy and the Sniplate app.
First, make code changes.
Then run the following, where ./test-api is the name of the executable you are
building.
GOOS=linux GOARCH=amd64 go build -o ./test-api ./cmd/apiThis is a work in progress and will be updated when I have free time.