go
1type Profile struct { 2 name string 3 age string 4 country string 5} 6 7func main() { 8 jsonKey := "" 9 ctx := context.Background() 10 client, err := datastore.NewClient(ctx, "", option.WithCredentialsFile(jsonKey)) 11 if err != nil { 12 log.Printf("Failed to create client:%v/n", err) 13 } 14 sha256 := sha256.Sum256([]byte(time.Now().String())) 15 name := fmt.Sprintf("'%x'", sha256) 16 key := datastore.NameKey("Profile", name, nil) 17 18 profile := Profile{ 19 name: "tanaka", 20 age: 50, 21 country: "Japan" 22 } 23 key, err = client.Put(ctx, key, &manageJobs) 24 fmt.Printf("%+v\n", key) 25 if err != nil { 26 log.Printf("Failed to put entity:%v\n", err) 27 } else { 28 fmt.Printf("Success\n") 29 }
datastoreにエンティティを新しく追加する旨のプログラムになります。
実行時にエラーもなく終了するのですがwebでdatastoreを確認すると登録されていません。
NameKey()の前にIncompleteKey()を試したのですがこちらでは成功いたしました。
keyの内容を確認したところ
/Profile,現在時間のハッシュ値となっていましたのでkeyは正しく作られているとは思うのですが...
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。