Skip to content
Permalink
Browse files
Introduce a way to have specific key/value names
This is an alternative solution for PR #47.

By using this approach we don’t have to make any changes to the raw
output generated by the `listApis` API call (which is saved in the
`v43.go` and `v44.go` files).

So when we now want to generate code based on a new version, we only
have to paste the output of the `listApis` call info a new `vxx.go`
file and were good to go, without having to manually alter the file.

Next to all that’ it simple feels a little cleaner and more robust
😉
  • Loading branch information
Sander van Harmelen committed Jan 29, 2016
1 parent 9181d8f commit cdef7bd076b4b719755ff2475b7d78d6b2b7f421
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
@@ -91,8 +91,8 @@ func (p *CreateNetworkOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -1350,8 +1350,8 @@ func (p *CreateVPCOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -91,8 +91,8 @@ func (p *CreateNetworkOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -1276,8 +1276,8 @@ func (p *CreateVPCOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -91,8 +91,8 @@ func (p *CreateNetworkOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -1350,8 +1350,8 @@ func (p *CreateVPCOfferingParams) toURLValues() url.Values {
if v, found := p.p["serviceproviderlist"]; found {
i := 0
for k, vv := range v.(map[string]string) {
u.Set(fmt.Sprintf("serviceproviderlist[%d].key", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].value", i), vv)
u.Set(fmt.Sprintf("serviceproviderlist[%d].service", i), k)
u.Set(fmt.Sprintf("serviceproviderlist[%d].provider", i), vv)
i++
}
}
@@ -600,8 +600,14 @@ func (s *service) generateConvertCode(name, typ string) {
case "map[string]string":
pn("i := 0")
pn("for k, vv := range v.(map[string]string) {")
pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", n)
pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), vv)", n)
switch name {
case "serviceproviderlist":
pn(" u.Set(fmt.Sprintf(\"%s[%%d].service\", i), k)", n)
pn(" u.Set(fmt.Sprintf(\"%s[%%d].provider\", i), vv)", n)
default:
pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", n)
pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), vv)", n)
}
pn(" i++")
pn("}")
}
@@ -966,7 +972,8 @@ func (s *service) generateNewAPICallFunc(a *API) {
pn(" return nil, err")
pn(" }")
pn("")
if n == "CreateNetwork" || n == "CreateServiceOffering" || n == "CreateSSHKeyPair" || n == "RegisterSSHKeyPair" {
switch n {
case "CreateNetwork", "CreateServiceOffering", "CreateSSHKeyPair", "RegisterSSHKeyPair":
pn(" if resp, err = getRawValue(resp); err != nil {")
pn(" return nil, err")
pn(" }")

0 comments on commit cdef7bd

Please sign in to comment.