feat: environment specific database handling

Changes have been made to support environment specific database file handling. By introducing a new environment variable "DB_FILE", the application's runtime now reads the database file path from the environment. In addition, subdirectories will now be automatically created if they don't exist and more detailed error messages will be printed in case of a failure. Environment variable setup and project building instructions were also updated in the README file.
This commit is contained in:
Florian Sylvain
2023-08-13 04:34:30 +02:00
parent 64ecbc6995
commit 245bf2fbf4
3 changed files with 35 additions and 10 deletions
+23 -6
View File
@@ -14,15 +14,32 @@ TODO (or is it...)
### Build and run it yourself
TODO
#### Requirements
- The project is developed with Go 1.20.5
#### Build
There are 2 scripts to build the project:
- `super_build.sh`
- `super_build.bat`
They will build the project for windows, linux and macOS. The binaries will be in the `bin` folder.
You can also really just use `go build` to build the project for your current OS.
#### Run
Once the project is built, you can simply run the binary for your OS. Setting the environment variables is
of course required, but not necessarily via the `.env` file.
### Environment variables
| Name | Type | Description | Comment |
|----------------------|--------|---------------------------------------|-----------------------------------------|
| ENVIRONMENT | string | The environment the API is running in | required, `development` or `production` |
| PORT | int | The port the API will use | required |
| CORS_ALLOWED_ORIGINS | string | The allowed origins for CORS | required, semicolon separated list |
| Name | Type | Description | Comment |
|----------------------|--------|---------------------------------------|-------------------------------------------------------------------------------------------------------|
| ENVIRONMENT | string | The environment the API is running in | required, `development` or `production` |
| PORT | int | The port the API will use | required |
| CORS_ALLOWED_ORIGINS | string | The allowed origins for CORS | required, semicolon separated list |
| DB_FILE | string | The path to the sqlite db file | required, can be at the root but name still required (e.g. `./gohcms.db`) ; have to end up with `.db` |
## API Usage