Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
0bc508ed22
  1. 1
      go.mod
  2. 4
      go.sum
  3. 6
      internal/config/config.go
  4. 6
      internal/config/data/data.go
  5. 6
      internal/config/data/logger.go
  6. 2
      internal/config/data/server.go
  7. 2
      internal/config/data/storage.go
  8. 11
      internal/config/yaml/yaml.go

1
go.mod

@ -16,4 +16,5 @@ require (
forge.chapril.org/mls-361/uuid v0.0.0-20210511091055-533cd6b13c6f
github.com/julienschmidt/httprouter v1.3.0
github.com/maragudk/gomponents v0.16.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

4
go.sum

@ -32,3 +32,7 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/maragudk/gomponents v0.16.0 h1:qoFF52ePoX27b6uvLGfGNcIfN/F6NSg9YCtqoipBXuM=
github.com/maragudk/gomponents v0.16.0/go.mod h1:0OdlqOoqxcwvhBFrp8wlKHnEXhNB7IVhb8GuARmd+tI=
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.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

6
internal/config/config.go

@ -11,7 +11,7 @@ import (
"forge.chapril.org/armen/armen/internal/components"
"forge.chapril.org/armen/armen/internal/config/data"
"forge.chapril.org/armen/armen/internal/config/json"
"forge.chapril.org/armen/armen/internal/config/yaml"
)
type config struct {
@ -31,8 +31,8 @@ func Load(ccs *components.Components) (components.Config, error) {
config, ok := ccs.Application.LookupEnv("CONFIG")
if ok {
switch config {
case "json":
if err := json.LoadConfig(ccs.Application, cc.data); err != nil {
case "yaml":
if err := yaml.LoadConfig(ccs.Application, cc.data); err != nil {
return nil, err
}
default:

6
internal/config/data/data.go

@ -15,9 +15,9 @@ import (
// Data AFAIRE.
type Data struct {
Logger Logger `json:"logger"`
Server Server `json:"server"`
Storage Storage `json:"storage"`
Logger Logger
Server Server
Storage Storage
}
// Validate AFAIRE.

6
internal/config/data/logger.go

@ -13,9 +13,9 @@ const (
// Logger AFAIRE.
type Logger struct {
Level string `json:"level"`
Output string `json:"output"`
Facility string `json:"facility"`
Level string
Output string
Facility string
}
func (l *Logger) validate() error {

2
internal/config/data/server.go

@ -10,7 +10,7 @@ const _defaultServerPort = 65530
// Server AFAIRE.
type Server struct {
Port int `json:"port"`
Port int
}
func (s *Server) validate() error {

2
internal/config/data/storage.go

@ -10,7 +10,7 @@ const _defaultStorage = "memory"
// Storage AFAIRE.
type Storage struct {
Impl string `json:"impl"`
Impl string
}
func (s *Storage) validate() error {

11
internal/config/json/json.go → internal/config/yaml/yaml.go

@ -1,16 +1,17 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### json ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
####### yaml ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package json
package yaml
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"gopkg.in/yaml.v3"
"forge.chapril.org/armen/armen/internal/components"
)
@ -22,7 +23,7 @@ const (
func LoadConfig(app components.Application, destination interface{}) error {
file, ok := app.LookupEnv("CONFIG_FILE")
if !ok {
file = filepath.Join(_defaultConfigDir, app.Name(), app.Name()+".json")
file = filepath.Join(_defaultConfigDir, app.Name(), app.Name()+".yaml")
}
data, err := ioutil.ReadFile(file)
@ -30,7 +31,7 @@ func LoadConfig(app components.Application, destination interface{}) error {
return err
}
if err := json.Unmarshal(data, destination); err != nil {
if err := yaml.Unmarshal(data, destination); err != nil {
return err
}
Loading…
Cancel
Save