mirror of
https://github.com/minio/minio.git
synced 2025-01-03 19:13:22 -05:00
61175ef091
- over the course of a project history every maintainer needs to update its dependency packages, the problem essentially with godep is manipulating GOPATH - this manipulation leads to static objects created at different locations which end up conflicting with the overall functionality of golang. This also leads to broken builds. There is no easier way out of this other than asking developers to do 'godep restore' all the time. Which perhaps as a practice doesn't sound like a clean solution. On the other hand 'godep restore' has its own set of problems. - govendor is a right tool but a stop gap tool until we wait for golangs official 1.5 version which fixes this vendoring issue once and for all. - govendor provides consistency in terms of how import paths should be handled unlike manipulation GOPATH. This has advantages - no more compiled objects being referenced in GOPATH and build time GOPATH manging which leads to conflicts. - proper import paths referencing the exact package a project is dependent on. govendor is simple and provides the minimal necessary tooling to achieve this. For now this is the right solution.
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Copyright 2012-2013 The Gorilla Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package json
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"math/rand"
|
|
)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Request and Response
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// clientRequest represents a JSON-RPC request sent by a client.
|
|
type clientRequest struct {
|
|
// A String containing the name of the method to be invoked.
|
|
Method string `json:"method"`
|
|
// Object to pass as request parameter to the method.
|
|
Params [1]interface{} `json:"params"`
|
|
// The request id. This can be of any type. It is used to match the
|
|
// response with the request that it is replying to.
|
|
Id uint64 `json:"id"`
|
|
}
|
|
|
|
// clientResponse represents a JSON-RPC response returned to a client.
|
|
type clientResponse struct {
|
|
Result *json.RawMessage `json:"result"`
|
|
Error interface{} `json:"error"`
|
|
Id uint64 `json:"id"`
|
|
}
|
|
|
|
// EncodeClientRequest encodes parameters for a JSON-RPC client request.
|
|
func EncodeClientRequest(method string, args interface{}) ([]byte, error) {
|
|
c := &clientRequest{
|
|
Method: method,
|
|
Params: [1]interface{}{args},
|
|
Id: uint64(rand.Int63()),
|
|
}
|
|
return json.Marshal(c)
|
|
}
|
|
|
|
// DecodeClientResponse decodes the response body of a client request into
|
|
// the interface reply.
|
|
func DecodeClientResponse(r io.Reader, reply interface{}) error {
|
|
var c clientResponse
|
|
if err := json.NewDecoder(r).Decode(&c); err != nil {
|
|
return err
|
|
}
|
|
if c.Error != nil {
|
|
return &Error{Data: c.Error}
|
|
}
|
|
if c.Result == nil {
|
|
return fmt.Errorf("Unexpected null result")
|
|
}
|
|
return json.Unmarshal(*c.Result, reply)
|
|
}
|