summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2023-01-04 18:44:58 +0300
committerNeonXP <i@neonxp.dev>2023-01-04 18:44:58 +0300
commit8716ac3e650075525cab7fb5caf1aa62b3efe55b (patch)
treef34dcb33400ef6bfd7f01b55a04f59784505c506 /internal/config/config.go
parente91712e388c530dd5bdfb46f028157a62a60b1e3 (diff)
rewriteHEADmaster
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go30
1 files changed, 16 insertions, 14 deletions
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(),
+ ),
},
}