|
@@ -7,7 +7,7 @@ import (
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/gofiber/fiber/v3"
|
|
|
|
|
|
|
|
- "gitp78su.ipnodns.ru/svi/kern/v4/lev0/defs"
|
|
|
|
|
|
|
+ "gitp78su.ipnodns.ru/svi/kern/v4/lev0"
|
|
|
mL1 "gitp78su.ipnodns.ru/svi/kern/v4/lev1"
|
|
mL1 "gitp78su.ipnodns.ru/svi/kern/v4/lev1"
|
|
|
"gitp78su.ipnodns.ru/svi/kern/v4/lev1/comp_spec"
|
|
"gitp78su.ipnodns.ru/svi/kern/v4/lev1/comp_spec"
|
|
|
"gitp78su.ipnodns.ru/svi/kern/v4/lev1/safe_bool"
|
|
"gitp78su.ipnodns.ru/svi/kern/v4/lev1/safe_bool"
|
|
@@ -41,10 +41,10 @@ func GetKernelBusHttp() bus_spec.IKernelBus {
|
|
|
}
|
|
}
|
|
|
paramLogBuf := &mL1.LogBufParam{
|
|
paramLogBuf := &mL1.LogBufParam{
|
|
|
IsTerm_: safe_bool.NewSafeBool(true),
|
|
IsTerm_: safe_bool.NewSafeBool(true),
|
|
|
- Prefix_: defs.TxtFix("kBusHttp"),
|
|
|
|
|
|
|
+ Prefix_: lev0.LetTxt("kBusHttp"),
|
|
|
}
|
|
}
|
|
|
log := mL1.NewLogBuf(paramLogBuf)
|
|
log := mL1.NewLogBuf(paramLogBuf)
|
|
|
- log.Debug(defs.TxtFix("GetKernelBusHttp(): new"))
|
|
|
|
|
|
|
+ log.Debug("GetKernelBusHttp(): new")
|
|
|
kCtx := kctx.GetKernelCtx()
|
|
kCtx := kctx.GetKernelCtx()
|
|
|
kBus := kbus_base.GetKernelBusBase()
|
|
kBus := kbus_base.GetKernelBusBase()
|
|
|
sf := &kBusHttp{
|
|
sf := &kBusHttp{
|
|
@@ -57,29 +57,28 @@ func GetKernelBusHttp() bus_spec.IKernelBus {
|
|
|
fibApp.Post("/bus/unsub", sf.postUnsub) // Топик отписки, IN
|
|
fibApp.Post("/bus/unsub", sf.postUnsub) // Топик отписки, IN
|
|
|
fibApp.Post("/bus/request", sf.postSendRequest) // Топик входящих запросов, IN
|
|
fibApp.Post("/bus/request", sf.postSendRequest) // Топик входящих запросов, IN
|
|
|
fibApp.Post("/bus/pub", sf.postPublish) // Топик публикаций подписки, IN
|
|
fibApp.Post("/bus/pub", sf.postPublish) // Топик публикаций подписки, IN
|
|
|
- kCtx.Set(defs.TxtFix("kernBus"), sf,
|
|
|
|
|
- "GetKernelBusHttp(): http data bus")
|
|
|
|
|
|
|
+ kCtx.Set("kernBus", sf, "GetKernelBusHttp(): http data bus")
|
|
|
Bus_ = sf
|
|
Bus_ = sf
|
|
|
return Bus_
|
|
return Bus_
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Входящий запрос HTTP на подписку.
|
|
// Входящий запрос HTTP на подписку.
|
|
|
func (sf *kBusHttp) postSub(ctx fiber.Ctx) error {
|
|
func (sf *kBusHttp) postSub(ctx fiber.Ctx) error {
|
|
|
- sf.log.Debug(defs.TxtFix("postSub()"))
|
|
|
|
|
|
|
+ sf.log.Debug("postSub()")
|
|
|
ctx.Set("Content-type", "text/html; charset=utf8")
|
|
ctx.Set("Content-type", "text/html; charset=utf8")
|
|
|
ctx.Set("Content-type", "text/json")
|
|
ctx.Set("Content-type", "text/json")
|
|
|
ctx.Set("Cache-Control", "no-cache")
|
|
ctx.Set("Cache-Control", "no-cache")
|
|
|
- sf.log.Debug(defs.TxtFix("postSub()"))
|
|
|
|
|
|
|
+ sf.log.Debug("postSub()")
|
|
|
req := &dot.SubscribeReq{}
|
|
req := &dot.SubscribeReq{}
|
|
|
err := ctx.Bind().Body(req)
|
|
err := ctx.Bind().Body(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
resp := &dot.SubscribeResp{
|
|
resp := &dot.SubscribeResp{
|
|
|
- Status_: defs.TxtFix("kernelBusHttp.postSub(): in parse request, err=\n\t%v\n", err),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("kernelBusHttp.postSub(): in parse request, err=\n\t%v\n", err),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
resp.SelfCheck()
|
|
resp.SelfCheck()
|
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
|
- err := defs.Err("kBusHttp.postSub(): in body parser, status=%q", resp.Status_)
|
|
|
|
|
|
|
+ err := lev0.LetErr("kBusHttp.postSub(): in body parser, status=%q", resp.Status_)
|
|
|
sf.log.Err(err)
|
|
sf.log.Err(err)
|
|
|
return ctx.JSON(resp)
|
|
return ctx.JSON(resp)
|
|
|
}
|
|
}
|
|
@@ -94,13 +93,13 @@ func (sf *kBusHttp) processSubscribe(req *dot.SubscribeReq) *dot.SubscribeResp {
|
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
|
handler := mock_hand_sub_http.NewMockHandSubHttp(topic, req.WebHook_)
|
|
handler := mock_hand_sub_http.NewMockHandSubHttp(topic, req.WebHook_)
|
|
|
resp := &dot.SubscribeResp{
|
|
resp := &dot.SubscribeResp{
|
|
|
- Status_: defs.TxtFix("ok"),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("ok"),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
Name_: handler.Name().Get(),
|
|
Name_: handler.Name().Get(),
|
|
|
}
|
|
}
|
|
|
res := sf.Subscribe(handler)
|
|
res := sf.Subscribe(handler)
|
|
|
if res.IsErr() {
|
|
if res.IsErr() {
|
|
|
- resp.Status_ = defs.TxtFix(
|
|
|
|
|
|
|
+ resp.Status_ = lev0.LetTxt(
|
|
|
"kernelBusHttp.processSubscribe(): err=\n\t%v",
|
|
"kernelBusHttp.processSubscribe(): err=\n\t%v",
|
|
|
res.Err())
|
|
res.Err())
|
|
|
return resp
|
|
return resp
|
|
@@ -110,18 +109,18 @@ func (sf *kBusHttp) processSubscribe(req *dot.SubscribeReq) *dot.SubscribeResp {
|
|
|
|
|
|
|
|
// Входящая публикация.
|
|
// Входящая публикация.
|
|
|
func (sf *kBusHttp) postPublish(ctx fiber.Ctx) error {
|
|
func (sf *kBusHttp) postPublish(ctx fiber.Ctx) error {
|
|
|
- sf.log.Debug(defs.TxtFix("postPublish()"))
|
|
|
|
|
|
|
+ sf.log.Debug("postPublish()")
|
|
|
sf.postCommon(ctx)
|
|
sf.postCommon(ctx)
|
|
|
req := &dot.PublishReq{}
|
|
req := &dot.PublishReq{}
|
|
|
err := ctx.Bind().Body(req)
|
|
err := ctx.Bind().Body(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
resp := &dot.PublishResp{
|
|
resp := &dot.PublishResp{
|
|
|
- Status_: defs.TxtFix("kernelBusHttp.postPublish(): in parse request, err=\n\t%v\n", err),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("kernelBusHttp.postPublish(): in parse request, err=\n\t%v\n", err),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
resp.SelfCheck()
|
|
resp.SelfCheck()
|
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
|
- err := defs.Err("postPublish(): in body parser, status=%v", resp.Status_)
|
|
|
|
|
|
|
+ err := lev0.LetErr("postPublish(): in body parser, status=%v", resp.Status_)
|
|
|
sf.log.Err(err)
|
|
sf.log.Err(err)
|
|
|
return ctx.JSON(resp)
|
|
return ctx.JSON(resp)
|
|
|
}
|
|
}
|
|
@@ -132,18 +131,18 @@ func (sf *kBusHttp) postPublish(ctx fiber.Ctx) error {
|
|
|
|
|
|
|
|
// Входящая отписка от топика по HTTP.
|
|
// Входящая отписка от топика по HTTP.
|
|
|
func (sf *kBusHttp) postUnsub(ctx fiber.Ctx) error {
|
|
func (sf *kBusHttp) postUnsub(ctx fiber.Ctx) error {
|
|
|
- sf.log.Debug(defs.TxtFix("postUnsub()"))
|
|
|
|
|
|
|
+ sf.log.Debug("postUnsub()")
|
|
|
sf.postCommon(ctx)
|
|
sf.postCommon(ctx)
|
|
|
req := &dot.UnsubReq{}
|
|
req := &dot.UnsubReq{}
|
|
|
err := ctx.Bind().Body(req)
|
|
err := ctx.Bind().Body(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
resp := &dot.ServeResp{
|
|
resp := &dot.ServeResp{
|
|
|
- Status_: defs.TxtFix("kernelBusHttp.postSendRequest(): err=\n\t%v", err),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("kernelBusHttp.postSendRequest(): err=\n\t%v", err),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
resp.SelfCheck()
|
|
resp.SelfCheck()
|
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
|
- err := defs.Err("kBusHttp.postUnsub(): in body parser, status=%q", resp.Status_)
|
|
|
|
|
|
|
+ err := lev0.LetErr("kBusHttp.postUnsub(): in body parser, status=%q", resp.Status_)
|
|
|
sf.log.Err(err)
|
|
sf.log.Err(err)
|
|
|
return ctx.JSON(resp)
|
|
return ctx.JSON(resp)
|
|
|
}
|
|
}
|
|
@@ -165,11 +164,11 @@ func (sf *kBusHttp) processPublish(req *dot.PublishReq) *dot.PublishResp {
|
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
|
res := sf.Publish(topic, req.BinMsg_)
|
|
res := sf.Publish(topic, req.BinMsg_)
|
|
|
resp := &dot.PublishResp{
|
|
resp := &dot.PublishResp{
|
|
|
- Status_: defs.TxtFix("ok"),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("ok"),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
if res.IsErr() {
|
|
if res.IsErr() {
|
|
|
- resp.Status_ = defs.TxtFix("kernelBusHttp.processPublish(): err=\n\t%v", res.Err())
|
|
|
|
|
|
|
+ resp.Status_ = lev0.LetTxt("kernelBusHttp.processPublish(): err=\n\t%v", res.Err())
|
|
|
return resp
|
|
return resp
|
|
|
}
|
|
}
|
|
|
return resp
|
|
return resp
|
|
@@ -177,7 +176,7 @@ func (sf *kBusHttp) processPublish(req *dot.PublishReq) *dot.PublishResp {
|
|
|
|
|
|
|
|
// Входящий запрос.
|
|
// Входящий запрос.
|
|
|
func (sf *kBusHttp) postSendRequest(ctx fiber.Ctx) error {
|
|
func (sf *kBusHttp) postSendRequest(ctx fiber.Ctx) error {
|
|
|
- sf.log.Debug(defs.TxtFix("postSendRequest()"))
|
|
|
|
|
|
|
+ sf.log.Debug("postSendRequest()")
|
|
|
ctx.Set("Content-type", "text/html; charset=utf8")
|
|
ctx.Set("Content-type", "text/html; charset=utf8")
|
|
|
ctx.Set("Content-type", "text/json")
|
|
ctx.Set("Content-type", "text/json")
|
|
|
ctx.Set("Cache-Control", "no-cache")
|
|
ctx.Set("Cache-Control", "no-cache")
|
|
@@ -185,12 +184,12 @@ func (sf *kBusHttp) postSendRequest(ctx fiber.Ctx) error {
|
|
|
err := ctx.Bind().Body(req)
|
|
err := ctx.Bind().Body(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
resp := &dot.ServeResp{
|
|
resp := &dot.ServeResp{
|
|
|
- Status_: defs.TxtFix("kernelBusHttp.postSendRequest(): err=\n\t%v", err),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("kernelBusHttp.postSendRequest(): err=\n\t%v", err),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
resp.SelfCheck()
|
|
resp.SelfCheck()
|
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
ctx.Response().SetStatusCode(http.StatusBadRequest)
|
|
|
- err := defs.Err("kBusHttp.postSendRequest(): in body parser, status=%v", resp.Status_)
|
|
|
|
|
|
|
+ err := lev0.LetErr("kBusHttp.postSendRequest(): in body parser, status=%v", resp.Status_)
|
|
|
sf.log.Err(err)
|
|
sf.log.Err(err)
|
|
|
return ctx.JSON(resp)
|
|
return ctx.JSON(resp)
|
|
|
}
|
|
}
|
|
@@ -205,11 +204,11 @@ func (sf *kBusHttp) processSendRequest(req *dot.ServeReq) *dot.ServeResp {
|
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
topic := bus_ent.ITopicFix(topic.NewTopic(req.Topic_))
|
|
|
res := sf.SendRequest(topic, req.BinReq_)
|
|
res := sf.SendRequest(topic, req.BinReq_)
|
|
|
resp := &dot.ServeResp{
|
|
resp := &dot.ServeResp{
|
|
|
- Status_: defs.TxtFix("ok"),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("ok"),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
if res.IsErr() {
|
|
if res.IsErr() {
|
|
|
- resp.Status_ = defs.TxtFix("kernelBusHttp.processSendRequest(): err=\n\t%v", res.Err())
|
|
|
|
|
|
|
+ resp.Status_ = lev0.LetTxt("kernelBusHttp.processSendRequest(): err=\n\t%v", res.Err())
|
|
|
return resp
|
|
return resp
|
|
|
}
|
|
}
|
|
|
resp.BinResp_ = res.Ok()
|
|
resp.BinResp_ = res.Ok()
|
|
@@ -220,17 +219,17 @@ func (sf *kBusHttp) processSendRequest(req *dot.ServeReq) *dot.ServeResp {
|
|
|
func (sf *kBusHttp) processUnsubRequest(req *dot.UnsubReq) *dot.UnsubResp {
|
|
func (sf *kBusHttp) processUnsubRequest(req *dot.UnsubReq) *dot.UnsubResp {
|
|
|
req.SelfCheck()
|
|
req.SelfCheck()
|
|
|
resp := &dot.UnsubResp{
|
|
resp := &dot.UnsubResp{
|
|
|
- Status_: defs.TxtFix("ok"),
|
|
|
|
|
|
|
+ Status_: lev0.LetTxt("ok"),
|
|
|
Uuid_: req.Uuid_,
|
|
Uuid_: req.Uuid_,
|
|
|
}
|
|
}
|
|
|
- optHandler := sf.KCtx_.Get(defs.TxtFix(req.HandlerName_))
|
|
|
|
|
|
|
+ optHandler := sf.KCtx_.Get(req.HandlerName_)
|
|
|
if optHandler.IsNone() {
|
|
if optHandler.IsNone() {
|
|
|
- resp.Status_ = defs.TxtFix("kernelBusHttp.processUnsubRequest(): not get handler(%v) from kernel ctx",
|
|
|
|
|
|
|
+ resp.Status_ = lev0.LetTxt("kernelBusHttp.processUnsubRequest(): not get handler(%v) from kernel ctx",
|
|
|
req.HandlerName_)
|
|
req.HandlerName_)
|
|
|
return resp
|
|
return resp
|
|
|
}
|
|
}
|
|
|
if optHandler == nil {
|
|
if optHandler == nil {
|
|
|
- resp.Status_ = defs.TxtFix("kernelBusHttp.processUnsubRequest(): handler(%v) not exists", req.HandlerName_)
|
|
|
|
|
|
|
+ resp.Status_ = lev0.LetTxt("kernelBusHttp.processUnsubRequest(): handler(%v) not exists", req.HandlerName_)
|
|
|
return resp
|
|
return resp
|
|
|
}
|
|
}
|
|
|
hand := optHandler.Some().Val().(bus_spec.IBusHandlerSubscribe)
|
|
hand := optHandler.Some().Val().(bus_spec.IBusHandlerSubscribe)
|