alexejk / go-xmlrpc

An XML-RPC Client for Go
https://alexejk.io/article/handling-xmlrpc-in-go/
MIT License
19 stars 7 forks source link

Struct field rename with `xmlrpc` tags #68

Closed alexejk closed 2 years ago

alexejk commented 2 years ago

Adding ability to remap XMLRPC struct member names with xmlrpc tags.

XML-RPC specification does not necessarily specify any rules for struct's member names. Some services allow struct member names to include characters not compatible with standard Go field naming.

For example, if a response value is a struct that looks like this:

<struct>
    <member>
        <name>stringValue</name>
        <value><string>bar</string></value>
    </member>
    <member>
        <name>2_numeric.Value</name>
        <value><i4>2</i4></value>
    </member>
</struct>

it would be impossible to map the second value to a Go struct with a field 2_numeric.Value as it's not valid in Go. Instead, we can map it to any valid field as follows:

v := &struct {
    StringValue string
    SecondNumericValue string `xmlrpc:"2_numeric.Value"`
}{}

Fixes #47

codecov[bot] commented 2 years ago

Codecov Report

Merging #68 (d1b60d7) into master (9dea1ed) will increase coverage by 1.16%. The diff coverage is 74.07%.

@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   70.97%   72.14%   +1.16%     
==========================================
  Files           7        7              
  Lines         317      341      +24     
==========================================
+ Hits          225      246      +21     
+ Misses         65       64       -1     
- Partials       27       31       +4     
Impacted Files Coverage Δ
encode.go 66.34% <40.00%> (+1.98%) :arrow_up:
decode.go 73.33% <81.81%> (+1.24%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

89.7% 89.7% Coverage
0.0% 0.0% Duplication