| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- // package log_topic -- элемент лога шины топика.
- package log_topic
- import (
- "gitp78su.ipnodns.ru/svi/kern/v4/d0"
- "gitp78su.ipnodns.ru/svi/kern/v4/d2/lti/bus_ent/topic"
- "gitp78su.ipnodns.ru/svi/kern/v4/d2/lti/bus_spec"
- )
- // LogTopic -- элемент лога шины.
- type LogTopic struct {
- owner *d0.LOwner
- topic *topic.LTopic // Топик, куда публиковать лог
- client bus_spec.IBusClient // С помощью чего публиковать лог
- }
- // NewLogTopic -- возвращает новый элемент лога.
- func NewLogTopic(owner *d0.LOwner, topic *topic.LTopic, client bus_spec.IBusClient) *d0.Result[*LogTopic] {
- d0.If(topic == nil).Hassert("NewLogTopic(): topic==nil", []any{})
- if client == nil {
- err := d0.LetErr(owner, "NewLogTopic(): IBusClient==nil")
- return d0.ResErr[*LogTopic](err)
- }
- sf := &LogTopic{
- owner: owner,
- topic: topic,
- client: client,
- }
- return d0.ResOk(sf)
- }
- // Pub -- публикует сообщение в топик.
- func (sf *LogTopic) Pub(binMsg []byte) *d0.Result[d0.Bool] {
- res := sf.client.Publish(sf.topic, binMsg)
- if res.IsErr() {
- err := d0.LetErr(sf.owner, "LogTopic.Pub(): in pub with client, err=\n\t%w", res.Err())
- return d0.ResErr[d0.Bool](err)
- }
- return res
- }
|