nats-server
nats-server copied to clipboard
[refactor]: encapsulate the network logic into internal/network folder
Currently, nats-server provides many network protocol support such as mqtt
and websocket
. But the code management seems not good and it might block the further network feature such as adding quic
support.
- code coupling:
Now all network details are in theserver
package which is easy confusing both developers and people who read the source code. The code management way here is more like what python does, each file handles one package. For example, in theserver
package, there are bothmqtt
andwebsocket
and in the future, there might bequic
. To clarify which the function relationship, we do this:
// this is a websocket function as it has prefix ws.
func (c *client) wsRead(r *wsReadInfo, ior io.Reader, buf []byte) ([][]byte, error)
// this is a mqtt function.
func (c *client) mqttConnectTrace(cp *mqttConnectProto) string {
Instead, we should encapsulate those function like the following.
package websocket
func (c *client) Read(r *wsReadInfo, ior io.Reader, buf []byte) ([][]byte, error)
package mqtt
func (c *client) ConnectTrace(cp *mqttConnectProto) string
What's worse, all unexported function are visable in server
package but they should not. I think it's better to encapsulate the network into a single package to make the code cleaner.
Thanks
For the code coupling, could also see the #3174 .
To enable a global logger which binds to the server, we could decouple many functions from the server
struct.
Thanks.
Will have @kozlovic take a look once back from extended holiday.
Will have @kozlovic take a look once back from extended holiday.
Got it, could I know about the approximate agenda about him? Thanks
A few weeks.
I am picking this up possibly looking forward to v2.10.0.
I am picking this up possibly looking forward to v2.10.0.
Glad to here it:) Regards