fix: mount config directory instead of file for Docker Compose
Build and Push to GHCR / build-and-push (push) Has been cancelled
Build and Push to GHCR / build-and-push (push) Has been cancelled
- Add CONFIG_PATH env support to avoid Docker creating config.json as a directory - Config Save() now auto-creates parent directories - Update docker-compose.yml to mount ./config:/app/config - Update README deployment docs accordingly
This commit is contained in:
@@ -3,9 +3,20 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var configFilePath string = "config.json"
|
||||
|
||||
func SetConfigFilePath(path string) {
|
||||
configFilePath = path
|
||||
}
|
||||
|
||||
func GetConfigFilePath() string {
|
||||
return configFilePath
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ListenAddr string `json:"listen_addr"`
|
||||
AdminPath string `json:"admin_path"`
|
||||
@@ -38,6 +49,7 @@ var (
|
||||
)
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
configFilePath = path
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -73,6 +85,14 @@ func defaultConfig() *Config {
|
||||
func (c *Config) Save(path string) error {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
dir := filepath.Dir(path)
|
||||
if dir != "" && dir != "." {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(c, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user