I call a function to execute an http request, two pass by reference parameters are used for this function. I pass the [] byte to v interface. I want a function to update the v reference value of an interface. The response body is a string, I want to pass a string value to the v-interface. However, I tried many ways, but did not succeed.
Here is the code, you can see that I declare byts as v.(*[]byte) to make v updated string value of the response body. But that does not work. v always nil . Please suggest any way to make v can be updated with a string value.
func (s *BackendConfiguration) Do(req *http.Request, v interface{}) error { res, err := s.HTTPClient.Do(req) defer res.Body.Close() resBody, err := ioutil.ReadAll(res.Body) if v != nil { byts, ok := v.(*[]byte) if len(resBody) > 0 { byts = append(byts, resBody...) return nil } } } return nil }
source share