init(web): add loading configuration from file

This commit is contained in:
Masahiko AMANO 2025-01-07 17:03:45 +03:00
parent b42542931a
commit 1acb32aea0
2 changed files with 34 additions and 0 deletions

24
web/conf/conf.go Normal file
View File

@ -0,0 +1,24 @@
package conf
import (
"os"
"gopkg.in/yaml.v3"
)
const CONF_FILE = "/etc/skazanull/web.conf.yml"
type Conf struct {
DBConfig string `yaml:"db_config"`
Interface string `yaml:"interface"`
EncryptionKey string `yaml:"encryption_key"`
}
func GetConf() (conf Conf, err error) {
confFile, err := os.ReadFile(CONF_FILE)
if err != nil {
return
}
err = yaml.Unmarshal(confFile, &conf)
return
}

10
web/web.conf.yml.example Normal file
View File

@ -0,0 +1,10 @@
# Database configuration string
db_config: postgres://user:password@host:port/db?application_name=SkazaNull%20Web
# The interface on which to run the webserver
interface: ":9672"
# Encryption key for sessions.
# Change it to a string of exactly 16, 32 or 64 chars
# Avoid the "#" character in your APP_KEY, it may break things.
encryption_key: some_secret_key