firestore_delete.go
// ---------------------------------------------------------------
//
// firestore_delete.go
//
// Dec/16/2020
//
// ---------------------------------------------------------------
package main
import (
"context"
"fmt"
"log"
"os"
firebase "firebase.google.com/go"
"google.golang.org/api/option"
)
// ---------------------------------------------------------------
func main() {
fmt.Fprintf (os.Stderr,"*** 開始 ***\n")
key_in := os.Args[1]
fmt.Printf ("key_in = %s\n" , key_in)
// 初期化
ctx := context.Background()
sa := option.WithCredentialsFile("./application_default_credentials.json")
app, err := firebase.NewApp(ctx, nil, sa)
if err != nil {
log.Fatalln(err)
}
client, err := app.Firestore(ctx)
if err != nil {
log.Fatalln(err)
}
_, err = client.Collection("cities").Doc(key_in).Delete(ctx)
if err != nil {
// Handle any errors in an appropriate way, such as returning them.
log.Printf("An error has occurred: %s", err)
}
// 切断
defer client.Close()
fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}
// ---------------------------------------------------------------
実行コマンド
project_id="project-dec16-2020"
echo $project_id
export GOOGLE_CLOUD_PROJECT=$project_id
#
go run firestore_delete.go t0923