A template to quickly start a new API with Go and the Echo framework, featuring:
- Sentry Integration
- AWS Integration (or can be CloudFlare R2)
- MySQL/MariaDB Integration
- JWT Authentication, using cookies for authentication and authorization
- A Bruno collection for API documentation
- Copy
.env.example
to.env
and fill in the details.- Note: Currently there is a dependency even on dev to use CloudFlare R2. I may change this to allow minIO, but R2 has a good free tier so will leave it for now.
- For the JWT Key:
- Generate a rsa public/private key pair with:
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout > public-key.pem
- Copy the contents of the private.pem into your
.env
file under theRSA_PRIVATE_KEY
key, with the following changes:- REMOVE THE TOP AND BOTTOM LINES (ie.
-----BEGIN RSA PRIVATE KEY-----
and-----END RSA PRIVATE KEY-----
) - Remove the newline characters so all is on a single line
- Wrap in double quotes for safety
- REMOVE THE TOP AND BOTTOM LINES (ie.
- Copy the
public-key.pem
into thecmd/api/internal/jwtHelper
directory. - Delete the original files if you ran the above steps inside your project directory.
- Generate a rsa public/private key pair with:
- Ensure MySQL/MariaDB database is setup with credentials matching those of the
.env
- To Run;
- If using
air
, can runair ./cmd/api
for hot reloading - Else can use
go run ./cmd/api
and then rerun every time a change occurs
- If using
- The API collection is saved in this repo as a Bruno collection. Download Bruno and import the collection.
- Visit
http://localhost:3001
to test that it is working!
Note: This is a WIP and so is likely to change and may have some issues. If you encounter any issues, please raise an issue report on GitHub.