From 1acb32aea078515f21f948fff92895ad5351aacc Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Tue, 7 Jan 2025 17:03:45 +0300 Subject: [PATCH] init(web): add loading configuration from file --- web/conf/conf.go | 24 ++++++++++++++++++++++++ web/web.conf.yml.example | 10 ++++++++++ 2 files changed, 34 insertions(+) create mode 100644 web/conf/conf.go create mode 100644 web/web.conf.yml.example diff --git a/web/conf/conf.go b/web/conf/conf.go new file mode 100644 index 0000000..a9b489d --- /dev/null +++ b/web/conf/conf.go @@ -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 +} diff --git a/web/web.conf.yml.example b/web/web.conf.yml.example new file mode 100644 index 0000000..76cf2b7 --- /dev/null +++ b/web/web.conf.yml.example @@ -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