golang.zone

Home of golang.zone
This repository holds the files for the REST API of https://golang.zone
You need to make a config file in the config directory - below is an example of what it could look like
{
"env": "local",
"mysql": {
"host": "app_mysql",
"username": "root",
"password": "root",
"database": "database_name",
"encoding": "utf8mb4",
"port": "3306"
},
"redis": {
"host": "app_redis",
"port": 6379
},
"jwt": {
"secret": "secret",
"public_key_path": "config/api.rsa.pub",
"private_key_path": "config/api.rsa"
},
"port": 8080
}
Generate private key
- openssl genrsa -out api.rsa keysize(2048 or 4096)
Generate public key
- openssl rsa -in api.rsa -pubout > api.rsa.pub
Prerequisites
- Go 1.7+
- Mysql
- Redis (To revoke JWTs)
Endpoints
Users:
Posts:
Auth:
Misc:
Example requests
Paw
Mac users only
golang.zone.paw
Open the file with Paw then set the environment in the upper left corner
Postman
- Import the golang.zone.postman_collection.json in Postman
- Setup your environments by clicking the 🔩 icon just next to the 👁️ icon top in the top right corner
- You can also import the environments created by me,
golang.zone.Local.postman_environment.json, golang.zone.Prod.postman_environment.json
continue at step 8.
- I suggest creating 2 envs on called golang.zone Local and one called golang.zone Prod
- Create 3 keys BASE_URL, ACCESS_TOKEN and REFRESH_TOKEN
- Set the value of BASE_URL to http://localhost:8080 for the local env and https://golang.zone for the Prod env, leave the tokens value empty for now
- Click Add/Update.
- Go to the Login request and open up the Tests tab.
- Insert the code below then save and finally click send.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("ACCESS_TOKEN", jsonData.data.accessToken);
postman.setEnvironmentVariable("REFRESH_TOKEN", jsonData.data.refreshToken);
- Now when you call endpoints that require authorization it will automatically insert the token value inside the Authorization header
Docker Development
Run the following commands only before boostrapping the application.
# Migrate database
docker-compose run --rm --name app -p 8080:8080 app_api bash
# Inside the app container
# TODO: Clean up the migration
goose -dir ./db/migrations/ mysql "app:password@(app_mysql:3306)/app" up
Development - Since linking the local folder to container we can edit code and run container.
docker-compose up