Browse Source

En cours de développement

master
mls-361 5 months ago
parent
commit
345300f4ca
  1. 2
      cmd/main.go
  2. 2
      internal/components/components.go
  3. 21
      internal/config/config.go
  4. 29
      internal/config/data/data.go
  5. 13
      internal/config/data/logger.go
  6. 8
      internal/config/data/server.go
  7. 12
      internal/config/data/storage.go
  8. 10
      internal/logger/logger.go

2
cmd/main.go

@ -142,6 +142,8 @@ func run() error {
"pid", os.Getpid(),
)
ccs.Logger.Debug("Config", "data", ccs.Config.Data()) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
group, endCh := waitEnd(ccs.Server)
demo.Start()

2
internal/components/components.go

@ -21,12 +21,14 @@ import (
type Application interface {
ID() uuid.UUID
Name() string
Debug() int
LookupEnv(suffix string) (string, bool)
Host() string
}
// Config AFAIRE.
type Config interface {
Data() *data.Data
Logger() *data.Logger
Server() *data.Server
Storage() *data.Storage

21
internal/config/config.go

@ -29,9 +29,7 @@ func Load(ccs *components.Components) (components.Config, error) {
cc := newConfig()
config, ok := ccs.Application.LookupEnv("CONFIG")
if !ok {
cc.data.Default()
} else {
if ok {
switch config {
case "json":
if err := json.LoadConfig(ccs.Application, cc.data); err != nil {
@ -43,28 +41,33 @@ func Load(ccs *components.Components) (components.Config, error) {
"mode", config,
)
}
}
if err := cc.data.Validate(); err != nil {
return nil, err
}
if err := cc.data.Validate(); err != nil {
return nil, err
}
return cc, nil
}
// Data AFAIRE.
func (cc *config) Data() *data.Data {
return cc.data
}
// Logger AFAIRE.
func (cc *config) Logger() *data.Logger {
return cc.data.Logger
return &cc.data.Logger
}
// Server AFAIRE.
func (cc *config) Server() *data.Server {
return cc.data.Server
return &cc.data.Server
}
// Storage AFAIRE.
func (cc *config) Storage() *data.Storage {
return cc.data.Storage
return &cc.data.Storage
}
/*

29
internal/config/data/data.go

@ -8,39 +8,22 @@ package data
// Data AFAIRE.
type Data struct {
Logger *Logger `json:"logger"`
Server *Server `json:"server"`
Storage *Storage `json:"storage"`
}
// Default AFAIRE.
func (d *Data) Default() {
d.Logger = defaultLogger()
d.Server = defaultServer()
d.Storage = defaultStorage()
Logger Logger
Server Server
Storage Storage
}
// Validate AFAIRE.
func (d *Data) Validate() error {
if d.Logger == nil {
d.Logger = defaultLogger()
} else if err := d.Logger.validate(); err != nil {
return err
}
if d.Server == nil {
d.Server = defaultServer()
} else if err := d.Server.validate(); err != nil {
if err := d.Logger.validate(); err != nil {
return err
}
if d.Storage == nil {
d.Storage = defaultStorage()
} else if err := d.Storage.validate(); err != nil {
if err := d.Server.validate(); err != nil {
return err
}
return nil
return d.Storage.validate()
}
/*

13
internal/config/data/logger.go

@ -13,15 +13,8 @@ const (
// Logger AFAIRE.
type Logger struct {
Level string `json:"level"`
Output string `json:"output"`
}
func defaultLogger() *Logger {
return &Logger{
Level: _defaultLoggerLevel,
Output: _defaultLoggerOutput,
}
Level string
Output string
}
func (l *Logger) validate() error {
@ -33,6 +26,8 @@ func (l *Logger) validate() error {
l.Output = _defaultLoggerOutput
}
//AFINIR
return nil
}

8
internal/config/data/server.go

@ -15,13 +15,11 @@ type Server struct {
Port int `json:"port"`
}
func defaultServer() *Server {
return &Server{
Port: _defaultServerPort,
func (s *Server) validate() error {
if s.Port == 0 {
s.Port = _defaultServerPort
}
}
func (s *Server) validate() error {
return nil
}

12
internal/config/data/storage.go

@ -6,22 +6,18 @@
package data
const (
_defaultStorage = "memory"
)
const _defaultStorage = "memory"
// Storage AFAIRE.
type Storage struct {
Type string
}
func defaultStorage() *Storage {
return &Storage{
Type: _defaultStorage,
func (s *Storage) validate() error {
if s.Type == "" {
s.Type = _defaultStorage
}
}
func (s *Storage) validate() error {
return nil
}

10
internal/logger/logger.go

@ -15,9 +15,15 @@ import (
// AFAIRE.
func Build(ccs *components.Components) (components.Logger, error) {
app := ccs.Application
cfg := ccs.Config
cfg := ccs.Config.Logger()
return logger.New(app.ID(), app.Name(), cfg.Logger().Level, logger.NewStderrOutput())
level := cfg.Level
if app.Debug() > 0 {
level = "trace"
}
return logger.New(app.ID(), app.Name(), level, logger.NewStderrOutput())
}
/*

Loading…
Cancel
Save