config: переезд на YAML вместо JSON + main ветка

- config.json → config.yaml (формат YAML)
- github.com/spf13/viper не нужен — используем gopkg.in/yaml.v3
- Поддержка .yaml и .yml расширений
- Флаг -config по умолчанию смотрит config.yaml
- config.local.{yaml,yml} добавлены в .gitignore
- Ветка переименована master → main
This commit is contained in:
SashegDev
2026-06-06 22:48:27 +00:00
parent 096c4d0a2d
commit 04230fa7f0
7 changed files with 36 additions and 23 deletions
+2 -1
View File
@@ -28,4 +28,5 @@ client/.flutter-plugins-dependencies
Thumbs.db Thumbs.db
# Config # Config
server/config.local.json server/config.local.yaml
server/config.local.yml
+1 -1
View File
@@ -13,7 +13,7 @@ import (
) )
func main() { func main() {
configPath := flag.String("config", "config.json", "path to config file") configPath := flag.String("config", "config.yaml", "path to config file")
flag.Parse() flag.Parse()
cfg, err := config.Load(*configPath) cfg, err := config.Load(*configPath)
-10
View File
@@ -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"
}
+8
View File
@@ -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"
+1
View File
@@ -8,6 +8,7 @@ require (
github.com/klauspost/compress v1.17.9 github.com/klauspost/compress v1.17.9
github.com/mattn/go-sqlite3 v1.14.22 github.com/mattn/go-sqlite3 v1.14.22
golang.org/x/crypto v0.26.0 golang.org/x/crypto v0.26.0
gopkg.in/yaml.v3 v3.0.1
) )
require golang.org/x/sys v0.23.0 // indirect require golang.org/x/sys v0.23.0 // indirect
+4
View File
@@ -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/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 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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=
+20 -11
View File
@@ -1,20 +1,22 @@
package config package config
import ( import (
"encoding/json"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"gopkg.in/yaml.v3"
) )
type Config struct { type Config struct {
ServerName string `json:"server_name"` ServerName string `yaml:"server_name"`
ListenAddr string `json:"listen_addr"` ListenAddr string `yaml:"listen_addr"`
Domain string `json:"domain"` Domain string `yaml:"domain"`
DataDir string `json:"data_dir"` DataDir string `yaml:"data_dir"`
MaxFileSize int64 `json:"max_file_size"` MaxFileSize int64 `yaml:"max_file_size"`
Federation bool `json:"federation"` Federation bool `yaml:"federation"`
FederatedWith []string `json:"federated_with"` FederatedWith []string `yaml:"federated_with"`
LogLevel string `json:"log_level"` LogLevel string `yaml:"log_level"`
} }
func Default() *Config { func Default() *Config {
@@ -39,8 +41,15 @@ func Load(path string) (*Config, error) {
if err != nil { if err != nil {
return cfg, 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 return cfg, nil
} }