package json import ( "encoding/json" "sync" ) // ---------------------------------------------------------------------------- // Response // ---------------------------------------------------------------------------- // serverResponse represents a JSON-RPC response returned by the server. type serverResponse struct { // The Object that was returned by the invoked method. This must be null // in case there was an error invoking the method. // As per spec the member will be omitted if there was an error. Result interface{} `json:"result,omitempty"` // An Error object if there was an error invoking the method. It must be // null if there was no error. // As per spec the member will be omitted if there was no error. Error *Error `json:"error,omitempty"` // This must be the same id as the request it is responding to. ID *json.RawMessage `json:"id,omitempty"` } var serverResponsePool sync.Pool func retainServerResponse(result interface{}, err *Error, id *json.RawMessage) *serverResponse { var sr *serverResponse v := serverResponsePool.Get() if v == nil { sr = &serverResponse{} } else { sr = v.(*serverResponse) } sr.Result = result sr.Error = err sr.ID = id return sr } func releaseServerResponse(sr *serverResponse) { sr.Result = nil sr.Error = nil sr.ID = nil serverResponsePool.Put(sr) }