()
| 132 | } |
| 133 | |
| 134 | func Example() { |
| 135 | // Connect to a bucket when your program starts up. |
| 136 | // This example uses the file-based implementation in fileblob, and creates |
| 137 | // a temporary directory to use as the root directory. |
| 138 | dir, cleanup := newTempDir() |
| 139 | defer cleanup() |
| 140 | bucket, err := fileblob.OpenBucket(dir, nil) |
| 141 | if err != nil { |
| 142 | log.Fatal(err) |
| 143 | } |
| 144 | defer bucket.Close() |
| 145 | |
| 146 | // We now have a *blob.Bucket! We can write our application using the |
| 147 | // *blob.Bucket type, and have the freedom to change the initialization code |
| 148 | // above to choose a different service-specific driver later. |
| 149 | |
| 150 | // In this example, we'll write a blob and then read it. |
| 151 | ctx := context.Background() |
| 152 | if err := bucket.WriteAll(ctx, "foo.txt", []byte("Go Cloud Development Kit"), nil); err != nil { |
| 153 | log.Fatal(err) |
| 154 | } |
| 155 | b, err := bucket.ReadAll(ctx, "foo.txt") |
| 156 | if err != nil { |
| 157 | log.Fatal(err) |
| 158 | } |
| 159 | fmt.Println(string(b)) |
| 160 | |
| 161 | // Output: |
| 162 | // Go Cloud Development Kit |
| 163 | } |
| 164 | |
| 165 | func ExampleBucket_ErrorAs() { |
| 166 | // This example is specific to the s3blob implementation; it demonstrates |
nothing calls this directly
no test coverage detected