🔧 Create a configuration file interface

This commit adds the ability to provide a config file in different ways:

The following options are given in the order in which they are checked:
1. A config file path passed by the -c parameter on the command line
2. A config file path passed by the HS_CONFIGFILE environment variable
3. A config.json file in the application root

Should these fail we try to get the parameters for the config struct
directly from environment variables or secret files as used in a
container environment. As example the JwtKey can be supplied by either
passing the value through:

* An environment variable HS_CONFIG_JWTKEY which contains the value directly
* An environment variable HS_CONFIG_JWTKEY_FILE which contains a path
  pointing to the Secret File
This commit is contained in:
2024-01-18 01:04:43 +01:00
parent c08de78984
commit 83753c3ee1
6 changed files with 107 additions and 5 deletions

11
main.go
View File

@ -1,8 +1,11 @@
package main
import (
"log"
"git.beisel.it/florian/hostname-service/api"
"git.beisel.it/florian/hostname-service/auth"
"git.beisel.it/florian/hostname-service/config"
"git.beisel.it/florian/hostname-service/db"
"git.beisel.it/florian/hostname-service/docs"
"git.beisel.it/florian/hostname-service/middleware"
@ -29,9 +32,15 @@ import (
// @description Type "Bearer" followed by a space and JWT token.
func main() {
err := config.LoadConfig()
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
gin.SetMode(gin.DebugMode)
db.Init("hostname-service.db")
db.Init(config.GlobalConfig.DatabaseFile)
router := gin.Default()