forked from GoogleCloudPlatform/golang-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (33 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// [START storage_quickstart]
// Sample storage-quickstart creates a Google Cloud Storage bucket.
package main
import (
"fmt"
"log"
// Imports the Google Cloud Storage client package.
"cloud.google.com/go/storage"
"golang.org/x/net/context"
)
func main() {
ctx := context.Background()
// Sets your Google Cloud Platform project ID.
projectID := "YOUR_PROJECT_ID"
// Creates a client.
client, err := storage.NewClient(ctx)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// Sets the name for the new bucket.
bucketName := "my-new-bucket"
// Creates a Bucket instance.
bucket := client.Bucket(bucketName)
// Creates the new bucket.
if err := bucket.Create(ctx, projectID, nil); err != nil {
log.Fatalf("Failed to create bucket: %v", err)
}
fmt.Printf("Bucket %v created.\n", bucketName)
}
// [END storage_quickstart]