42 lines
699 B
Go
42 lines
699 B
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"nfeeder/internal/db"
|
|
)
|
|
|
|
var ISSUER = "nfeeder-app"
|
|
var MAX_USER_SESSIONS = 3
|
|
|
|
type Server struct {
|
|
httpServer *http.Server
|
|
store *db.Store
|
|
jwtSecret []byte
|
|
}
|
|
|
|
func NewServer(store *db.Store, secret string) *Server {
|
|
s := &Server{
|
|
store: store,
|
|
// could extend this to something more generic
|
|
// will do if more fields needed
|
|
jwtSecret: []byte(secret),
|
|
}
|
|
|
|
s.httpServer = &http.Server{
|
|
Handler: s.setupRoutes(),
|
|
}
|
|
|
|
return s
|
|
}
|
|
|
|
func (s *Server) Start(addr string) error {
|
|
s.httpServer.Addr = addr
|
|
return s.httpServer.ListenAndServe()
|
|
}
|
|
|
|
func (s *Server) Shutdown(ctx context.Context) error {
|
|
return s.httpServer.Shutdown(ctx)
|
|
}
|