From 8716ac3e650075525cab7fb5caf1aa62b3efe55b Mon Sep 17 00:00:00 2001 From: NeonXP Date: Wed, 4 Jan 2023 18:44:58 +0300 Subject: rewrite --- internal/config/config.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'internal/config') diff --git a/internal/config/config.go b/internal/config/config.go index 0c48a87..9f581de 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,18 +3,20 @@ package config import ( "os" + "go.neonxp.dev/djson/internal/node" + "go.neonxp.dev/json" - "go.neonxp.dev/json/model" ) type Config struct { Listen string - DB dbConfig + Log logConfig + DB string JWT jwtConfig } -type dbConfig struct { - Path string +type logConfig struct { + Level string } type jwtConfig struct { @@ -28,23 +30,23 @@ func Parse(file string) (*Config, error) { return nil, err } - cfgNode, err := json.Unmarshal(fb) + j := json.New(node.Factory) + root, err := j.Unmarshal(string(fb)) if err != nil { return nil, err } - listen := model.MustQuery(cfgNode, []string{"listen"}).(*model.StringNode).Value - dbPath := model.MustQuery(cfgNode, []string{"db", "path"}).(*model.StringNode).Value - algorithm := model.MustQuery(cfgNode, []string{"jwt", "algorithm"}).(*model.StringNode).Value - privateKey := model.MustQuery(cfgNode, []string{"jwt", "privateKey"}).(*model.StringNode).Value cfg := &Config{ - Listen: listen, - DB: dbConfig{ - Path: dbPath, + Listen: json.MustQuery(root, []string{"listen"}).(*node.Node).GetString(), + Log: logConfig{ + Level: json.MustQuery(root, []string{"log", "level"}).(*node.Node).GetString(), }, + DB: json.MustQuery(root, []string{"db"}).(*node.Node).GetString(), JWT: jwtConfig{ - Algorithm: algorithm, - PrivateKey: []byte(privateKey), + Algorithm: json.MustQuery(root, []string{"jwt", "algorithm"}).(*node.Node).GetString(), + PrivateKey: []byte( + json.MustQuery(root, []string{"jwt", "privateKey"}).(*node.Node).GetString(), + ), }, } -- cgit v1.2.3