第一次用go不清楚如何调用这个类 希望各位帮帮忙

hellsam · · 2826 次点击
<a href="/user/polaris" title="@polaris">@polaris</a> 大哥 希望给个代码 万分感谢!
#8
更多评论
```go package client import ( &#34;errors&#34; &#34;fmt&#34; log &#34;github.com/Sirupsen/logrus&#34; &#34;github.com/nilshell/xmlrpc&#34; ) type SinAPIClient struct { Session interface{} Host string Url string Username string Password string RPC *xmlrpc.Client } type APIResult struct { Status string Value interface{} ErrorDescription string } type XenAPIObject struct { Ref string Client *SinAPIClient } func (c *SinAPIClient) RPCCall(result interface{}, method string, params []interface{}) (err error) { log.Debugf(&#34;RPCCall method=%v params=%v\n&#34;, method, params) p := new(xmlrpc.Params) p.Params = params err = c.RPC.Call(method, *p, result) return err } func (client *SinAPIClient) Login() (err error) { //Do loging call result := xmlrpc.Struct{} params := make([]interface{}, 2) params[0] = client.Username params[1] = client.Password err = client.RPCCall(&amp;result, &#34;session.login&#34;, params) if err == nil { // err might not be set properly, so check the reference if result[&#34;Value&#34;] == nil { return errors.New(&#34;Invalid credentials supplied&#34;) } } client.Session = result[&#34;Value&#34;] return err } func (client *SinAPIClient) APICall(result *APIResult, method string, params ...interface{}) (err error) { if client.Session == nil { log.Errorf(&#34;no session\n&#34;) return fmt.Errorf(&#34;No session. Unable to make call&#34;) } //Make a params slice which will include the session p := make([]interface{}, len(params)+1) p[0] = client.Session if params != nil { for idx, element := range params { p[idx+1] = element } } res := xmlrpc.Struct{} err = client.RPCCall(&amp;res, method, p) if err != nil { return err } result.Status = res[&#34;Status&#34;].(string) if result.Status != &#34;Success&#34; { log.Errorf(&#34;Encountered an API error: %v %v&#34;, result.Status, res[&#34;ErrorDescription&#34;]) return fmt.Errorf(&#34;API Error: %s&#34;, res[&#34;ErrorDescription&#34;]) } else { result.Value = res[&#34;Value&#34;] } return } ```
#1
![请把jpg改txt.jpg](https://static.studygolang.com/170902/ff4f9563ec462441527562babdf74391.jpg) 额 发布的代码都乱的 附件发不上来 请下载这个jpg文件 后缀改txt 希望大牛帮帮忙 怎么弄得呢
#2