| 123456789101112131415161718192021222324252627282930313233343536 |
- // package http_api -- различные API для работы веб-морды
- package http_api
- import (
- "fmt"
- "github.com/gofiber/fiber/v2"
- "gitp78su.ipnodns.ru/svi/kern/v4/krn/kctx"
- . "gitp78su.ipnodns.ru/svi/kern/v4/lev0/ktypes"
- . "gitp78su.ipnodns.ru/svi/kern/v4/lev1/helpers"
- . "gitp78su.ipnodns.ru/svi/kern/v4/lev1/result"
- )
- // HttpApi -- различные API для работы веб-морды
- type HttpApi struct{}
- // NewHttpApi -- возвращает новое HttpApi
- func NewHttpApi() IResult[*HttpApi] {
- sf := &HttpApi{}
- kCtx := kctx.GetKernelCtx()
- resFiber := kCtx.Get("fiberApp")
- if resFiber.IsErr() {
- err := fmt.Errorf("NewHttpApi(): in fiberApp from kernel ctx, err=\n\t%w", resFiber.Err())
- return NewErr[*HttpApi](err)
- }
- fiberApp := resFiber.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))
- }
|