From 9391139d8c337aa6d82a3b8c972275f55dc0d3b7 Mon Sep 17 00:00:00 2001 From: Ben Olive Date: Sun, 27 Dec 2009 23:13:07 -0500 Subject: [PATCH] Added Base Params functionality Currently only at beginning of args list. --- xmlrpc/http.go | 16 +++++++++++++++- xmlrpc/param.go | 5 +++++ xmlrpc/request.go | 5 +++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/xmlrpc/http.go b/xmlrpc/http.go index 84d44e4..a979977 100644 --- a/xmlrpc/http.go +++ b/xmlrpc/http.go @@ -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 diff --git a/xmlrpc/param.go b/xmlrpc/param.go index fe47b83..63544e7 100644 --- a/xmlrpc/param.go +++ b/xmlrpc/param.go @@ -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++ { diff --git a/xmlrpc/request.go b/xmlrpc/request.go index 30957a9..e786a25 100644 --- a/xmlrpc/request.go +++ b/xmlrpc/request.go @@ -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