This project provides a best practice way to build application using Go.
Note: After installing the application, you need to download all necessary dependency which application requires:
go mod download or go mod tidy
After successfully installed migration, let's create migration using command: migrate create -seq -ext .sql -dir internal/migrations create_example_table
If there were no errors, we should have two files available under internal/migrations folder:
To run migration, let's use command: migrate -database ${POSTGRESQL_URL} -path db/migrations up
When using Migrate CLI we need to pass to database URL. Let's export it to a variable for convenience: export POSTGRESQL_URL='postgres://username:password@localhost:5432/database_name?sslmode=disable'
During migration running if error occurred which tells, Dirty database version <version>. Fix and force version
. In that case, run command: migrate -path migrations/ -database postgres://test:test@localhost/dummy?sslmode=disable force <version>
Note: Please note that before drop migration you need to export convenience variable.
migrate -database ${POSTGRESQL_URL} -path db/migrations down
The following environment variables are required to run the application:
Variable | Description | Default Value |
---|---|---|
DB_PORT |
Port of the database server | (Set as an environment variable) |
DB_HOST |
Hostname or IP address of the database server | (Set as an environment variable) |
DB_USER |
Username for the database user | (Set as an environment variable) |
DB_PASSWORD |
Password for the database user | (Set as an environment variable) |
DB_NAME |
Name of the database | (Set as an environment variable) |
Note: Do not store the actual password in this file. Instead, set the password as an environment variable before running the container using methods specific to your operating system. For example, on Linux or macOS, you can use the export
command:
Note: If you're making changes to the code that affect the Swagger documentation, you can regenerate it using the following command.
swag init --parseDependency --parseInternal -g main.go