diff --git a/.gitignore b/.gitignore index 8613c48..580b7d2 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ client/.flutter-plugins-dependencies Thumbs.db # Config -server/config.local.json +server/config.local.yaml +server/config.local.yml diff --git a/server/cmd/jam-server/main.go b/server/cmd/jam-server/main.go index 50a883b..ca68597 100644 --- a/server/cmd/jam-server/main.go +++ b/server/cmd/jam-server/main.go @@ -13,7 +13,7 @@ import ( ) func main() { - configPath := flag.String("config", "config.json", "path to config file") + configPath := flag.String("config", "config.yaml", "path to config file") flag.Parse() cfg, err := config.Load(*configPath) diff --git a/server/config.json b/server/config.json deleted file mode 100644 index a928dcd..0000000 --- a/server/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "server_name": "JustAMessenger", - "listen_addr": ":8443", - "domain": "localhost", - "data_dir": "./data", - "max_file_size": 2147483648, - "federation": false, - "federated_with": [], - "log_level": "info" -} diff --git a/server/config.yaml b/server/config.yaml new file mode 100644 index 0000000..a7a86b5 --- /dev/null +++ b/server/config.yaml @@ -0,0 +1,8 @@ +server_name: "JustAMessenger" +listen_addr: ":8443" +domain: "localhost" +data_dir: "./data" +max_file_size: 2147483648 +federation: false +federated_with: [] +log_level: "info" diff --git a/server/go.mod b/server/go.mod index 243b7b9..8512621 100644 --- a/server/go.mod +++ b/server/go.mod @@ -8,6 +8,7 @@ require ( github.com/klauspost/compress v1.17.9 github.com/mattn/go-sqlite3 v1.14.22 golang.org/x/crypto v0.26.0 + gopkg.in/yaml.v3 v3.0.1 ) require golang.org/x/sys v0.23.0 // indirect diff --git a/server/go.sum b/server/go.sum index 8cb1e25..de156ee 100644 --- a/server/go.sum +++ b/server/go.sum @@ -10,3 +10,7 @@ golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/server/internal/config/config.go b/server/internal/config/config.go index ef1d6a5..7d4520b 100644 --- a/server/internal/config/config.go +++ b/server/internal/config/config.go @@ -1,20 +1,22 @@ package config import ( - "encoding/json" "os" "path/filepath" + "strings" + + "gopkg.in/yaml.v3" ) type Config struct { - ServerName string `json:"server_name"` - ListenAddr string `json:"listen_addr"` - Domain string `json:"domain"` - DataDir string `json:"data_dir"` - MaxFileSize int64 `json:"max_file_size"` - Federation bool `json:"federation"` - FederatedWith []string `json:"federated_with"` - LogLevel string `json:"log_level"` + ServerName string `yaml:"server_name"` + ListenAddr string `yaml:"listen_addr"` + Domain string `yaml:"domain"` + DataDir string `yaml:"data_dir"` + MaxFileSize int64 `yaml:"max_file_size"` + Federation bool `yaml:"federation"` + FederatedWith []string `yaml:"federated_with"` + LogLevel string `yaml:"log_level"` } func Default() *Config { @@ -39,8 +41,15 @@ func Load(path string) (*Config, error) { if err != nil { return cfg, nil } - if err := json.Unmarshal(data, cfg); err != nil { - return nil, err + + ext := strings.ToLower(filepath.Ext(path)) + switch ext { + case ".yaml", ".yml": + if err := yaml.Unmarshal(data, cfg); err != nil { + return nil, err + } + default: + return cfg, nil } return cfg, nil }