add bunch of stuff to server

Also pulled in my weblogger middleware
This commit is contained in:
mStar aka a person 2024-01-29 17:15:28 +00:00
parent c2ff5ac1fa
commit fa4e300b49
3 changed files with 29 additions and 2 deletions

1
go.mod
View file

@ -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

2
go.sum
View file

@ -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=

View file

@ -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 {
// Register routes on here
Router *httprouter.Router
// Where to read and write stuff from
Storage *storage.Storage
// 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)
}