Initial commit
This commit is contained in:
22
internal/app/api/router.go
Normal file
22
internal/app/api/router.go
Normal file
@ -0,0 +1,22 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
v1 "git.cesium.pw/niku/virteen/internal/app/api/v1"
|
||||
"git.cesium.pw/niku/virteen/internal/middleware"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/helmet"
|
||||
)
|
||||
|
||||
func ConfigureRoutes(app *fiber.App) error {
|
||||
api := app.Group("/api")
|
||||
|
||||
api.Use(helmet.New())
|
||||
api.Use(middleware.ErrorHandler())
|
||||
|
||||
err := v1.ConfigureRoutes(api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
9
internal/app/api/v1/ping.go
Normal file
9
internal/app/api/v1/ping.go
Normal file
@ -0,0 +1,9 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Ping(c *fiber.Ctx) error {
|
||||
return c.SendString("pong")
|
||||
}
|
43
internal/app/api/v1/router.go
Normal file
43
internal/app/api/v1/router.go
Normal file
@ -0,0 +1,43 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"git.cesium.pw/niku/virteen/internal/auth"
|
||||
"git.cesium.pw/niku/virteen/internal/middleware"
|
||||
"git.cesium.pw/niku/virteen/internal/podman"
|
||||
"git.cesium.pw/niku/virteen/internal/podman/models"
|
||||
"git.cesium.pw/niku/virteen/internal/podman/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/monitor"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func ConfigureRoutes(router fiber.Router) error {
|
||||
v1 := router.Group("/v1")
|
||||
|
||||
ac := auth.NewPamAuthController()
|
||||
ag := v1.Group("/auth")
|
||||
ag.Post("/token", ac.GetToken)
|
||||
|
||||
v1.Get("/ping", Ping)
|
||||
v1.Get("/metrics", monitor.New())
|
||||
|
||||
v1.Use(middleware.Protected())
|
||||
|
||||
var cs models.PodmanService
|
||||
cs, err := services.NewPodmanContainerService()
|
||||
if err != nil {
|
||||
panic(errors.Wrapf(err, "failed to build podman container service"))
|
||||
}
|
||||
|
||||
cc := podman.NewPodmanController(&cs)
|
||||
|
||||
cg := v1.Group("/containers")
|
||||
cg.Get("/", cc.ListContainers)
|
||||
cg.Post("/", cc.CreateContainer)
|
||||
|
||||
ccg := cg.Group("/:name")
|
||||
ccg.Put("/status", cc.UpdateContainerStatus)
|
||||
ccg.Delete("/", cc.DeleteContainer)
|
||||
|
||||
return nil
|
||||
}
|
19
internal/app/main.go
Normal file
19
internal/app/main.go
Normal file
@ -0,0 +1,19 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.cesium.pw/niku/virteen/internal/app/api"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/compress"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
)
|
||||
|
||||
func Run() error {
|
||||
app := fiber.New()
|
||||
|
||||
app.Use(logger.New())
|
||||
app.Use(compress.New())
|
||||
|
||||
api.ConfigureRoutes(app)
|
||||
|
||||
return app.Listen(":3000")
|
||||
}
|
Reference in New Issue
Block a user