linstrom/server/server.go
mStar aka a person fa4e300b49 add bunch of stuff to server
Also pulled in my weblogger middleware
2024-01-29 17:15:28 +00:00

37 lines
891 B
Go

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)
}