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

hellsam · · 2820 次点击
代码都是乱的 重新打包的 发到百度盘了。下载地址 https://pan.baidu.com/s/1o8gG2tO 提取密码 bjr3
#3
更多评论
```go package client import ( "errors" "fmt" log "github.com/Sirupsen/logrus" "github.com/nilshell/xmlrpc" ) 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("RPCCall method=%v params=%v\n", 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(&result, "session.login", params) if err == nil { // err might not be set properly, so check the reference if result["Value"] == nil { return errors.New("Invalid credentials supplied") } } client.Session = result["Value"] return err } func (client *SinAPIClient) APICall(result *APIResult, method string, params ...interface{}) (err error) { if client.Session == nil { log.Errorf("no session\n") return fmt.Errorf("No session. Unable to make call") } //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(&res, method, p) if err != nil { return err } result.Status = res["Status"].(string) if result.Status != "Success" { log.Errorf("Encountered an API error: %v %v", result.Status, res["ErrorDescription"]) return fmt.Errorf("API Error: %s", res["ErrorDescription"]) } else { result.Value = res["Value"] } return } ```
#1
![请把jpg改txt.jpg](https://static.studygolang.com/170902/ff4f9563ec462441527562babdf74391.jpg) 额 发布的代码都乱的 附件发不上来 请下载这个jpg文件 后缀改txt 希望大牛帮帮忙 怎么弄得呢
#2