Clean Up
This commit is contained in:
@@ -1,58 +1,59 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"time"
|
||||
"context"
|
||||
"net/http"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"reichard.io/imagini/internal/db"
|
||||
"reichard.io/imagini/internal/api"
|
||||
"reichard.io/imagini/internal/auth"
|
||||
"reichard.io/imagini/internal/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"reichard.io/imagini/internal/api"
|
||||
"reichard.io/imagini/internal/auth"
|
||||
"reichard.io/imagini/internal/config"
|
||||
"reichard.io/imagini/internal/db"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
API *api.API
|
||||
Auth *auth.AuthManager
|
||||
Config *config.Config
|
||||
Database *db.DBManager
|
||||
httpServer *http.Server
|
||||
API *api.API
|
||||
Auth *auth.AuthManager
|
||||
Config *config.Config
|
||||
Database *db.DBManager
|
||||
httpServer *http.Server
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
c := config.Load()
|
||||
db := db.NewMgr(c)
|
||||
auth := auth.NewMgr(db, c)
|
||||
api := api.NewApi(db, c, auth)
|
||||
c := config.Load()
|
||||
db := db.NewMgr(c)
|
||||
auth := auth.NewMgr(db, c)
|
||||
api := api.NewApi(db, c, auth)
|
||||
|
||||
return &Server{
|
||||
API: api,
|
||||
Auth: auth,
|
||||
Config: c,
|
||||
Database: db,
|
||||
}
|
||||
return &Server{
|
||||
API: api,
|
||||
Auth: auth,
|
||||
Config: c,
|
||||
Database: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) StartServer() {
|
||||
listenAddr := (":" + s.Config.ListenPort)
|
||||
listenAddr := (":" + s.Config.ListenPort)
|
||||
|
||||
s.httpServer = &http.Server{
|
||||
Handler: s.API.Router,
|
||||
Addr: listenAddr,
|
||||
}
|
||||
s.httpServer = &http.Server{
|
||||
Handler: s.API.Router,
|
||||
Addr: listenAddr,
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := s.httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Error("Error starting server ", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
err := s.httpServer.ListenAndServe()
|
||||
if err != nil {
|
||||
log.Error("Error starting server ", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *Server) StopServer() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
|
||||
defer cancel()
|
||||
s.httpServer.Shutdown(ctx)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
s.httpServer.Shutdown(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user