Set session limit and add secret to server struct.
This commit is contained in:
+5
-1
@@ -58,7 +58,11 @@ func main() {
|
||||
|
||||
// Server Init
|
||||
// ------------------------------------------------------------
|
||||
server := web.NewServer(store)
|
||||
jwtSecret := os.Getenv("JWT_SECRET")
|
||||
if jwtSecret == "" {
|
||||
log.Fatal("JWT_SECRET environment variable is required")
|
||||
}
|
||||
server := web.NewServer(store, jwtSecret)
|
||||
|
||||
// We run it in a goroutine so it doesn't block main from reaching the signal listener.
|
||||
go func() {
|
||||
|
||||
+10
-5
@@ -7,17 +7,23 @@ import (
|
||||
"nfeeder/internal/db"
|
||||
)
|
||||
|
||||
var MAX_USER_SESSIONS = 5
|
||||
|
||||
type Server struct {
|
||||
httpServer *http.Server
|
||||
store *db.Store
|
||||
store *db.Store
|
||||
jwtSecret []byte
|
||||
}
|
||||
|
||||
func NewServer(store *db.Store) *Server {
|
||||
s := &Server {
|
||||
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 {
|
||||
s.httpServer = &http.Server{
|
||||
Handler: s.setupRoutes(),
|
||||
}
|
||||
|
||||
@@ -32,4 +38,3 @@ func (s *Server) Start(addr string) error {
|
||||
func (s *Server) Shutdown(ctx context.Context) error {
|
||||
return s.httpServer.Shutdown(ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user