-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for GCP Storage connector
- Loading branch information
Showing
10 changed files
with
656 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/storage/storage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"data": "test" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"cloud.google.com/go/storage" | ||
"github.com/reugn/go-streams/flow" | ||
connector "github.com/reugn/go-streams/gcp" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
// docker run --rm --name fake-gcs-server -p 4443:4443 -v ${PWD}/data:/data \ | ||
// fsouza/fake-gcs-server -scheme http | ||
|
||
// curl http://0.0.0.0:4443/storage/v1/b | ||
// curl http://0.0.0.0:4443/storage/v1/b/test-bucket/o | ||
func main() { | ||
ctx := context.Background() | ||
client, err := storage.NewClient( | ||
ctx, | ||
option.WithEndpoint("http://localhost:4443/storage/v1/"), | ||
option.WithoutAuthentication(), | ||
storage.WithJSONReads(), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
sourceConfig := &connector.StorageSourceConfig{ | ||
Bucket: "test-bucket", | ||
// Prefix: "source", | ||
} | ||
source := connector.NewStorageSource(ctx, client, sourceConfig, nil) | ||
|
||
mapObjects := flow.NewMap(transform, 1) | ||
|
||
sinkConfig := &connector.StorageSinkConfig{ | ||
Bucket: "test-bucket", | ||
} | ||
sink := connector.NewStorageSink(ctx, client, sinkConfig, nil) | ||
|
||
source. | ||
Via(mapObjects). | ||
To(sink) | ||
|
||
time.Sleep(time.Second) | ||
} | ||
|
||
var transform = func(object *connector.StorageObject) *connector.StorageObject { | ||
object.Key = fmt.Sprintf("sink/%s", object.Key) | ||
return object | ||
} |
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
Oops, something went wrong.