Created
April 29, 2019 14:44
-
-
Save ceoro9/652a0fd4f5976be00f9f703bd99c9799 to your computer and use it in GitHub Desktop.
Insert data to big query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"context" | |
"cloud.google.com/go/bigquery" | |
) | |
type Item struct { | |
EventName string | |
PostUUID string | |
} | |
func (i *Item) Save() (map[string]bigquery.Value, string, error) { | |
return map[string]bigquery.Value{ | |
"event_name": i.EventName, | |
"post_uuid": i.PostUUID, | |
}, "", nil | |
} | |
func main() { | |
ctx := context.Background() | |
client, err := bigquery.NewClient(ctx, "project_id") | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
u := client.Dataset("dataset_name").Table("table_name").Uploader() | |
items := []*Item{ | |
{EventName: "START_UPLOADING", PostUUID: "298dd3ed-3834-459e-9299-965243704ff3"}, | |
} | |
if err = u.Put(ctx, items); err != nil { | |
fmt.Println("error") | |
fmt.Println(err) | |
return | |
} | |
fmt.Println("success") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Authentication