Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Commit

Permalink
Added Base Params functionality
Browse files Browse the repository at this point in the history
Currently only at beginning of args list.
  • Loading branch information
sionide21 committed Dec 28, 2009
1 parent fe27fbc commit 9391139
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 15 additions & 1 deletion xmlrpc/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ import (
// xmlrpc.Fault.
func (r RemoteMethod) Call(args ...) (ParamValue, os.Error) {
body := new(bytes.Buffer)
r.SendXML(body, Params(args))
if r.BaseParams != nil {
p := make([]ParamValue, len(r.BaseParams)+argLength(args))
i := 0
for _, v := range r.BaseParams {
p[i] = v
i++
}
for _, v := range Params(args) {
p[i] = v
i++
}
r.SendXML(body, p)
} else {
r.SendXML(body, Params(args))
}
resp, err := http.Post(r.Endpoint, "text/xml", body)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions xmlrpc/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func Params(params ...) []ParamValue {
return par
}

func argLength(args ...) int {
pStruct := reflect.NewValue(args).(*reflect.StructValue)
return pStruct.NumField()
}

func structParams(v *reflect.StructValue) StructValue {
p := make(StructValue, v.NumField())
for n := 0; n < v.NumField(); n++ {
Expand Down
5 changes: 3 additions & 2 deletions xmlrpc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
// The remote method to call. Endpoint is the URL of the endpoint
// Method is the name of the method to call.
type RemoteMethod struct {
Endpoint string
Method string
Endpoint string
Method string
BaseParams []ParamValue
}

// This methods writes the xml representation of the request
Expand Down

0 comments on commit 9391139

Please sign in to comment.