diff --git a/go.mod b/go.mod index 040b534..abcc192 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( github.com/joho/godotenv v1.5.1 // indirect github.com/lib/pq v1.10.9 // indirect gitlab.com/mstarongitlab/goutils v0.0.0-20240117084827-7f9be06e1b58 // indirect + gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d golang.org/x/crypto v0.14.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect diff --git a/go.sum b/go.sum index bd1f72a..7a5908f 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gitlab.com/mstarongitlab/goutils v0.0.0-20240117084827-7f9be06e1b58 h1:mRislY6modrbqu9ck/3d+P1b/fqxEcuN/s67ULMgATY= gitlab.com/mstarongitlab/goutils v0.0.0-20240117084827-7f9be06e1b58/go.mod h1:SvqfzFxgashuZPqR9kPwQ9gFA7I1yskZjhmGmY2pAow= +gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d h1:ixTYuViFIDQh9fs3xyc8sPKBr7dU7T98rs4kqM0q51k= +gitlab.com/mstarongitlab/weblogger v0.0.0-20240123135616-d64461e3b20d/go.mod h1:8G+BrXVs97wI7W+Z4E8M2MXFFKKy01cVnFazoCpNg9Y= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/server/server.go b/server/server.go index 510b57c..9c23d43 100644 --- a/server/server.go +++ b/server/server.go @@ -1,13 +1,37 @@ package server import ( + "net/http" + "github.com/julienschmidt/httprouter" "gitlab.com/mstarongitlab/linstrom/config" + "gitlab.com/mstarongitlab/linstrom/guardian" "gitlab.com/mstarongitlab/linstrom/storage" + "gitlab.com/mstarongitlab/weblogger" ) type Server struct { - Router *httprouter.Router + // Register routes on here + Router *httprouter.Router + // Where to read and write stuff from Storage *storage.Storage - Config *config.Config + // Global config. READ ONLY + Config *config.Config + // Final handler given to http.ListenAndServe + // Can be any router or middleware wrapped around a router + handler http.Handler +} + +func NewServer(cfg *config.Config, s *storage.Storage) *Server { + router := httprouter.New() + return &Server{ + Router: router, + Storage: s, + Config: cfg, + handler: guardian.NewMiddleware(weblogger.LoggingMiddleware(router), cfg, s), + } +} + +func (s *Server) Run() { + http.ListenAndServe(":8080", s.handler) }