Browse Source

En cours de développement

master
mls-361 6 months ago
parent
commit
697851e883
  1. 5
      cmd/main.go
  2. 1
      go.mod
  3. 2
      go.sum
  4. 8
      internal/components/components.go
  5. 2
      internal/config/config.go
  6. 51
      internal/router/router.go
  7. 4
      internal/server/server.go

5
cmd/main.go

@ -19,6 +19,7 @@ import (
"forge.chapril.org/armen/armen/internal/components"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/logger"
"forge.chapril.org/armen/armen/internal/router"
"forge.chapril.org/armen/armen/internal/server"
)
@ -38,7 +39,9 @@ func createComponents(app components.Application) (components.Logger, components
return nil, nil, failure.Wrap(err, "logger") ///////////////////////////////////////////////////////////////////
}
server, err := server.Build(config, logger)
router := router.Build(logger)
server, err := server.Build(config, logger, router)
if err != nil {
return nil, nil, failure.Wrap(err, "server") ///////////////////////////////////////////////////////////////////
}

1
go.mod

@ -8,4 +8,5 @@ require (
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
github.com/julienschmidt/httprouter v1.3.0
)

2
go.sum

@ -14,3 +14,5 @@ forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de h1:6SpigDheC
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de/go.mod h1:kQ2uGfvLdRl47OxE/GI8LThroYe6RnodiqfRUbJMst0=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff h1:N7L3nN/9Wlck9qtIxH6gbQ9sbWtsZ048+eDEdpvD09g=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff/go.mod h1:OAYM+f6ErfC4jbruuG2crA5W7YSpr7+wEs2MrxIzR3Q=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=

8
internal/components/components.go

@ -7,6 +7,8 @@
package components
import (
"net/http"
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/mls-361/uuid"
@ -31,6 +33,12 @@ type Logger interface {
logger.Logger
}
// Router AFAIRE.
type Router interface {
Get(path string, handler http.Handler)
Post(path string, handler http.Handler)
}
// Server AFAIRE.
type Server interface {
Start() error

2
internal/config/config.go

@ -52,10 +52,12 @@ func Load(app components.Application) (*config, error) {
return cc, nil
}
// Logger AFAIRE.
func (cc *config) Logger() *data.Logger {
return cc.data.Logger
}
// Server AFAIRE.
func (cc *config) Server() *data.Server {
return cc.data.Server
}

51
internal/router/router.go

@ -0,0 +1,51 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### router ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package router
import (
"net/http"
"github.com/julienschmidt/httprouter"
"forge.chapril.org/armen/armen/internal/components"
)
type router struct {
mux *httprouter.Router
}
func newRouter() *router {
return &router{
mux: httprouter.New(),
}
}
// Build AFAIRE.
func Build(logger components.Logger) *router {
cr := newRouter()
cr.mux.PanicHandler = func(rw http.ResponseWriter, _ *http.Request, _ interface{}) {
//AFINIR: logger
rw.WriteHeader(http.StatusInternalServerError)
}
return cr
}
// Get AFAIRE.
func (cr *router) Get(path string, handler http.Handler) {
cr.mux.Handler(http.MethodGet, path, handler)
}
// Post AFAIRE.
func (cr *router) Post(path string, handler http.Handler) {
cr.mux.Handler(http.MethodPost, path, handler)
}
/*
######################################################################################################## @(°_°)@ #######
*/

4
internal/server/server.go

@ -7,8 +7,6 @@
package server
import (
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/armen/armen/internal/components"
)
@ -19,7 +17,7 @@ func newServer() *server {
return &server{}
}
func Build(config components.Config, logger logger.Logger) (*server, error) {
func Build(config components.Config, logger components.Logger, router components.Router) (*server, error) {
cs := newServer()
return cs, nil

Loading…
Cancel
Save