Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
e7585fd564
  1. 56
      cmd/main.go
  2. 18
      internal/components/components.go
  3. 33
      internal/config/data/data.go
  4. 8
      internal/config/data/logger.go
  5. 4
      internal/config/data/server.go
  6. 6
      internal/config/data/storage.go
  7. 20
      internal/logger/logger.go
  8. 6
      internal/storage/storage.go

56
cmd/main.go

@ -41,51 +41,41 @@ func init() {
}
func buildComponents(ccs *components.Components) error {
config, err := config.Load(ccs)
var err error
ccs.Config, err = config.Load(ccs)
if err != nil {
return errors.WithMessage(err, "config") ///////////////////////////////////////////////////////////////////////
}
ccs.Config = config
logger, err := logger.Build(ccs)
ccs.Logger, err = logger.Build(ccs)
if err != nil {
return errors.WithMessage(err, "logger") ///////////////////////////////////////////////////////////////////////
}
ccs.Logger = logger
crypto, err := crypto.Build(ccs)
ccs.Crypto, err = crypto.Build(ccs)
if err != nil {
return errors.WithMessage(err, "crypto") ///////////////////////////////////////////////////////////////////////
}
ccs.Crypto = crypto
storage, err := storage.Build(ccs)
ccs.Storage, err = storage.Build(ccs)
if err != nil {
return errors.WithMessage(err, "storage") //////////////////////////////////////////////////////////////////////
}
ccs.Storage = storage
model, err := model.Build(ccs)
ccs.Model, err = model.Build(ccs)
if err != nil {
return errors.WithMessage(err, "model") ////////////////////////////////////////////////////////////////////////
}
ccs.Model = model
ccs.Router = router.Build(ccs)
server, err := server.Build(ccs)
ccs.Server, err = server.Build(ccs)
if err != nil {
return errors.WithMessage(err, "server") ///////////////////////////////////////////////////////////////////////
}
ccs.Server = server
if err := demo.Build(ccs); err != nil {
if err = demo.Build(ccs); err != nil {
return errors.WithMessage(err, "demo") /////////////////////////////////////////////////////////////////////////
}
@ -131,23 +121,22 @@ func run() error {
ccs := components.New(app)
defer ccs.Shutdown()
if err := buildComponents(ccs); err != nil {
if ccs.Logger != nil {
ccs.Logger.Fatal( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Components build error",
"reason", err,
)
}
return app.OnError(err)
}
ccs.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"APP",
"id", app.ID(),
"name", app.Name(),
"version", app.Version(),
"builtAt", app.BuiltAt().Format("2006-01-02 15:04:05"),
"pid", os.Getpid(),
)
ccs.Logger.Debug("Config", "data", ccs.Config.Data()) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
group, endCh := waitEnd(ccs.Server)
ccs.Startup()
demo.Start()
err := ccs.Server.Start()
@ -158,13 +147,6 @@ func run() error {
group.Wait()
ccs.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"END",
"uptime", time.Since(app.StartedAt()).Round(time.Second).String(),
)
_ = ccs.Logger.Close()
return app.OnError(err)
}

18
internal/components/components.go

@ -8,6 +8,7 @@ package components
import (
"net/http"
"time"
"forge.chapril.org/armen/jw"
"forge.chapril.org/mls-361/jsonapi"
@ -21,6 +22,8 @@ type Application interface {
ID() string
Name() string
Version() string
BuiltAt() time.Time
StartedAt() time.Time
Debug() int
LookupEnv(suffix string) (string, bool)
Host() string
@ -88,6 +91,21 @@ func New(app Application) *Components {
}
}
// Startup AFAIRE.
func (ccs *Components) Startup() {}
// Shutdown AFAIRE.
func (ccs *Components) Shutdown() {
if ccs.Logger != nil {
ccs.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"END",
"uptime", time.Since(ccs.Application.StartedAt()).Round(time.Second).String(),
)
_ = ccs.Logger.Close()
}
}
/*
######################################################################################################## @(°_°)@ #######
*/

33
internal/config/data/data.go

@ -6,24 +6,45 @@
package data
import (
"encoding/json"
"fmt"
"forge.chapril.org/mls-361/errors"
)
// Data AFAIRE.
type Data struct {
Logger Logger
Server Server
Storage Storage
Logger Logger `json:"logger"`
Server Server `json:"server"`
Storage Storage `json:"storage"`
}
// Validate AFAIRE.
func (d *Data) Validate() error {
if err := d.Logger.validate(); err != nil {
return err
return errors.WithMessage(err, "logger") ///////////////////////////////////////////////////////////////////////
}
if err := d.Server.validate(); err != nil {
return err
return errors.WithMessage(err, "server") ///////////////////////////////////////////////////////////////////////
}
if err := d.Storage.validate(); err != nil {
return errors.WithMessage(err, "storage") //////////////////////////////////////////////////////////////////////
}
return nil
}
// String AFAIRE.
func (d *Data) String() string {
data, err := json.Marshal(d)
if err != nil {
return fmt.Sprintf(`{"ERROR":"%s"}`, err)
}
return d.Storage.validate()
return string(data)
}
/*

8
internal/config/data/logger.go

@ -7,15 +7,15 @@
package data
const (
_defaultLoggerLevel = "debug"
_defaultLoggerLevel = "trace"
_defaultLoggerOutput = "stderr"
)
// Logger AFAIRE.
type Logger struct {
Level string
Output string
Facility string
Level string `json:"level"`
Output string `json:"output"`
Facility string `json:"facility"`
}
func (l *Logger) validate() error {

4
internal/config/data/server.go

@ -6,9 +6,7 @@
package data
const (
_defaultServerPort = 65530
)
const _defaultServerPort = 65530
// Server AFAIRE.
type Server struct {

6
internal/config/data/storage.go

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

20
internal/logger/logger.go

@ -7,6 +7,8 @@
package logger
import (
"os"
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/armen/armen/internal/components"
@ -39,7 +41,23 @@ func Build(ccs *components.Components) (components.Logger, error) {
return nil, err
}
return logger.New(app.ID(), app.Name(), level, output)
logger, err := logger.New(app.ID(), app.Name(), level, output)
if err != nil {
return nil, err
}
logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"APP",
"id", app.ID(),
"name", app.Name(),
"version", app.Version(),
"builtAt", app.BuiltAt().Format("2006-01-02 15:04:05"),
"pid", os.Getpid(),
)
logger.Debug("Config", "data", ccs.Config.Data().String()) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::
return logger, nil
}
/*

6
internal/storage/storage.go

@ -17,13 +17,13 @@ import (
func Build(ccs *components.Components) (components.Storage, error) {
cfg := ccs.Config.Storage()
switch cfg.Type {
switch cfg.Impl {
case "memory":
return memory.New(), nil
default:
return nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////////
"this storage type is unknown",
"type", cfg.Type,
"this implementation does not exist",
"impl", cfg.Impl,
)
}
}

Loading…
Cancel
Save