當前位置: 首頁>>代碼示例>>Golang>>正文


Golang json.DecodeClientResponse函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。