@@ -41,58 +41,43 @@ The Go SDK includes an S3 storage driver. Follow these steps to set it up:
41411 . Load your AWS configuration and create the S3 storage driver. The driver uses your standard [ AWS credentials] ( https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-gosdk.html ) from the environment (environment variables, IAM role, or AWS config file):
4242
4343 <!--SNIPSTART go-s3-driver-create-- >
44+ [ features/snippets/external_storage/s3_setup/s3_driver_create.go] ( https://github.com/temporalio/features/blob/main/features/snippets/external_storage/s3_setup/s3_driver_create.go )
45+ ``` go
46+ cfg , err := config.LoadDefaultConfig (context.Background (),
47+ config.WithRegion (" us-east-2" ),
48+ )
49+ if err != nil {
50+ log.Fatalf (" load AWS config: %v " , err)
51+ }
4452
45- ``` go
46- import (
47- " github.com/aws/aws-sdk-go-v2/config"
48- " github.com/aws/aws-sdk-go-v2/service/s3"
49- " go.temporal.io/sdk/contrib/aws/s3driver"
50- " go.temporal.io/sdk/contrib/aws/s3driver/awssdkv2"
51- )
52-
53- cfg , err := config.LoadDefaultConfig (context.Background (),
54- config.WithRegion (" us-east-2" ),
55- )
56- if err != nil {
57- log.Fatalf (" load AWS config: %v " , err)
58- }
59-
60- driver , err := s3driver.NewDriver (s3driver.Options {
61- Client : awssdkv2.NewClient (s3.NewFromConfig (cfg)),
62- Bucket : s3driver.StaticBucket (" my-temporal-payloads" ),
63- })
64- if err != nil {
65- log.Fatalf (" create S3 driver: %v " , err)
66- }
67- ```
68-
53+ driver , err := s3driver.NewDriver (s3driver.Options {
54+ Client : awssdkv2.NewClient (s3.NewFromConfig (cfg)),
55+ Bucket : s3driver.StaticBucket (" my-temporal-payloads" ),
56+ })
57+ if err != nil {
58+ log.Fatalf (" create S3 driver: %v " , err)
59+ }
60+ ```
6961 <!--SNIPEND-->
7062
71632. Configure the driver on `ExternalStorage` and pass it in your Client options:
7264
7365 <!--SNIPSTART go-s3-external-storage-setup-- >
66+ [ features/snippets/external_storage/s3_setup/s3_external_storage_setup.go] ( https://github.com/temporalio/features/blob/main/features/snippets/external_storage/s3_setup/s3_external_storage_setup.go )
67+ ``` go
68+ c , err := client.Dial (client.Options {
69+ HostPort : " localhost:7233" ,
70+ ExternalStorage : converter.ExternalStorage {
71+ Drivers: []converter.StorageDriver {driver},
72+ },
73+ })
74+ if err != nil {
75+ log.Fatalf (" connect to Temporal: %v " , err)
76+ }
77+ defer c.Close ()
7478
75- ``` go
76- import (
77- " go.temporal.io/sdk/client"
78- " go.temporal.io/sdk/converter"
79- " go.temporal.io/sdk/worker"
80- )
81-
82- c , err := client.Dial (client.Options {
83- HostPort : " localhost:7233" ,
84- ExternalStorage : converter.ExternalStorage {
85- Drivers: []converter.StorageDriver {driver},
86- },
87- })
88- if err != nil {
89- log.Fatalf (" connect to Temporal: %v " , err)
90- }
91- defer c.Close ()
92-
93- w := worker.New (c, " my-task-queue" , worker.Options {})
94- ```
95-
79+ w := worker.New (c, " my-task-queue" , worker.Options {})
80+ ```
9681 <!--SNIPEND-->
9782
9883 By default, payloads larger than 256 KiB are offloaded to external storage. You can adjust this with the
@@ -112,21 +97,8 @@ The following example shows a custom driver that uses local disk as the backing
11297development and testing only. In production, use a durable storage system that is accessible to all Workers:
11398
11499<!--SNIPSTART go-custom-storage-driver-- >
115-
100+ [ features/snippets/external_storage/custom_driver/custom_storage_driver.go ] ( https://github.com/temporalio/features/blob/main/features/snippets/external_storage/custom_driver/custom_storage_driver.go )
116101``` go
117- package main
118-
119- import (
120- " fmt"
121- " os"
122- " path/filepath"
123-
124- " github.com/google/uuid"
125- commonpb " go.temporal.io/api/common/v1"
126- " go.temporal.io/sdk/converter"
127- " google.golang.org/protobuf/proto"
128- )
129-
130102type LocalDiskStorageDriver struct {
131103 storeDir string
132104}
@@ -204,7 +176,6 @@ func (d *LocalDiskStorageDriver) Retrieve(
204176 return payloads, nil
205177}
206178```
207-
208179<!--SNIPEND-->
209180
210181The following sections walk through the key parts of the driver implementation.
@@ -262,18 +233,15 @@ are offloaded to external storage. You can adjust this with the `PayloadSizeThre
262233externalize all payloads regardless of size. A value of 0 is interpreted as the default (256 KiB).
263234
264235<!--SNIPSTART go-external-storage-threshold-- >
265-
236+ [ features/snippets/external_storage/threshold/threshold_config.go ] ( https://github.com/temporalio/features/blob/main/features/snippets/external_storage/threshold/threshold_config.go )
266237``` go
267- import " go.temporal.io/sdk/converter"
268-
269238c , err := client.Dial (client.Options {
270- ExternalStorage : converter.ExternalStorage {
271- Drivers: []converter.StorageDriver {driver},
272- PayloadSizeThreshold: 1 ,
273- },
239+ ExternalStorage : converter.ExternalStorage {
240+ Drivers: []converter.StorageDriver {driver},
241+ PayloadSizeThreshold: 1 ,
242+ },
274243})
275244```
276-
277245<!--SNIPEND-->
278246
279247## Use multiple storage drivers
@@ -296,29 +264,24 @@ The following example registers two drivers but always selects `preferredDriver`
296264is only registered so the Worker can retrieve payloads that were previously stored with it:
297265
298266<!--SNIPSTART go-external-storage-multiple-drivers-- >
299-
267+ [ features/snippets/external_storage/multiple_drivers/multiple_drivers.go ] ( https://github.com/temporalio/features/blob/main/features/snippets/external_storage/multiple_drivers/multiple_drivers.go )
300268``` go
301- import (
302- commonpb " go.temporal.io/api/common/v1"
303- " go.temporal.io/sdk/converter"
304- )
305-
306269type PreferredSelector struct {
307- preferred converter.StorageDriver
270+ preferred converter.StorageDriver
308271}
309272
310273func (s *PreferredSelector ) SelectDriver (
311- ctx converter.StorageDriverStoreContext,
312- payload *commonpb.Payload,
274+ ctx converter.StorageDriverStoreContext,
275+ payload *commonpb.Payload,
313276) (converter.StorageDriver, error) {
314- return s.preferred , nil
277+ return s.preferred , nil
315278}
316279
317- // Usage:
318- converter.ExternalStorage {
319- Drivers : []converter.StorageDriver {preferredDriver, legacyDriver},
320- DriverSelector : &PreferredSelector{preferred: preferredDriver},
280+ func MultipleDriversSetup (preferredDriver , legacyDriver converter .StorageDriver ) converter .ExternalStorage {
281+ return converter.ExternalStorage {
282+ Drivers: []converter.StorageDriver {preferredDriver, legacyDriver},
283+ DriverSelector: &PreferredSelector{preferred: preferredDriver},
284+ }
321285}
322286```
323-
324287<!--SNIPEND-->
0 commit comments