http_api.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // package http_api -- различные API для работы веб-морды
  2. package http_api
  3. import (
  4. "fmt"
  5. "github.com/gofiber/fiber/v2"
  6. "gitp78su.ipnodns.ru/svi/kern/v4/krn/kctx"
  7. . "gitp78su.ipnodns.ru/svi/kern/v4/lev0/ktypes"
  8. . "gitp78su.ipnodns.ru/svi/kern/v4/lev1/helpers"
  9. . "gitp78su.ipnodns.ru/svi/kern/v4/lev1/result"
  10. )
  11. // HttpApi -- различные API для работы веб-морды
  12. type HttpApi struct{}
  13. // NewHttpApi -- возвращает новое HttpApi
  14. func NewHttpApi() IResult[*HttpApi] {
  15. sf := &HttpApi{}
  16. kCtx := kctx.GetKernelCtx()
  17. resFiber := kCtx.Get("fiberApp")
  18. if resFiber.IsErr() {
  19. err := fmt.Errorf("NewHttpApi(): in fiberApp from kernel ctx, err=\n\t%w", resFiber.Err())
  20. return NewErr[*HttpApi](err)
  21. }
  22. fiberApp := resFiber.Val().Val().(*fiber.App)
  23. fiberApp.Post("/api_time", sf.postTime)
  24. return NewRes(sf)
  25. }
  26. // Возвращает текущее время сервера
  27. func (sf *HttpApi) postTime(ctx *fiber.Ctx) error {
  28. strTime := TimeNowStr()
  29. return ctx.SendString(string(strTime))
  30. }