Created
March 3, 2013 12:37
-
-
Save RadioactiveMouse/5075952 to your computer and use it in GitHub Desktop.
Golang Reference issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (self *Client) Store(bucket string, returnBody bool, data *Data) (*Data, error) { | |
// check if the key exists for conditional put/post | |
path := "" | |
returnData := Data{} | |
resp := http.Response{} | |
// check if the key exists | |
if data.value == "" { | |
return &returnData, errors.New("RGO: no value defined for the key") | |
} | |
if data.key != "" { | |
// put | |
path = fmt.Sprintf("/buckets/%s/keys/%s",bucket,data.key) | |
if returnBody { | |
path = path + "?returnbody=true" | |
} | |
values := url.Values{data.key:{data.value}} | |
err := self.query("PUT",path,values,&resp) | |
if err != nil { | |
return &returnData, err | |
} | |
} else { | |
//post | |
path = fmt.Sprintf("/buckets/%s/keys",bucket) | |
if returnBody { | |
path = path + "?returnbody=true" | |
} | |
values := url.Values{"":{data.value}} | |
err := self.query("POST",path,values,&resp) | |
if err != nil { | |
return &returnData, err | |
} | |
} | |
func (self *Client) query(method string, path string, values url.Values, r *http.Response) (error) { | |
// construct the base URL | |
riakurl := fmt.Sprintf("%s:%d",self.Address,self.Port) | |
endpoint, err := url.Parse(riakurl) | |
if err != nil { | |
return err | |
} | |
endpoint.Path = path | |
if method == "GET" { | |
endpoint.RawQuery = values.Encode() | |
} | |
var body io.Reader | |
if method != "GET" && values != nil { | |
body = strings.NewReader(values.Encode()) | |
} | |
if self.Log { | |
fmt.Println("R before mod : ", r) | |
fmt.Println("RGO :", method, endpoint.String()) | |
fmt.Println(values.Encode()) | |
} | |
request, err := http.NewRequest(method, endpoint.String(), body) | |
if err != nil { | |
return err | |
} | |
response, err := http.DefaultClient.Do(request) | |
r = response | |
if self.Log { | |
fmt.Println("RESPONSE : ", response) | |
fmt.Println("R : ", r) | |
} |
Line 63.
You want:
*r = *response
Since you want to copy the value from the location pointed to by the return from Do() to the location pointed by r.
Thanks, that was it. Must have tried every other permutation but that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically once I get the response at the bottom I try to set "r" so that I can use it as "resp" but it remains an empty response despite the print statements to the contrary at the bottom which print fine.