add config change in cli

This commit is contained in:
2026-02-10 15:45:03 +01:00
parent 60c610de42
commit c948090961
3 changed files with 28 additions and 12 deletions

View File

@@ -5,17 +5,19 @@ import (
"log"
"os"
"github.com/alecthomas/kong"
kongtoml "github.com/alecthomas/kong-toml"
"github.com/pelletier/go-toml"
)
type Config struct {
Port string `toml:"port" default:"8080" comment:"The port to listen on for the server."`
DatabaseFilePath string `toml:"database_file_path" default:"plm.db" comment:"Path to sqlite database file."`
DemoDataPath string `toml:"demo_data_path" comment:"The path to the sql file to load for demo data."`
JWTKey string `toml:"jwt_key" comment:"The key used to encrypt the generated JWT. Encoded in base64. If empty a random one will be generated on every restart."`
ImageFolderPath string `toml:"image_folder_path" default:"img" comment:"Folder where uploaded files will be stored."`
DatabaseFilePath string `toml:"database-file-path" default:"plm.db" comment:"Path to sqlite database file."`
DemoDataPath string `toml:"demo-data-path" comment:"The path to the sql file to load for demo data."`
JWTKey string `toml:"jwt-key" comment:"The key used to encrypt the generated JWT. Encoded in base64. If empty a random one will be generated on every restart."`
ImageFolderPath string `toml:"image-folder-path" default:"img" comment:"Folder where uploaded files will be stored."`
Limit int `toml:"limit" default:"100" comment:"A single API call will return at most this number of records."`
InventaireUrl string `toml:"inventaire_url" default:"https://inventaire.io" comment:"An inventaire.io instance URL."`
InventaireUrl string `toml:"inventaire-url" default:"https://inventaire.io" comment:"An inventaire.io instance URL."`
}
func defaultConfig() Config {
@@ -43,6 +45,8 @@ func LoadConfig(configPath string) Config {
if err != nil {
panic(err)
}
kong.Parse(&cfg, kong.Configuration(kongtoml.Loader, configPath))
return cfg
}