@@ -12,82 +12,86 @@ items:
1212 as described in\n https://cloud.google.com/storage/docs/exponential-backoff. Retrying
1313 continues\n indefinitely unless the controlling context is canceled or the client
1414 is closed. See\n context.WithTimeout and context.WithCancel.</p>\n <h3>Creating
15- a Client</h3>\n <p>To start working with this package, create a client:</p>\n <pre><code>ctx
16- := context.Background()\n client, err := storage.NewClient(ctx)\n if err != nil
17- {\n // TODO: Handle error.\n }\n </code></pre>\n <p>The client will use your default
18- application credentials. Clients should be\n reused instead of created as needed.
19- The methods of Client are safe for\n concurrent use by multiple goroutines.</p>\n <p>If
15+ a Client</h3>\n <p>To start working with this package, create a client:</p>\n <pre><code
16+ class= \" prettyprint \" >ctx := context.Background()\n client, err := storage.NewClient(ctx)\n if
17+ err != nil {\n // TODO: Handle error.\n }\n </code></pre><p>The client will use
18+ your default application credentials. Clients should be\n reused instead of created
19+ as needed. The methods of Client are safe for\n concurrent use by multiple goroutines.</p>\n <p>If
2020 you only wish to access public data, you can create\n an unauthenticated client
21- with</p>\n <pre><code>client, err := storage.NewClient(ctx, option.WithoutAuthentication())\n </code></pre>\n <h3>Buckets</h3>\n <p>A
22- Google Cloud Storage bucket is a collection of objects. To work with a\n bucket,
23- make a bucket handle:</p>\n <pre><code>bkt := client.Bucket(bucketName)\n </code></pre>\n <p>A
21+ with</p>\n <pre><code class=\" prettyprint\" >client, err := storage.NewClient(ctx,
22+ option.WithoutAuthentication())\n </code></pre><h3>Buckets</h3>\n <p>A Google Cloud
23+ Storage bucket is a collection of objects. To work with a\n bucket, make a bucket
24+ handle:</p>\n <pre><code class=\" prettyprint\" >bkt := client.Bucket(bucketName)\n </code></pre><p>A
2425 handle is a reference to a bucket. You can have a handle even if the\n bucket doesn't
25- exist yet. To create a bucket in Google Cloud Storage,\n call Create on the handle:</p>\n <pre><code>if
26- err := bkt.Create(ctx, projectID, nil); err != nil {\n // TODO: Handle error.\n }\n </code></pre>\n <p>Note
27- that although buckets are associated with projects, bucket names are\n global across
28- all projects.</p>\n <p>Each bucket has associated metadata, represented in this
29- package by\n BucketAttrs. The third argument to BucketHandle.Create allows you
30- to set\n the initial BucketAttrs of a bucket. To retrieve a bucket's attributes,
31- use\n Attrs:</p>\n <pre><code>attrs, err := bkt.Attrs(ctx)\n if err != nil {\n //
32- TODO: Handle error.\n }\n fmt.Printf("bucket %s, created at %s, is located
33- in %s with storage class %s\\ n",\n attrs.Name, attrs.Created, attrs.Location,
34- attrs.StorageClass)\n </code></pre>\n <h3>Objects</h3>\n <p>An object holds arbitrary
35- data as a sequence of bytes, like a file. You\n refer to objects using a handle,
36- just as with buckets, but unlike buckets\n you don't explicitly create an object.
37- Instead, the first time you write\n to an object it will be created. You can use
38- the standard Go io.Reader\n and io.Writer interfaces to read and write object data:</p>\n <pre><code>obj
39- := bkt.Object("data")\n // Write something to obj.\n // w implements io.Writer.\n w
40- := obj.NewWriter(ctx)\n // Write some text to obj. This will either create the
41- object or overwrite whatever is there already.\n if _, err := fmt.Fprintf(w, "This
42- object contains text.\\ n"); err != nil {\n // TODO: Handle error.\n }\n //
43- Close, just like writing a file.\n if err := w.Close(); err != nil {\n // TODO:
44- Handle error.\n }\n\n // Read it back.\n r, err := obj.NewReader(ctx)\n if err !=
45- nil {\n // TODO: Handle error.\n }\n defer r.Close()\n if _, err := io.Copy(os.Stdout,
46- r); err != nil {\n // TODO: Handle error.\n }\n // Prints "This object contains
47- text."\n </code></pre>\n <p>Objects also have attributes, which you can fetch
48- with Attrs:</p>\n <pre><code>objAttrs, err := obj.Attrs(ctx)\n if err != nil {\n
49- \ // TODO: Handle error.\n }\n fmt.Printf("object %s has size %d and can
50- be read using %s\\ n",\n objAttrs.Name, objAttrs.Size, objAttrs.MediaLink)\n </code></pre>\n <h3>Listing
51- objects</h3>\n <p>Listing objects in a bucket is done with the Bucket.Objects method:</p>\n <pre><code>query
26+ exist yet. To create a bucket in Google Cloud Storage,\n call Create on the handle:</p>\n <pre><code
27+ class=\" prettyprint\" >if err := bkt.Create(ctx, projectID, nil); err != nil {\n
28+ \ // TODO: Handle error.\n }\n </code></pre><p>Note that although buckets are
29+ associated with projects, bucket names are\n global across all projects.</p>\n <p>Each
30+ bucket has associated metadata, represented in this package by\n BucketAttrs. The
31+ third argument to BucketHandle.Create allows you to set\n the initial BucketAttrs
32+ of a bucket. To retrieve a bucket's attributes, use\n Attrs:</p>\n <pre><code class=\" prettyprint\" >attrs,
33+ err := bkt.Attrs(ctx)\n if err != nil {\n // TODO: Handle error.\n }\n fmt.Printf("bucket
34+ %s, created at %s, is located in %s with storage class %s\\ n",\n attrs.Name,
35+ attrs.Created, attrs.Location, attrs.StorageClass)\n </code></pre><h3>Objects</h3>\n <p>An
36+ object holds arbitrary data as a sequence of bytes, like a file. You\n refer to
37+ objects using a handle, just as with buckets, but unlike buckets\n you don't explicitly
38+ create an object. Instead, the first time you write\n to an object it will be created.
39+ You can use the standard Go io.Reader\n and io.Writer interfaces to read and write
40+ object data:</p>\n <pre><code class=\" prettyprint\" >obj := bkt.Object("data")\n //
41+ Write something to obj.\n // w implements io.Writer.\n w := obj.NewWriter(ctx)\n //
42+ Write some text to obj. This will either create the object or overwrite whatever
43+ is there already.\n if _, err := fmt.Fprintf(w, "This object contains text.\\ n");
44+ err != nil {\n // TODO: Handle error.\n }\n // Close, just like writing a file.\n if
45+ err := w.Close(); err != nil {\n // TODO: Handle error.\n }\n\n // Read it back.\n r,
46+ err := obj.NewReader(ctx)\n if err != nil {\n // TODO: Handle error.\n }\n defer
47+ r.Close()\n if _, err := io.Copy(os.Stdout, r); err != nil {\n // TODO: Handle
48+ error.\n }\n // Prints "This object contains text."\n </code></pre><p>Objects
49+ also have attributes, which you can fetch with Attrs:</p>\n <pre><code class=\" prettyprint\" >objAttrs,
50+ err := obj.Attrs(ctx)\n if err != nil {\n // TODO: Handle error.\n }\n fmt.Printf("object
51+ %s has size %d and can be read using %s\\ n",\n objAttrs.Name, objAttrs.Size,
52+ objAttrs.MediaLink)\n </code></pre><h3>Listing objects</h3>\n <p>Listing objects
53+ in a bucket is done with the Bucket.Objects method:</p>\n <pre><code class=\" prettyprint\" >query
5254 := &storage.Query{Prefix: ""}\n\n var names []string\n it := bkt.Objects(ctx,
5355 query)\n for {\n attrs, err := it.Next()\n if err == iterator.Done {\n break\n
5456 \ }\n if err != nil {\n log.Fatal(err)\n }\n names = append(names,
55- attrs.Name)\n }\n </code></pre>\n <p>If only a subset of object attributes is needed
57+ attrs.Name)\n }\n </code></pre><p>If only a subset of object attributes is needed
5658 when listing, specifying this\n subset using Query.SetAttrSelection may speed up
57- the listing process:</p>\n <pre><code>query := &storage.Query{Prefix: ""}\n query.SetAttrSelection([]string{"Name"})\n\n //
58- ... as before\n </code></pre>\n <h3>ACLs</h3>\n <p>Both objects and buckets have
59- ACLs (Access Control Lists). An ACL is a list of\n ACLRules, each of which specifies
60- the role of a user, group or project. ACLs\n are suitable for fine-grained control,
61- but you may prefer using IAM to control\n access at the project level (see\n https://cloud.google.com/storage/docs/access-control/iam).</p>\n <p>To
62- list the ACLs of a bucket or object, obtain an ACLHandle and call its List method:</p>\n <pre><code>acls,
63- err := obj.ACL().List(ctx)\n if err != nil {\n // TODO: Handle error.\n }\n for
64- _, rule := range acls {\n fmt.Printf("%s has role %s\\ n", rule.Entity,
65- rule.Role)\n }\n </code></pre>\n <p>You can also set and delete ACLs.</p>\n <h3>Conditions</h3>\n <p>Every
66- object has a generation and a metageneration. The generation changes\n whenever
67- the content changes, and the metageneration changes whenever the\n metadata changes.
68- Conditions let you check these values before an operation;\n the operation only
69- executes if the conditions match. You can use conditions to\n prevent race conditions
70- in read-modify-write operations.</p>\n <p>For example, say you've read an object's
71- metadata into objAttrs. Now\n you want to write to that object, but only if its
72- contents haven't changed\n since you read it. Here is how to express that:</p>\n <pre><code>w
59+ the listing process:</p>\n <pre><code class=\" prettyprint\" >query := &storage.Query{Prefix:
60+ ""}\n query.SetAttrSelection([]string{"Name"})\n\n // ... as
61+ before\n </code></pre><h3>ACLs</h3>\n <p>Both objects and buckets have ACLs (Access
62+ Control Lists). An ACL is a list of\n ACLRules, each of which specifies the role
63+ of a user, group or project. ACLs\n are suitable for fine-grained control, but
64+ you may prefer using IAM to control\n access at the project level (see\n https://cloud.google.com/storage/docs/access-control/iam).</p>\n <p>To
65+ list the ACLs of a bucket or object, obtain an ACLHandle and call its List method:</p>\n <pre><code
66+ class=\" prettyprint\" >acls, err := obj.ACL().List(ctx)\n if err != nil {\n //
67+ TODO: Handle error.\n }\n for _, rule := range acls {\n fmt.Printf("%s has
68+ role %s\\ n", rule.Entity, rule.Role)\n }\n </code></pre><p>You can also set
69+ and delete ACLs.</p>\n <h3>Conditions</h3>\n <p>Every object has a generation and
70+ a metageneration. The generation changes\n whenever the content changes, and the
71+ metageneration changes whenever the\n metadata changes. Conditions let you check
72+ these values before an operation;\n the operation only executes if the conditions
73+ match. You can use conditions to\n prevent race conditions in read-modify-write
74+ operations.</p>\n <p>For example, say you've read an object's metadata into objAttrs.
75+ Now\n you want to write to that object, but only if its contents haven't changed\n since
76+ you read it. Here is how to express that:</p>\n <pre><code class=\" prettyprint\" >w
7377 = obj.If(storage.Conditions{GenerationMatch: objAttrs.Generation}).NewWriter(ctx)\n //
74- Proceed with writing as above.\n </code></pre>\n <h3>Signed URLs</h3>\n <p>You can
78+ Proceed with writing as above.\n </code></pre><h3>Signed URLs</h3>\n <p>You can
7579 obtain a URL that lets anyone read or write an object for a limited time.\n You
7680 don't need to create a client to do this. See the documentation of\n SignedURL
77- for details.</p>\n <pre><code>url, err := storage.SignedURL(bucketName, "shared-object" ,
78- opts)\n if err != nil {\n // TODO: Handle error.\n }\n fmt.Println(url)\n </code></pre>\n <h3>Post
81+ for details.</p>\n <pre><code class= \" prettyprint \" >url, err := storage.SignedURL(bucketName,
82+ "shared-object", opts)\n if err != nil {\n // TODO: Handle error.\n }\n fmt.Println(url)\n </code></pre><h3>Post
7983 Policy V4 Signed Request</h3>\n <p>A type of signed request that allows uploads
8084 through HTML forms directly to Cloud Storage with\n temporary permission. Conditions
8185 can be applied to restrict how the HTML form is used and exercised\n by a user.</p>\n <p>For
8286 more information, please see https://cloud.google.com/storage/docs/xml-api/post-object
83- as well\n as the documentation of GenerateSignedPostPolicyV4.</p>\n <pre><code>pv4,
87+ as well\n as the documentation of GenerateSignedPostPolicyV4.</p>\n <pre><code class= \" prettyprint \" >pv4,
8488 err := storage.GenerateSignedPostPolicyV4(bucketName, objectName, opts)\n if err
8589 != nil {\n // TODO: Handle error.\n }\n fmt.Printf("URL: %s\\ nFields; %v\\ n",
86- pv4.URL, pv4.Fields)\n </code></pre>\n <h3>Errors</h3>\n <p>Errors returned by this
90+ pv4.URL, pv4.Fields)\n </code></pre><h3>Errors</h3>\n <p>Errors returned by this
8791 client are often of the type <a href=\" https://godoc.org/google.golang.org/api/googleapi#Error\" ><code>googleapi.Error</code></a>.\n These
8892 errors can be introspected for more information by type asserting to the richer
89- <code>googleapi.Error</code> type. For example:</p>\n <pre><code>if e, ok := err.(*googleapi.Error);
90- ok {\n\t if e.Code == 409 { ... }\n }\n </code></pre>\n "
93+ <code>googleapi.Error</code> type. For example:</p>\n <pre><code class= \" prettyprint \" >if
94+ e, ok := err.(*googleapi.Error); ok {\n\t if e.Code == 409 { ... }\n }\n </code></pre>"
9195 type : package
9296 langs :
9397 - go
0 commit comments