We want our code to be resistant to the passage of time and also to its growth. With the API already stable, the code will be read much more frequently than it is written, which is why we prefer the code to be tedious to write but easy to read.
In this context, the objective of these guidelines is to manage the complexity of our code. Below you will find a list of tools and guides to help you in that regard:
- Follow (as much as you can) the golang code review guide.
- Follow (as much as you can) the effective go guide.
- Prepare your environment to activate our hooks that validate code and tests before each commit.
- All new code must contain automated tests that validate the new rules.
The important thing is that you are aware when you make a contribution, and try to follow the same style that is already used in the code. If you have any questions, do not hesitate to ask us!
This app is written in GoLang 1.19. In order to contribute to this project, you must provide tested code to keep our coverage as high as possible.
To prepare your environment, we recommend running the command below, as it adds our pre-commit hook
to ensure some rules before pushing code. To include it you must run just once (or when the script is updated):
make hooks
To be able to run/debug this application on VSCode, here is a example of a launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/api/",
"env": {},
"envFile": [
"${workspaceFolder}/variables.env"
],
"args": []
}
]
}
Some variables are necessary to run application:
export APP_PATH="/Users/username/go/src/github.com/<new-project-name>"
export SCOPE="local"
export checksumEnabled="false"
This app manages its dependencies using go mod
, in this topic there are some instructions on how to prepare your
environment to have it working.
When developing using Go modules, it is imperative that you add the following env var
to your local environment
(usually in your ~/.profile
or equivalent):
export GOPRIVATE="github.com/<new-project-name>"
If using Go 1.13+ you can run once:
go env -w GOPRIVATE="github.com/<new-project-name>"
Once you've set GOPRIVATE
, Go modules resolver will use git to clone repositories that match with the value in the env
variable. Go modules clones using https by default, in order to authenticate with Github and be able to clone private
repositories you usually need to use ssh. In order to force git to use ssh
on Github, you need to set the following
lines in your ~/.gitconfig
:
[url "ssh://[email protected]/"]
insteadOf = https://github.com/
This repository has some make commands that helps developers to get started to it. To used you MUST have docker
and
docker-compose
installed locally.
To get all support services running, just run make dev
and it will run all support service containers.
To run the tests, you just need to run make test
.
To execute the app locally in docker, the command is make run
When executing inside a container, the application is configured to perform the migrations in
/migrations/mysql/testlocal
automatically at startup.
To execute the process outside the application container, it is necessary that the environment variables are properly
configured. cmd/migration/main.go
is a file that performs the migration process, and can be called with the
UP | DOWN
parameters.
It can be executed directly using golang: Eg:
go run cmd/migration/main.go UP
To populate local database with valid data for testing purposes, you can run make fixtures
. make fixtures
will load
the fixtures and generate test data for flight, forecasts and recommendations for next week.
The fixture files are located in /resources/fixtures
folder. The cmd/fixtures/app
is responsible for starting the
application modules invoking the data generation methods in order.
To run the application locally with debugging capabilities, follow these steps:
- Go to
Run > Edit Configurations...
and select+
to add a new configuration. - Select
Go Build
and name itBuild Name of the APP
. - In
Environment
variables, add the following:APP_PATH=$PWD;configFileName=configFileName=resources/config/local.properties
- Click on
EnvFile
tab and add select+
to add new envfile - Choose
variables.env
on project root folder - Click on
Apply
andOK
. - Run the APP by clicking the green play button in the top right corner.
- You should now be able to access the APP at
http://localhost:8080
.
For more detailed instructions and additional configurations, refer to the Goland guide.
run
make lint
to execute linter locally