| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- // package http_api -- различные API для работы веб-морды.
- package http_api
- import (
- "fmt"
- "github.com/gofiber/fiber/v3"
- mL0 "gitp78su.ipnodns.ru/svi/kern/v4/lev0"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev0/alias"
- "gitp78su.ipnodns.ru/svi/kern/v4/lev2/kctx"
- )
- // HttpApi -- различные API для работы веб-морды.
- type HttpApi struct{}
- // NewHttpApi -- возвращает новое HttpApi.
- func NewHttpApi() *mL0.Result[*HttpApi] {
- sf := &HttpApi{}
- resKernCtx := kctx.GetKernelCtx()
- if resKernCtx.IsErr() {
- err := fmt.Errorf("NewHttpApi(): in kern ctx, err=\n\t%w", resKernCtx.Err())
- return mL0.NewErr[*HttpApi](err)
- }
- kCtx := resKernCtx.Val()
- optFiber := kCtx.Get("fiberApp")
- if optFiber.IsNone() {
- err := fmt.Errorf("NewHttpApi(): not found fiberApp in kernel ctx")
- return mL0.NewErr[*HttpApi](err)
- }
- fiberApp := optFiber.Val().Val().(*fiber.App)
- fiberApp.Post("/api_time", sf.postTime)
- return mL0.NewRes(sf)
- }
- // Возвращает текущее время сервера.
- func (sf *HttpApi) postTime(ctx fiber.Ctx) error {
- aTime := alias.NewATime()
- return ctx.SendString(aTime.Get())
- }
|