|
|
@@ -32,19 +32,19 @@ type ClientBusHttp struct {
|
|
|
lCtx comp_spec.ILocalCtx
|
|
|
log comp_spec.ILogBuf
|
|
|
isWork mKs.ISafeBool
|
|
|
- urlRemote string // URL дистанционной шины
|
|
|
- urlLocal string // URL локальной шины для веб-хуков
|
|
|
+ urlRemote defs.ITxtFix // URL дистанционной шины
|
|
|
+ urlLocal defs.ITxtFix // URL локальной шины для веб-хуков
|
|
|
}
|
|
|
|
|
|
// NewClientBusHttp - -возвращает новый клиент HTTP-шины.
|
|
|
-func NewClientBusHttp(urlRemote string) bus_spec.IBusClient {
|
|
|
+func NewClientBusHttp(urlRemote defs.ITxtFix) bus_spec.IBusClient {
|
|
|
param := &log_buf.LogBufParam{
|
|
|
IsTerm_: safe_bool.NewSafeBool(true),
|
|
|
Prefix_: defs.Txt("ClientBusHttp"),
|
|
|
}
|
|
|
log := mL1.NewLogBuf(param)
|
|
|
log.Debug(defs.Txt("NewClientBusHttp()"))
|
|
|
- helpers.Hassert(urlRemote != "", "NewClientBusHttp(): urlRemote is empty", []any{})
|
|
|
+ helpers.Hassert(urlRemote != nil, "NewClientBusHttp(): urlRemote is empty", []any{})
|
|
|
kCtx := kctx.GetKernelCtx()
|
|
|
resLocal := safe_string.NewSafeStringGetenv(defs.Txt("LOCAL_HTTP_URL"))
|
|
|
resLocal.Hassert(defs.Txt("NewClientBusHttp(): in get env LOCAL_HTTP_URL)"))
|
|
|
@@ -55,8 +55,8 @@ func NewClientBusHttp(urlRemote string) bus_spec.IBusClient {
|
|
|
log: log,
|
|
|
bus: kBusHttp,
|
|
|
isWork: mL1.NewSafeBool(true),
|
|
|
- urlRemote: strings.TrimSuffix(urlRemote, "/"),
|
|
|
- urlLocal: strings.TrimSuffix(urlLocal.Get().String(), "/"),
|
|
|
+ urlRemote: urlRemote.TrimSuffix("/"),
|
|
|
+ urlLocal: urlLocal.Get().TrimSuffix("/"),
|
|
|
}
|
|
|
return sf
|
|
|
}
|
|
|
@@ -76,7 +76,7 @@ func (sf *ClientBusHttp) Unsubscribe(handler bus_spec.IBusHandlerSubscribe) {
|
|
|
"ClientBusHttp.Unsubscribe(): in marshal to JSON unsubscribe request, err=\n\t%v", err)
|
|
|
reader := strings.NewReader(string(binReq))
|
|
|
|
|
|
- hReq, err := http.NewRequest(http.MethodPost, sf.urlRemote+"/bus/unsub", reader)
|
|
|
+ hReq, err := http.NewRequest(http.MethodPost, sf.urlRemote.String()+"/bus/unsub", reader)
|
|
|
mL1.FnHassert(helpers.Hassert)(err == nil, "ClientBusHttp.Unsubscribe(): in new request, err=\n\t%v", err)
|
|
|
|
|
|
resBody := sf.makePost(hReq)
|
|
|
@@ -106,14 +106,14 @@ func (sf *ClientBusHttp) Subscribe(handler bus_spec.IBusHandlerSubscribe) mKs.IR
|
|
|
helpers.Hassert(err == nil, "ClientBusHttp.Subscribe(): in generate UUID v6, err=\n\t%v", []any{err})
|
|
|
req := &dot.SubscribeReq{
|
|
|
Topic_: handler.Topic().Get(),
|
|
|
- Uuid_: _uuid.String(),
|
|
|
- WebHook_: sf.urlLocal + "/bus/pub", // Веб-хук всегда на своей стороне
|
|
|
+ Uuid_: defs.Txt(_uuid.String()),
|
|
|
+ WebHook_: defs.Txt("%v%v", sf.urlLocal.String()+"/bus/pub"), // Веб-хук всегда на своей стороне
|
|
|
}
|
|
|
req.SelfCheck()
|
|
|
binReq, _ := json.MarshalIndent(req, "", " ")
|
|
|
body := strings.NewReader(string(binReq))
|
|
|
-
|
|
|
- hReq, err := http.NewRequest(http.MethodPost, sf.urlRemote+"/bus/sub", body)
|
|
|
+ endPoint := defs.Txt("%v%v", sf.urlLocal.String()+"/bus/sub")
|
|
|
+ hReq, err := http.NewRequest(http.MethodPost, endPoint.String(), body)
|
|
|
helpers.Hassert(err != nil, "ClientBusHttp.Subscribe(): in new request, err=\n\t%v", []any{})
|
|
|
|
|
|
resBody := sf.makePost(hReq)
|
|
|
@@ -127,7 +127,7 @@ func (sf *ClientBusHttp) Subscribe(handler bus_spec.IBusHandlerSubscribe) mKs.IR
|
|
|
err := defs.Err("ClientBusHttp.Subscribe(): in unmarshal response, err=\n\t%v", err)
|
|
|
return mL0.NewErr[mKs.EBool](err)
|
|
|
}
|
|
|
- if resp.Status_ != "ok" {
|
|
|
+ if resp.Status_.Get() != "ok" {
|
|
|
err := defs.Err("ClientBusHttp.Subscribe(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
|
return mL0.NewErr[mKs.EBool](err)
|
|
|
}
|
|
|
@@ -151,8 +151,8 @@ func (sf *ClientBusHttp) SendRequest(topic bus_ent.ITopicFix, binReq []byte) mL0
|
|
|
req.SelfCheck()
|
|
|
_binReq, _ := json.MarshalIndent(req, "", " ")
|
|
|
body := strings.NewReader(string(_binReq))
|
|
|
-
|
|
|
- hReq, err := http.NewRequest(http.MethodPost, sf.urlRemote+"/bus/request", body)
|
|
|
+ endPont := defs.Txt("%v%v", sf.urlRemote.String(), "/bus/request")
|
|
|
+ hReq, err := http.NewRequest(http.MethodPost, endPont.String(), body)
|
|
|
mL1.FnHassert(helpers.Hassert)(err == nil, "ClientBusHttp.SendRequest(): in new request, err=\n\t%v")
|
|
|
|
|
|
resBody := sf.makePost(hReq)
|
|
|
@@ -197,14 +197,14 @@ func (sf *ClientBusHttp) Publish(topic bus_ent.ITopicFix, binMsg []byte) mL0.IRe
|
|
|
mL1.FnHassert(helpers.Hassert)(err == nil, "ClientBusHttp.Publish(): in generate UUID v6, err=\n\t%v", err)
|
|
|
req := &dot.PublishReq{
|
|
|
Topic_: topic.Get(),
|
|
|
- Uuid_: _uuid.String(),
|
|
|
+ Uuid_: defs.Txt(_uuid.String()),
|
|
|
BinMsg_: binMsg,
|
|
|
}
|
|
|
req.SelfCheck()
|
|
|
binReq, _ := json.MarshalIndent(req, "", " ")
|
|
|
body := strings.NewReader(string(binReq))
|
|
|
-
|
|
|
- hReq, err := http.NewRequest(http.MethodPost, sf.urlRemote+"/bus/pub", body)
|
|
|
+ endPoint := defs.Txt("%v%v", sf.urlRemote.Get(), "/bus/pub")
|
|
|
+ hReq, err := http.NewRequest(http.MethodPost, endPoint.String(), body)
|
|
|
mL1.FnHassert(helpers.Hassert)(err == nil, "ClientBusHttp.Publish(): in new request, err=\n\t%v")
|
|
|
|
|
|
resBody := sf.makePost(hReq)
|
|
|
@@ -218,7 +218,7 @@ func (sf *ClientBusHttp) Publish(topic bus_ent.ITopicFix, binMsg []byte) mL0.IRe
|
|
|
err := defs.Err("ClientBusHttp.Publish(): in unmarshal response, err=\n\t%v", err)
|
|
|
return mL0.NewErr[mKs.EBool](err)
|
|
|
}
|
|
|
- if resp.Status_ != "ok" {
|
|
|
+ if resp.Status_.Get() != "ok" {
|
|
|
err := defs.Err("ClientBusHttp.Publish(): resp!='ok', err=\n\t%v", resp.Status_)
|
|
|
return mL0.NewErr[mKs.EBool](err)
|
|
|
}
|