options.go 819 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package mqtt_api
  2. type Options struct {
  3. // topic前缀
  4. topicPrefix string
  5. // 日志跳过的打印路径
  6. logSkipPaths []string
  7. // mqtt配置
  8. mqttOptions *MqttClientOptions
  9. }
  10. func (options Options) GetTopicPrefix() string {
  11. return options.topicPrefix
  12. }
  13. type Option func(options *Options)
  14. // WithTopicPrefix 设置topic前缀
  15. func WithTopicPrefix(topicPrefix string) Option {
  16. return func(options *Options) {
  17. options.topicPrefix = topicPrefix
  18. }
  19. }
  20. // WithLogSkipPaths 设置日志跳过的打印路径
  21. func WithLogSkipPaths(logSkipPaths ...string) Option {
  22. return func(options *Options) {
  23. options.logSkipPaths = logSkipPaths
  24. }
  25. }
  26. // WithMqttOptions 设置mqtt配置
  27. func WithMqttOptions(mqttOptions *MqttClientOptions) Option {
  28. return func(options *Options) {
  29. options.mqttOptions = mqttOptions
  30. }
  31. }