infra-dashboard/main.go
2024-08-08 17:18:46 +02:00

47 lines
1.5 KiB
Go

// Receive and send information about servers
package main
import (
h "infra-dashboard/Http"
tools "infra-dashboard/Tools"
"log"
"net/http"
"github.com/alexflint/go-arg"
"github.com/gorilla/mux"
)
var (
args struct {
Log string `arg:"-l,--logfile" help:"location of output logfile." default:"infra-dashboard-access.log"`
EnvFile string `arg:"-e,--envfile" help:"location of file containing environment variables." default:".env"`
}
)
func main() {
arg.MustParse(&args)
tools.InitLog(args.Log)
tools.ReadDotEnvFile(args.EnvFile)
router := mux.NewRouter()
router.NotFoundHandler = http.HandlerFunc(h.NotFound)
router.HandleFunc("/", h.RequestHandler).Methods("GET")
router.HandleFunc("/healthcheck", h.HealthHandler)
router.HandleFunc("/os", h.GetOS).Methods("GET")
router.HandleFunc("/os/{id:[0-9]+}", h.GetOSbyID).Methods("GET")
router.HandleFunc("/os/create", h.CreateOS).Methods("POST")
router.HandleFunc("/os/distribution", h.GetDistributionList).Methods("GET")
router.HandleFunc("/os/distribution/{distribution:[a-zA-Z]+}/versions", h.GetVersionsByDistributionList).Methods("GET")
router.HandleFunc("/servers", h.GetServersList).Methods("GET")
router.HandleFunc("/server/{id:[0-9]+}", h.GetServersbyID).Methods("GET")
router.HandleFunc("/server/os/{os_id:[0-9]+}", h.GetServersbyOS).Methods("GET")
router.HandleFunc("/packages", h.GetAllPackages).Methods("GET")
router.HandleFunc("/packages/{id:[0-9]+}", h.GetPackagebyID).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", router))
}