|
|
|
@@ -18,6 +18,7 @@ import ( |
|
|
|
"github.com/AFASystems/presence/internal/pkg/common/appcontext" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/config" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/controller" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/database" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/kafkaclient" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/model" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/service" |
|
|
|
@@ -32,7 +33,6 @@ var upgrader = websocket.Upgrader{ |
|
|
|
} |
|
|
|
|
|
|
|
var _ io.Writer = (*os.File)(nil) |
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
|
|
|
|
func main() { |
|
|
|
@@ -53,6 +53,11 @@ func main() { |
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT) |
|
|
|
defer stop() |
|
|
|
|
|
|
|
db, err := database.Connect(cfg) |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("Failed to open database connection: %v\n", err) |
|
|
|
} |
|
|
|
|
|
|
|
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"}) |
|
|
|
originsOk := handlers.AllowedOrigins([]string{"*"}) |
|
|
|
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"}) |
|
|
|
@@ -87,6 +92,11 @@ func main() { |
|
|
|
r.HandleFunc("/api/settings", controller.SettingsListController(appState, ctx)).Methods("GET") |
|
|
|
r.HandleFunc("/api/settings", controller.SettingsEditController(settingsWriter, appState, ctx)).Methods("POST") |
|
|
|
|
|
|
|
r.HandleFunc("/reslevis/getGateways", controller.GatewayListController(db)).Methods("GET") |
|
|
|
r.HandleFunc("/reslevis/postGateway", controller.GatewayAddController(db)).Methods("POST") |
|
|
|
r.HandleFunc("/reslevis/removeGateway/{gateway_id}", controller.GatewayDeleteController(db)).Methods("DELETE") |
|
|
|
r.HandleFunc("/reslevis/updateGateway/{gateway_id}", controller.GatewayUpdateController(db)).Methods("PUT") |
|
|
|
|
|
|
|
wsHandler := http.HandlerFunc(serveWs(appState, ctx)) |
|
|
|
restApiHandler := handlers.CORS(originsOk, headersOk, methodsOk)(r) |
|
|
|
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|