http_api.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // package http_api -- различные API для работы веб-морды.
  2. package http_api
  3. import (
  4. "fmt"
  5. "github.com/gofiber/fiber/v3"
  6. mL0 "gitp78su.ipnodns.ru/svi/kern/v4/lev0"
  7. "gitp78su.ipnodns.ru/svi/kern/v4/lev0/alias"
  8. "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx"
  9. )
  10. // HttpApi -- различные API для работы веб-морды.
  11. type HttpApi struct{}
  12. // NewHttpApi -- возвращает новое HttpApi.
  13. func NewHttpApi() *mL0.Result[*HttpApi] {
  14. sf := &HttpApi{}
  15. resKernCtx := kctx.GetKernelCtx()
  16. if resKernCtx.IsErr() {
  17. err := fmt.Errorf("NewHttpApi(): in kern ctx, err=\n\t%w", resKernCtx.Err())
  18. return mL0.NewErr[*HttpApi](err)
  19. }
  20. kCtx := resKernCtx.Val()
  21. optFiber := kCtx.Get("fiberApp")
  22. if optFiber.IsNone() {
  23. err := fmt.Errorf("NewHttpApi(): not found fiberApp in kernel ctx")
  24. return mL0.NewErr[*HttpApi](err)
  25. }
  26. fiberApp := optFiber.Val().Val().(*fiber.App)
  27. fiberApp.Post("/api_time", sf.postTime)
  28. return mL0.NewRes(sf)
  29. }
  30. // Возвращает текущее время сервера.
  31. func (sf *HttpApi) postTime(ctx fiber.Ctx) error {
  32. aTime := alias.NewATime()
  33. return ctx.SendString(aTime.Get())
  34. }