本文整理汇总了Golang中github.com/gorilla/rpc/v2/json.DecodeClientResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeClientResponse函数的具体用法?Golang DecodeClientResponse怎么用?Golang DecodeClientResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeClientResponse函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetAuthKeys
// GetAuthKeys get access key id and secret access key
func GetAuthKeys(url string) ([]byte, error) {
op := RPCOps{
Method: "Auth.Get",
Request: rpc.Args{Request: ""},
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return nil, iodine.New(err, nil)
}
var reply rpc.AuthReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
}
authConfig := &auth.Config{}
authConfig.Version = "0.0.1"
authConfig.Users = make(map[string]*auth.User)
user := &auth.User{}
user.Name = "testuser"
user.AccessKeyID = reply.AccessKeyID
user.SecretAccessKey = reply.SecretAccessKey
authConfig.Users[reply.AccessKeyID] = user
if err := auth.SaveConfig(authConfig); err != nil {
return nil, iodine.New(err, nil)
}
return json.MarshalIndent(reply, "", "\t")
}
开发者ID:flandr,项目名称:minio,代码行数:32,代码来源:client.go
示例2: SetDonut
// SetDonut - set donut config
func SetDonut(url, hostname string, disks []string) error {
op := RPCOps{
Method: "Donut.Set",
Request: rpc.DonutArgs{
Hostname: hostname,
Disks: disks,
Name: "default",
MaxSize: 512000000,
},
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return iodine.New(err, nil)
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return iodine.New(err, nil)
}
var reply rpc.Reply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return iodine.New(err, nil)
}
return reply.Error
}
开发者ID:flandr,项目名称:minio,代码行数:26,代码来源:client.go
示例3: proxyRequest
func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error {
u := &url.URL{}
if ssl {
u.Scheme = "https"
} else {
u.Scheme = "http"
}
u.Host = host
if _, _, err := net.SplitHostPort(host); err == nil {
u.Host = host
} else {
u.Host = host + ":9002"
}
u.Path = "/rpc"
op := rpcOperation{
Method: method,
Request: ServerArg{},
}
request, err := newRPCRequest(u.String(), op, nil)
if err != nil {
return err.Trace()
}
var resp *http.Response
resp, err = request.Do()
if err != nil {
return err.Trace()
}
if err := json.DecodeClientResponse(resp.Body, res); err != nil {
return probe.NewError(err)
}
return nil
}
开发者ID:solderzzc,项目名称:minio,代码行数:33,代码来源:controller-rpc.go
示例4: Do
// Do holds a JSON-RPC request.
func Do(url, method string, args *openstack.Args) error {
message, err := json.EncodeClientRequest(method, args)
checkErr(err)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(message))
checkErr(err)
req.Header.Set("Content-Type", "application/json")
client := new(http.Client)
resp, err := client.Do(req)
if err != nil {
log.Printf("Error in sending request to %s. %s", url, err)
return err
}
defer resp.Body.Close()
err = json.DecodeClientResponse(resp.Body, &result)
if err != nil {
log.Printf("Couldn't decode response. %s", err)
return err
}
log.Printf("url: %s, method: %s, args: %s", url, method, args)
return nil
}
开发者ID:zhangxuekun,项目名称:fastforward,代码行数:26,代码来源:client.go
示例5: proxyRequest
func proxyRequest(method, host string, ssl bool, res interface{}) *probe.Error {
u := &url.URL{
Scheme: func() string {
if ssl {
return "https"
}
return "http"
}(),
Host: host,
Path: "/rpc",
}
op := rpcOperation{
Method: method,
Request: ServerArg{},
}
request, err := newRPCRequest(u.String(), op, nil)
if err != nil {
return err.Trace()
}
var resp *http.Response
resp, err = request.Do()
if err != nil {
return err.Trace()
}
if err := json.DecodeClientResponse(resp.Body, res); err != nil {
return probe.NewError(err)
}
return nil
}
开发者ID:StorageTW,项目名称:minio,代码行数:29,代码来源:controller-rpc.go
示例6: Execute
func (rc *RpcClient) Execute(method string, req, res interface{}) error {
buf, _ := json.EncodeClientRequest(method, req)
body := bytes.NewBuffer(buf)
log.Println(body)
httpreq, _ := http.NewRequest("POST", rc.Address, body)
httpreq.Header.Set("Content-Type", "application/json")
response, err := rc.Httpclient.Do(httpreq)
if err != nil {
return err
}
return json.DecodeClientResponse(response.Body, res)
}
开发者ID:souche-open,项目名称:smoni,代码行数:12,代码来源:rpcclient.go
示例7: TestDiskStats
func (s *ControllerRPCSuite) TestDiskStats(c *C) {
op := rpcOperation{
Method: "Controller.GetServerDiskStats",
Request: ControllerArgs{Hosts: []string{s.url.Host}},
}
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var reply MemStatsRep
c.Assert(json.DecodeClientResponse(resp.Body, &reply), IsNil)
resp.Body.Close()
c.Assert(reply, Not(DeepEquals), DiskStatsRep{})
}
开发者ID:StorageTW,项目名称:minio,代码行数:17,代码来源:controller_rpc_test.go
示例8: TestServerAdd
func (s *ControllerRPCSuite) TestServerAdd(c *C) {
op := rpcOperation{
Method: "Controller.AddServer",
Request: ControllerArgs{Host: s.url.Host},
}
req, err := newRPCRequest(s.config, testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var reply DefaultRep
c.Assert(json.DecodeClientResponse(resp.Body, &reply), IsNil)
resp.Body.Close()
c.Assert(reply, Not(DeepEquals), DefaultRep{nil, "Added"})
}
开发者ID:fwessels,项目名称:minio-xl,代码行数:17,代码来源:controller_rpc_test.go
示例9: TestSysInfo
func (s *MyRPCSuite) TestSysInfo(c *C) {
op := controller.RPCOps{
Method: "SysInfo.Get",
Request: rpc.Args{Request: ""},
}
req, err := controller.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var reply rpc.SysInfoReply
c.Assert(jsonrpc.DecodeClientResponse(resp.Body, &reply), IsNil)
resp.Body.Close()
c.Assert(reply, Not(DeepEquals), rpc.SysInfoReply{})
}
开发者ID:theanalyst,项目名称:minio,代码行数:17,代码来源:rpc_test.go
示例10: TestAuth
func (s *MySuite) TestAuth(c *C) {
op := rpc.Operation{
Method: "Auth.Get",
Request: rpc.Args{Request: ""},
}
req, err := rpc.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var reply rpc.AuthReply
c.Assert(jsonrpc.DecodeClientResponse(resp.Body, &reply), IsNil)
resp.Body.Close()
c.Assert(reply, Not(DeepEquals), rpc.AuthReply{})
c.Assert(len(reply.AccessKeyID), Equals, 20)
c.Assert(len(reply.SecretAccessKey), Equals, 40)
}
开发者ID:kahing,项目名称:minio,代码行数:19,代码来源:rpc_test.go
示例11: GetSysInfo
// GetSysInfo get system status of the server at given url
func GetSysInfo(url string) ([]byte, error) {
op := RPCOps{
Method: "SysInfo.Get",
Request: rpc.Args{Request: ""},
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return nil, iodine.New(err, nil)
}
var reply rpc.SysInfoReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
}
return json.MarshalIndent(reply, "", "\t")
}
开发者ID:flandr,项目名称:minio,代码行数:21,代码来源:client.go
示例12: GetDisks
// GetDisks get disks info of the server at given url
func GetDisks(url string) ([]string, error) {
op := RPCOps{
Method: "DiskInfo.Get",
Request: rpc.Args{Request: ""},
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
}
resp, err := req.Do()
if err != nil {
return nil, iodine.New(err, nil)
}
defer resp.Body.Close()
var reply rpc.DiskInfoReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
}
return reply.Disks, nil
}
开发者ID:bosky101,项目名称:minio,代码行数:21,代码来源:client.go
示例13: GetMemStats
// GetMemStats get memory status of the server at given url
func GetMemStats(url string) ([]byte, *probe.Error) {
op := RPCOps{
Method: "MemStats.Get",
Request: rpc.Args{Request: ""},
}
req, perr := NewRequest(url, op, http.DefaultTransport)
if perr != nil {
return nil, perr.Trace()
}
resp, perr := req.Do()
defer closeResp(resp)
if perr != nil {
return nil, perr.Trace()
}
var reply rpc.MemStatsReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, probe.NewError(err)
}
jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
if err != nil {
return nil, probe.NewError(err)
}
return jsonRespBytes, nil
}
开发者ID:theanalyst,项目名称:minio,代码行数:25,代码来源:client.go
示例14: TestAuth
func (s *ControllerRPCSuite) TestAuth(c *C) {
op := rpcOperation{
Method: "Controller.GenerateAuth",
Request: AuthArgs{User: "newuser"},
}
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err := req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var reply AuthRep
c.Assert(json.DecodeClientResponse(resp.Body, &reply), IsNil)
resp.Body.Close()
c.Assert(reply, Not(DeepEquals), AuthRep{})
c.Assert(len(reply.AccessKeyID), Equals, 20)
c.Assert(len(reply.SecretAccessKey), Equals, 40)
c.Assert(len(reply.Name), Not(Equals), 0)
op = rpcOperation{
Method: "Controller.FetchAuth",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var newReply AuthRep
c.Assert(json.DecodeClientResponse(resp.Body, &newReply), IsNil)
resp.Body.Close()
c.Assert(newReply, Not(DeepEquals), AuthRep{})
c.Assert(reply.AccessKeyID, Equals, newReply.AccessKeyID)
c.Assert(reply.SecretAccessKey, Equals, newReply.SecretAccessKey)
c.Assert(len(reply.Name), Not(Equals), 0)
op = rpcOperation{
Method: "Controller.ResetAuth",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
var resetReply AuthRep
c.Assert(json.DecodeClientResponse(resp.Body, &resetReply), IsNil)
resp.Body.Close()
c.Assert(newReply, Not(DeepEquals), AuthRep{})
c.Assert(reply.AccessKeyID, Not(Equals), resetReply.AccessKeyID)
c.Assert(reply.SecretAccessKey, Not(Equals), resetReply.SecretAccessKey)
c.Assert(len(reply.Name), Not(Equals), 0)
// these operations should fail
/// generating access for existing user fails
op = rpcOperation{
Method: "Controller.GenerateAuth",
Request: AuthArgs{User: "newuser"},
}
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusBadRequest)
/// null user provided invalid
op = rpcOperation{
Method: "Controller.GenerateAuth",
Request: AuthArgs{User: ""},
}
req, err = newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusBadRequest)
}
开发者ID:StorageTW,项目名称:minio,代码行数:84,代码来源:controller_rpc_test.go
注:本文中的github.com/gorilla/rpc/v2/json.DecodeClientResponse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论