Files
mocksnow/server/router/router.go
2025-03-22 21:28:09 +11:00

64 lines
2.0 KiB
Go

package router
import (
"log/slog"
"mocksnow/db"
"mocksnow/dist"
"mocksnow/internal/settings"
"mocksnow/server/handler"
"mocksnow/server/middleware"
"net/http"
"net/http/pprof"
)
func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver string, goVersion string, settings *settings.Settings) http.Handler {
h := &handler.Handler{
Logger: logger,
Database: database,
BuildTime: buildTime,
SHA1Ver: sha1ver,
GoVersion: goVersion,
//VcCreds: creds,
//Secret: secret,
Settings: settings,
}
mux := http.NewServeMux()
mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
mux.HandleFunc("/", h.Home)
mux.HandleFunc("/api/now/import/x_dusa2_itom_inc_imp", h.NewSnow)
mux.HandleFunc("/api/now/table/incident/", h.GetIncident)
// mux.HandleFunc("/api/event/vm/create", h.VmCreateEvent)
// mux.HandleFunc("/api/event/vm/modify", h.VmModifyEvent)
// mux.HandleFunc("/api/event/vm/move", h.VmMoveEvent)
// mux.HandleFunc("/api/event/vm/delete", h.VmDeleteEvent)
// mux.HandleFunc("/api/import/vm", h.VmImport)
// // Use this when we need to manually remove a VM from the database to clean up
// mux.HandleFunc("/api/inventory/vm/delete", h.VmCleanup)
// // add missing data to VMs
// //mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails)
// // temporary endpoint
// mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
// //mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup)
// mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)
// mux.HandleFunc("/api/report/updates", h.UpdateReportDownload)
// // endpoint for encrypting vcenter credential
// mux.HandleFunc("/api/encrypt", h.EncryptData)
// Register pprof handlers
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
return middleware.NewLoggingMiddleware(logger, mux)
}