我无法将数据插入到数据存储中。 在第一个请求中,可以调用第三方API并根据需要获取结果以插入数据。
但是它没有将值发送到数据存储。并得到EOF
错误
func CreateProPayAccount(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
kinPropay := &PropayAccount{}
ctx := appengine.NewContext(r)
pro := signuppropay(ctx, r)
if err := json.NewDecoder(r.Body).Decode(kinPropay); err != nil {
log.Println("==>", err) // EOF Error
}
log.Println("==>", pro.Status)
if pro.Status == "00" {
vitalsignsKey := datastore.NewIncompleteKey(ctx, "PropayAccount", nil)
vk, err := datastore.Put(ctx, vitalsignsKey, kinPropay) // in this line kinPropay not constian values
if err != nil {
log.Println("==>", err)
}
log.Println("==>", vk)
}
if err := json.NewEncoder(w).Encode(pro); err != nil {
panic(err)
}
}
func signuppropay(ctx context.Context, r *http.Request) *PropayAccountResonse {
client := urlfetch.Client(ctx)
url := "https://xmltestapi.propay.com/propayapi/signup"
jsonStr, _ := ioutil.ReadAll(r.Body)
req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr))
req.Close = true
data := "********:******"
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
req.Header.Set("Authorization", "Basic "+sEnc)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Println("==>", err)
return nil
}
defer resp.Body.Close()
kinPropayAccountResonse := &PropayAccountResonse{}
if err := json.NewDecoder(resp.Body).Decode(kinPropayAccountResonse); err != nil {
panic(err)
}
return kinPropayAccountResonse
}