-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve / simplify stanza building code #61
Comments
@genofire Any opinion on this? |
unnecessary complicated |
Thanks for feedback. I feel that at some point the code may be difficult to navigate, with the pure parsing / packet formatting part, being mixed with client, component workflow and connection manager. Separating the stanza building, marshalling and unmarshalling maybe help structure the code better as it grows (and I did not add test modules for all the structure generation, yet). I think it should still be possible to use the full expending stanza version as well. Anyway, still thinking about it, as you find this complicated. Maybe I will end up doing something in between (move to a separate package but remove the builder interface). I am also afraid that godoc will become unusable if we do no split the XML marshalling / unmarshalling part: https://godoc.org/gosrc.io/xmpp |
Using pointers, I managed to have a prototype of approach that can further reduce building an IQ with payload, as follows: iq := stanza.NewIQ(stanza.Attrs{Type: "get", To: "service.localhost", Id: "disco-get-1"})
disco := iq.DiscoInfo()
disco.AddIdentity("Test Component", "gateway", "service")
disco.AddFeatures(stanza.NSDiscoInfo, stanza.NSDiscoItems, "jabber:iq:version", "urn:xmpp:delegation:1") |
…nzas - Move parsing and stanza marshalling / unmarshalling to stanza package - Add pattern & basic helpers to simplify stanza building. This was requested on #61
@genofire Several things to note for upgrade:
Other than that, you are not force to use shortcuts and can keep on relying on building the stanza with structs, as before. |
Currently, building a stanza can lead to quite lengthy code, like the following:
I am exploring ways to make the code more compact and more guided through helpers (usable with code completin) with a code like this:
What do you think?
The text was updated successfully, but these errors were encountered: