package json import "sync" // ---------------------------------------------------------------------------- // Request and Response // ---------------------------------------------------------------------------- // clientRequest represents a JSON-RPC request sent by a client. type clientRequest struct { // JSON-RPC protocol. Version string `json:"jsonrpc"` // 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 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 interface{} `json:"id"` } var clientRequestPool sync.Pool func retainClientRequest(method string, params interface{}, id interface{}) *clientRequest { var cr *clientRequest v := clientRequestPool.Get() if v == nil { cr = &clientRequest{} } else { cr = v.(*clientRequest) } cr.Version = Version cr.Method = method cr.Params = params cr.ID = id return cr } func releaseClientRequest(cr *clientRequest) { cr.Version = "" cr.Method = "" cr.Params = nil cr.ID = nil clientRequestPool.Put(cr) }