vault-usage-example/fiber.go

64 lines
1.2 KiB
Go
Raw Normal View History

2024-06-07 07:29:07 +03:00
package main
import (
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
)
const (
MethodList = "LIST"
)
var (
fiberConfig = fiber.Config{
AppName: userAgent,
ServerHeader: userAgent,
StrictRouting: true,
DisableDefaultDate: true,
DisablePreParseMultipartForm: true,
ErrorHandler: fiberErrorHandler,
}
)
func initFiber() *fiber.App {
// adjust with Hashicorp Vault HTTP API
haveListMethod := false
for _, m := range fiber.DefaultMethods {
if m == MethodList {
haveListMethod = true
break
}
}
if !haveListMethod {
fiberConfig.RequestMethods = append(fiber.DefaultMethods, MethodList)
}
_, debug := os.LookupEnv("DEBUG")
if debug {
fiberConfig.EnablePrintRoutes = true
}
app := fiber.New(fiberConfig)
app.Use(logger.New(logger.Config{
TimeInterval: 100 * time.Millisecond,
}))
return app
}
func fiberOk(c *fiber.Ctx) error {
c.Status(fiber.StatusOK)
return nil
}
func fiberNone(c *fiber.Ctx) error {
c.Status(fiber.StatusNoContent)
return nil
}
func fiberErrorHandler(c *fiber.Ctx, err error) error {
return fiberNone(c)
}