log_topic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // package log_topic -- элемент лога шины топика.
  2. package log_topic
  3. import (
  4. "gitp78su.ipnodns.ru/svi/kern/v4/d0"
  5. "gitp78su.ipnodns.ru/svi/kern/v4/d2/lti/bus_ent/topic"
  6. "gitp78su.ipnodns.ru/svi/kern/v4/d2/lti/bus_spec"
  7. )
  8. // LogTopic -- элемент лога шины.
  9. type LogTopic struct {
  10. topic *topic.LTopic // Топик, куда публиковать лог
  11. client bus_spec.IBusClient // С помощью чего публиковать лог
  12. }
  13. // NewLogTopic -- возвращает новый элемент лога.
  14. func NewLogTopic(topic *topic.LTopic, client bus_spec.IBusClient) *d0.Result[*LogTopic] {
  15. d0.If(topic == nil).Hassert("NewLogTopic(): topic==nil", []any{})
  16. if client == nil {
  17. err := d0.LetErr("NewLogTopic(): IBusClient==nil")
  18. return d0.ResErr[*LogTopic](err)
  19. }
  20. sf := &LogTopic{
  21. topic: topic,
  22. client: client,
  23. }
  24. return d0.ResOk(sf)
  25. }
  26. // Pub -- публикует сообщение в топик.
  27. func (sf *LogTopic) Pub(binMsg []byte) *d0.Result[d0.Bool] {
  28. res := sf.client.Publish(sf.topic, binMsg)
  29. if res.IsErr() {
  30. err := d0.LetErr("LogTopic.Pub(): in pub with client, err=\n\t%w", res.Err())
  31. return d0.ResErr[d0.Bool](err)
  32. }
  33. return res
  34. }