eclipse / paho.golang

Go libraries
Other
341 stars 93 forks source link

ClientConfig: Inconsistent mix of exported and private (with setter) fields #174

Closed MattBrittan closed 11 months ago

MattBrittan commented 1 year ago

Autopaho.ClientConfig originally contained exported fields only; PR #69 added a range of un-exported fields with setter functions e.g.

connectUsername string
connectPassword []byte

willTopic           string
willPayload         []byte
...
connectPacketBuilder func(*paho.Connect) *paho.Connect

and a few further examples have been added since (where the settings were similar to those already in place).

We really should standardise on one approach before releasing V1. I'm suggesting that all fields be exported because:

At the same time I think it's worth renaming BrokerUrls to ServerUrls because the MQTT spec does not use the term Broker so its likely to be confusing to those new to the protocol. Again this can be non-breaking (NewConnection can overwrite ServerUrls with BrokerUrls if its empty).

alsm commented 12 months ago

I prefer to make things exported as default, as you say with there being no mutex an the struct being copied it should be safe/fine to move to exported fields for the autopaho config.

XANi commented 11 months ago

@MattBrittan just wanted to let you know that you accidentally fixed a bug here; before setting will with empty payload (example use case: using will to clear retained message when client disconnect) did not set the will on connect (because condition was if len(cfg.willTopic) > 0 && len(cfg.willPayload) > 0 { , now it works correctly.

Thanks :)