-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[ADD] rpc: Go examples #5064
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
[ADD] rpc: Go examples #5064
Conversation
The code examples in Go have been added in the same places as existing examples for other programming languages. All Go examples are based on existing examples, but respecting the specificities of the Go language. All examples have been tested with a local installation of odoo v16 and work fine, except the odoo test database which always returns an error. The Go code for testing can be found here: https://gist.github.com/mrhdias/f58106caa1e148c925cbe0b24635ef75
The RST text formatting errors have been fixed
The last issue with text formatting has been fixed.
xmo-odoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the printing needs to be removed.
The treatment of return values is also inconsistent between maps and structs, it's not clear why e.g. recordFields in the last snippet is a []map[string][any] while in the second to last it's gets a map[string][struct{...}]. Or while the last one exists at all when no other snippet actually names that value.
| json, err := json.MarshalIndent(common, "", " ") | ||
| if err != nil { | ||
| log.Fatalln(err) | ||
| } | ||
| fmt.Println(string(json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON output is indicative, no other client actually generates it. Remove output formatting in all snippets, it's an unnecessary waste of space.
Not to mention this doesn't format the structures to match the printed output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| if err := models.Close(); err != nil { | ||
| log.Fatalln(err) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the models client gets closed, then we keep using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
The requested changes have been made: All json output formatting has been removed in all snippets; The client is no longer closed; No more output of results in all snippets.
|
The treatment of return values is not inconsistent. If we know what is returned we use a structure, if we don't know we use an interface{} which is the same as using the "any" expression. But if you wish, I can pass everything to interface{}. |
We know what e.g. |
All go examples have been simplified. No more outputs in all go examples (including error output). Inconsistency between maps and structures has been eliminated.
A small typo in the authentication example has been fixed. Array replacement by map.
|
I think the examples are ok now. Check the latest revision. The Go examples closely follow the Java examples. |
One more correction. The constants url, db, username and password were replaced by variables, so that they can be assigned with new values.
|
@robodoo delegate=xmo-odoo |
The error handling was fine by me (most other languages would trigger exceptions on server-side error so the errors didn't need to he handled explicitely), I'm fine with approving as-is, or with adding the error checking stuff back in, as you prefer. |
Now errors can be checked immediately before proceeding to the next steps.
Thanks. I've added error checking again, so it's much clearer for developers to check for errors in each example. I followed this example from the go playground for errors. |
xmo-odoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robodoo r+
|
@robodoo squash |
|
Merge method set to squash. |
Examples rely on `kolo/xmlrpc` as well as on the standard library package `log` to panic on error, matching snippets in other languages (which tend to raise exceptions). As with other languages, only the RPC interaction is spelled out. closes #5128 Forward-port-of: #5064 Signed-off-by: Xavier Morel (xmo) <[email protected]>
Examples rely on `kolo/xmlrpc` as well as on the standard library package `log` to panic on error, matching snippets in other languages (which tend to raise exceptions). As with other languages, only the RPC interaction is spelled out. closes #5126 Forward-port-of: #5064 Signed-off-by: Xavier Morel (xmo) <[email protected]>
Examples rely on `kolo/xmlrpc` as well as on the standard library package `log` to panic on error, matching snippets in other languages (which tend to raise exceptions). As with other languages, only the RPC interaction is spelled out. closes #5127 Forward-port-of: #5064 Signed-off-by: Xavier Morel (xmo) <[email protected]>
Examples rely on `kolo/xmlrpc` as well as on the standard library package `log` to panic on error, matching snippets in other languages (which tend to raise exceptions). As with other languages, only the RPC interaction is spelled out. closes #5129 Forward-port-of: #5064 Signed-off-by: Xavier Morel (xmo) <[email protected]>
Examples rely on
kolo/xmlrpcas well as on the standard library packagelogto panic on error, matching snippets in other languages (which tend to raise exceptions).As with other languages, only the RPC interaction is spelled out.