I have a function for decode http response json to a struct.And I have two types of structs needed to pass to this function, and have the type of struct as return value to get the decoded json.
My function now can deal with ONE type, need help to make it can handle different type of struct, and return the struct.
// Response json
type responseResult struct {
result string
}
type loginResult struct {
responseResult
token string
}
func responseBodyDecoder(resp http.Response,response *responseResult) {
// get result form Response
decoder := json.NewDecoder(resp.Body)
decode_err := decoder.Decode(&response)
if decode_err != nil {
panic(decode_err)
}
}