added docker compose

This commit is contained in:
z1glr
2025-02-04 20:57:48 +01:00
parent 3f9a190795
commit 3227073470
14 changed files with 140 additions and 48 deletions

View File

@@ -2,7 +2,9 @@ package config
import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"
"time"
@@ -51,6 +53,8 @@ func (config ConfigStruct) SignJWT(val any) (string, error) {
}
func LoadConfig() ConfigStruct {
ensureConfigExists()
Config := ConfigYaml{}
yamlFile, err := os.ReadFile(CONFIG_PATH)
@@ -90,6 +94,32 @@ func LoadConfig() ConfigStruct {
}
}
func ensureConfigExists() {
// if the config path doesn't exist, copy the example config there
if _, err := os.Stat(CONFIG_PATH); errors.Is(err, os.ErrNotExist) {
source, err := os.Open("config-default.yaml")
if err == nil {
defer source.Close()
destination, err := os.Create(CONFIG_PATH)
if err == nil {
defer destination.Close()
io.Copy(destination, source)
}
}
}
}
func init() {
// check for the config passed as an argument
if len(os.Args) == 2 {
CONFIG_PATH = os.Args[1]
} else {
CONFIG_PATH = "config.yaml"
}
Config = LoadConfig()
}

View File

@@ -9,7 +9,7 @@ import (
"gopkg.in/yaml.v3"
)
var CONFIG_PATH = "config.yaml"
var CONFIG_PATH string
type ConfigYaml struct {
LogLevel string `yaml:"log_level"`