|
@@ -22,7 +22,6 @@ import (
|
|
|
"gitp78su.ipnodns.ru/svi/kern/krn/kbus/kbus_msg/msg_unsub"
|
|
"gitp78su.ipnodns.ru/svi/kern/krn/kbus/kbus_msg/msg_unsub"
|
|
|
"gitp78su.ipnodns.ru/svi/kern/krn/kctx"
|
|
"gitp78su.ipnodns.ru/svi/kern/krn/kctx"
|
|
|
. "gitp78su.ipnodns.ru/svi/kern/krn/ktypes"
|
|
. "gitp78su.ipnodns.ru/svi/kern/krn/ktypes"
|
|
|
- "gitp78su.ipnodns.ru/svi/kern/mock/mock_hand_sub_http"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// ClientBusHttp -- клиент HTTP-шины
|
|
// ClientBusHttp -- клиент HTTP-шины
|
|
@@ -83,7 +82,7 @@ func (sf *ClientBusHttp) Unsubscribe(handler IBusHandlerSubscribe) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Subscribe -- подписывается на топик в дистанционной шине
|
|
// Subscribe -- подписывается на топик в дистанционной шине
|
|
|
-func (sf *ClientBusHttp) Subscribe(handler IBusHandlerSubscribe) error {
|
|
|
|
|
|
|
+func (sf *ClientBusHttp) Subscribe(handler IBusHandlerSubscribe) Result[bool] {
|
|
|
_uuid, err := uuid.NewV6()
|
|
_uuid, err := uuid.NewV6()
|
|
|
Hassert(err == nil, "ClientBusHttp.Subscribe(): in generate UUID v6, err=\n\t%v", err)
|
|
Hassert(err == nil, "ClientBusHttp.Subscribe(): in generate UUID v6, err=\n\t%v", err)
|
|
|
req := &msg_sub.SubscribeReq{
|
|
req := &msg_sub.SubscribeReq{
|
|
@@ -102,7 +101,7 @@ func (sf *ClientBusHttp) Subscribe(handler IBusHandlerSubscribe) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
err := fmt.Errorf("ClientBusHttp.Subscribe(): in make request, err=\n\t%w", err)
|
|
err := fmt.Errorf("ClientBusHttp.Subscribe(): in make request, err=\n\t%w", err)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return err
|
|
|
|
|
|
|
+ return NewErr[bool](err)
|
|
|
}
|
|
}
|
|
|
resp := &msg_sub.SubscribeResp{}
|
|
resp := &msg_sub.SubscribeResp{}
|
|
|
err = json.Unmarshal(binBody, resp)
|
|
err = json.Unmarshal(binBody, resp)
|
|
@@ -110,18 +109,15 @@ func (sf *ClientBusHttp) Subscribe(handler IBusHandlerSubscribe) error {
|
|
|
if string(resp.Status_) != "ok" {
|
|
if string(resp.Status_) != "ok" {
|
|
|
err := fmt.Errorf("ClientBusHttp.Subscribe(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
err := fmt.Errorf("ClientBusHttp.Subscribe(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return err
|
|
|
|
|
|
|
+ return NewErr[bool](err)
|
|
|
}
|
|
}
|
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.Subscribe(): resp uuid(%v) bad", resp.Uuid_)
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.Subscribe(): resp uuid(%v) bad", resp.Uuid_)
|
|
|
- // FIXME: вот тут похоже дичь
|
|
|
|
|
- _handler := handler.(*mock_hand_sub_http.MockHandSubHttp)
|
|
|
|
|
- _handler.SetName(resp.Name_)
|
|
|
|
|
- err = sf.bus.Subscribe(_handler)
|
|
|
|
|
- return err
|
|
|
|
|
|
|
+ res := sf.bus.Subscribe(handler)
|
|
|
|
|
+ return res
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SendRequest -- отправляет в дистанционную шину запрос
|
|
// SendRequest -- отправляет в дистанционную шину запрос
|
|
|
-func (sf *ClientBusHttp) SendRequest(topic ATopic, binReq []byte) ([]byte, error) {
|
|
|
|
|
|
|
+func (sf *ClientBusHttp) SendRequest(topic ATopic, binReq []byte) Result[[]byte] {
|
|
|
_uuid, err := uuid.NewV6()
|
|
_uuid, err := uuid.NewV6()
|
|
|
Hassert(err == nil, "ClientBusHttp.SendRequest(): in generate UUID v6, err=\n\t%v", err)
|
|
Hassert(err == nil, "ClientBusHttp.SendRequest(): in generate UUID v6, err=\n\t%v", err)
|
|
|
req := &msg_serve.ServeReq{
|
|
req := &msg_serve.ServeReq{
|
|
@@ -140,7 +136,7 @@ func (sf *ClientBusHttp) SendRequest(topic ATopic, binReq []byte) ([]byte, error
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
err := fmt.Errorf("ClientBusHttp.SendRequest(): in make request, err=\n\t%w", err)
|
|
err := fmt.Errorf("ClientBusHttp.SendRequest(): in make request, err=\n\t%w", err)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return NewErr[[]byte](err)
|
|
|
}
|
|
}
|
|
|
resp := &msg_serve.ServeResp{}
|
|
resp := &msg_serve.ServeResp{}
|
|
|
err = json.Unmarshal(binBody, resp)
|
|
err = json.Unmarshal(binBody, resp)
|
|
@@ -148,10 +144,10 @@ func (sf *ClientBusHttp) SendRequest(topic ATopic, binReq []byte) ([]byte, error
|
|
|
if string(resp.Status_) != "ok" {
|
|
if string(resp.Status_) != "ok" {
|
|
|
err := fmt.Errorf("ClientBusHttp.SendRequest(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
err := fmt.Errorf("ClientBusHttp.SendRequest(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return NewErr[[]byte](err)
|
|
|
}
|
|
}
|
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.SendRequest(): resp uuid(%v) bad", resp.Uuid_)
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.SendRequest(): resp uuid(%v) bad", resp.Uuid_)
|
|
|
- return resp.BinResp_, nil
|
|
|
|
|
|
|
+ return NewOk(resp.BinResp_)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// RegisterServe -- регистрирует в локальной шине обработчик
|
|
// RegisterServe -- регистрирует в локальной шине обработчик
|
|
@@ -161,7 +157,7 @@ func (sf *ClientBusHttp) RegisterServe(handler IBusHandlerServe) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Publish -- публикует сообщение в дистанционной шину
|
|
// Publish -- публикует сообщение в дистанционной шину
|
|
|
-func (sf *ClientBusHttp) Publish(topic ATopic, binMsg []byte) error {
|
|
|
|
|
|
|
+func (sf *ClientBusHttp) Publish(topic ATopic, binMsg []byte) Result[bool] {
|
|
|
_uuid, err := uuid.NewV6()
|
|
_uuid, err := uuid.NewV6()
|
|
|
Hassert(err == nil, "ClientBusHttp.Publish(): in generate UUID v6, err=\n\t%v", err)
|
|
Hassert(err == nil, "ClientBusHttp.Publish(): in generate UUID v6, err=\n\t%v", err)
|
|
|
req := &msg_pub.PublishReq{
|
|
req := &msg_pub.PublishReq{
|
|
@@ -180,7 +176,7 @@ func (sf *ClientBusHttp) Publish(topic ATopic, binMsg []byte) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
err := fmt.Errorf("ClientBusHttp.Publish(): in make request, err=\n\t%w", err)
|
|
err := fmt.Errorf("ClientBusHttp.Publish(): in make request, err=\n\t%w", err)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return err
|
|
|
|
|
|
|
+ return NewErr[bool](err)
|
|
|
}
|
|
}
|
|
|
resp := &msg_pub.PublishResp{}
|
|
resp := &msg_pub.PublishResp{}
|
|
|
err = json.Unmarshal(binBody, resp)
|
|
err = json.Unmarshal(binBody, resp)
|
|
@@ -188,10 +184,10 @@ func (sf *ClientBusHttp) Publish(topic ATopic, binMsg []byte) error {
|
|
|
if string(resp.Status_) != "ok" {
|
|
if string(resp.Status_) != "ok" {
|
|
|
err := fmt.Errorf("ClientBusHttp.Publish(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
err := fmt.Errorf("ClientBusHttp.Publish(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
|
sf.log.Err(err.Error())
|
|
sf.log.Err(err.Error())
|
|
|
- return err
|
|
|
|
|
|
|
+ return NewErr[bool](err)
|
|
|
}
|
|
}
|
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.Publish(): resp uuid(%v) bad", resp.Uuid_)
|
|
Hassert(resp.Uuid_ == req.Uuid_, "ClientBusHttp.Publish(): resp uuid(%v) bad", resp.Uuid_)
|
|
|
- return nil
|
|
|
|
|
|
|
+ return NewOk(true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Единый обработчик запросов
|
|
// Единый обработчик запросов
|