New API
charl opened this issue · 2 comments
A place for us to discuss ideas about improving the API.
@nemith has suggested:
I think i would like an Session.Exec that takes a interface{} that we can type assert. If we are given a string or byte slice then send it raw, if we get an object that can be XML encoded then encode it and send that. If we get something that matches the RPCMethod interface then send that. It would make it all a lot easier.
And:
Yes it's not very well designed and I would like to provide a way to do encoding/decoding as an interface making it even more transparent to get results.
Addressing the performance and allocation concerns in #11 by @nemith: Why not implement a session.Exec
that uses reflection and takes an interface{}
, and implement the more performant methods taking string
or []byte
parameters? This would allow the user of the library to choose which method to use. Benchmarks could be written for each method, and documented in the godoc and/or in the README.md.
Alternatively, we could benchmark the session.Exec
that uses reflection, and if everyone agrees the performance penalty is acceptable, just modify the API accordingly.
I really like the idea of session.Exec(interface{})
, because it would greatly simplify client code. There would have to be a priority on each reflect.Type
though, and it would have to be well documented. Perhaps the netconf.RPCMethod
interface would take first priority, and the fmt.Sringer
interface would take last priority?
Probably netconf.RPCMethod-> xml.Encoder -> string would make since. Calling fmt.Stringer sound like a bad idea after reading this 1+ year later.