Browse Source

En cours de développement

master
mls-361 3 months ago
parent
commit
e9240bbf0d
  1. 16
      cmd/main.go
  2. 3
      go.mod
  3. 4
      go.sum
  4. 11
      internal/api/api.go
  5. 6
      internal/components/components.go
  6. 5
      internal/config/config.go
  7. 12
      internal/config/data/data.go
  8. 30
      internal/config/data/storage.go
  9. 27
      internal/model/model.go
  10. 34
      internal/storage/storage.go

16
cmd/main.go

@ -22,8 +22,10 @@ import (
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/crypto"
"forge.chapril.org/armen/armen/internal/logger"
"forge.chapril.org/armen/armen/internal/model"
"forge.chapril.org/armen/armen/internal/router"
"forge.chapril.org/armen/armen/internal/server"
"forge.chapril.org/armen/armen/internal/storage"
)
var (
@ -42,11 +44,21 @@ func createComponents(app components.Application) (components.Logger, components
return nil, nil, failure.Wrap(err, "logger") ///////////////////////////////////////////////////////////////////
}
_, err = crypto.Build(app)
crypto, err := crypto.Build(app)
if err != nil {
return nil, nil, failure.Wrap(err, "crypto") ///////////////////////////////////////////////////////////////////
}
storage, err := storage.Build(app, config, logger, crypto)
if err != nil {
return nil, nil, failure.Wrap(err, "storage") //////////////////////////////////////////////////////////////////
}
model, err := model.Build(logger, storage)
if err != nil {
return nil, nil, failure.Wrap(err, "model") ////////////////////////////////////////////////////////////////////
}
router := router.Build(logger)
server, err := server.Build(config, logger, router)
@ -54,7 +66,7 @@ func createComponents(app components.Application) (components.Logger, components
return nil, nil, failure.Wrap(err, "server") ///////////////////////////////////////////////////////////////////
}
api.Build(router)
api.Build(router, model)
return logger, server, nil
}

3
go.mod

@ -4,12 +4,13 @@ go 1.15
require (
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d
forge.chapril.org/mls-361/jsonapi v0.0.0-20210416210938-8892d7c86b70
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
github.com/jinzhu/copier v0.2.9 // indirect
github.com/julienschmidt/httprouter v1.3.0
)

4
go.sum

@ -1,6 +1,10 @@
cloud.google.com/go v0.16.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4 h1:4QpXO+P7ZEekXR92qc31Wg42MC2QYdwWr0tSHytFe2A=
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4/go.mod h1:Yucy16A+11RDmTxRNi29F4eWGUjJwQ+tP8WxbP1xIMU=
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c h1:djOYl2gDX9QIK1PijTPRXZDQA3SXfkS7vsSr/C0lWCM=
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c/go.mod h1:/vKiV89+6GypVQ5HtbEzqEFhSpkWSIy8Y4QjM+UE3dY=
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4 h1:UOB4NWNgzcTZHzuou51hUvebv0nvdz7zHJ+EBpJERFo=
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4/go.mod h1:OxL3gFumOmVM1WmO38C6P7cfxCRHRsj0G9RdAQseQcE=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10 h1:vUnf1qBtd1/aJY0Sod5pdtVD4rAlYqWdS6E9QfhaZIM=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10/go.mod h1:POwqatcN6c54BNVrOlsJDSpRuSwoub8iRIruASBI0jM=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79 h1:Lh+y98uVFC7btl5FdxKNtokzHD2j14R4ZIgJECao6r4=

11
internal/api/api.go

@ -18,18 +18,21 @@ const (
)
type api struct {
model components.Model
}
func newAPI() *api {
return &api{}
func newAPI(model components.Model) *api {
return &api{
model: model,
}
}
func (api *api) createJob(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusOK)
}
func Build(router components.Router) {
api := newAPI()
func Build(router components.Router, model components.Model) {
api := newAPI(model)
router.Get("/debug", expvar.Handler())
router.Get("/status", http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {

6
internal/components/components.go

@ -27,6 +27,12 @@ type Application interface {
type Config interface {
Logger() *data.Logger
Server() *data.Server
Storage() *data.Storage
}
// Crypto AFAIRE.
type Crypto interface {
DecryptString(text string) (string, error)
}
// Logger AFAIRE.

5
internal/config/config.go

@ -62,6 +62,11 @@ func (cc *config) Server() *data.Server {
return cc.data.Server
}
// Storage AFAIRE.
func (cc *config) Storage() *data.Storage {
return cc.data.Storage
}
/*
######################################################################################################## @(°_°)@ #######
*/

12
internal/config/data/data.go

@ -8,14 +8,16 @@ package data
// Data AFAIRE.
type Data struct {
Logger *Logger `json:"logger"`
Server *Server `json:"server"`
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()
}
// Validate AFAIRE.
@ -32,6 +34,12 @@ func (d *Data) Validate() error {
return err
}
if d.Storage == nil {
d.Storage = defaultStorage()
} else if err := d.Storage.validate(); err != nil {
return err
}
return nil
}

30
internal/config/data/storage.go

@ -0,0 +1,30 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### data ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package data
const (
_defaultStorage = "memory"
)
// Storage AFAIRE.
type Storage struct {
Type string
}
func defaultStorage() *Storage {
return &Storage{
Type: _defaultStorage,
}
}
func (s *Storage) validate() error {
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

27
internal/model/model.go

@ -0,0 +1,27 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### model ####### Copyright (c) 2021 mls-361 ################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package model
import (
"forge.chapril.org/armen/model"
"forge.chapril.org/armen/armen/internal/components"
)
// Build AFAIRE.
func Build(logger components.Logger, storage components.Storage) (components.Model, error) {
config := &model.Config{
Logger: logger,
Storage: storage,
}
return model.New(config)
}
/*
######################################################################################################## @(°_°)@ #######
*/

34
internal/storage/storage.go

@ -0,0 +1,34 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### storage ####### Copyright (c) 2021 mls-361 ################################################# MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package storage
import (
"forge.chapril.org/armen/memory"
"forge.chapril.org/mls-361/failure"
"forge.chapril.org/armen/armen/internal/components"
)
// Build AFAIRE.
func Build(app components.Application, config components.Config, logger components.Logger,
crypto components.Crypto) (components.Storage, error) {
cfg := config.Storage()
switch cfg.Type {
case "memory":
return memory.New(), nil
default:
return nil, failure.New( ///////////////////////////////////////////////////////////////////////////////////////
"this storage type is unknown",
"type", cfg.Type,
)
}
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save