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