diff options
Diffstat (limited to 'src/server/server.go')
| -rw-r--r-- | src/server/server.go | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/src/server/server.go b/src/server/server.go index c483069..eb5f785 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -4,26 +4,23 @@ import ( "net/http" "github.com/go-chi/chi/v5" - "github.com/google/uuid" "gitlab.com/alexkavon/newsstand/src/conf" "gitlab.com/alexkavon/newsstand/src/db" ) type Server struct { - Router *chi.Mux - Db *db.Database - Config *conf.Conf - Ui Ui - Sessions map[string]session + Router *chi.Mux + Db *db.Database + Config *conf.Conf + Ui Ui } func NewServer(config *conf.Conf, database *db.Database) *Server { return &Server{ - Router: NewRouter(config), - Db: database, - Config: config, - Ui: NewUi(config), - Sessions: map[string]session{}, + Router: NewRouter(config), + Db: database, + Config: config, + Ui: NewUi(config), } } @@ -33,6 +30,7 @@ func (s *Server) BuildUi() { func (s *Server) RegisterRoutes(routes Routes) { for _, r := range routes { + s.Router.Use(r.Middlewares...) s.Router.Method(r.Method, r.Path, r.HandlerFunc(s)) } } @@ -40,15 +38,3 @@ func (s *Server) RegisterRoutes(routes Routes) { func (s *Server) Serve() { http.ListenAndServe(":"+s.Config.Server.Port, s.Router) } - -func (s *Server) NewSession(w http.ResponseWriter, username string) { - token := uuid.NewString() - s.Sessions[token] = session{ - username: username, - } - - http.SetCookie(w, &http.Cookie{ - Name: "session_token", - Value: token, - }) -} |
