Skip to content

Commit

Permalink
Initial commit; add everything
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Aug 10, 2020
0 parents commit 971195d
Show file tree
Hide file tree
Showing 11 changed files with 1,045 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.11.x, 1.12.x, 1.13.x, 1.14.x]
env:
GO111MODULE: "on"
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v ./...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/pipedream/pipedream
/example/example
/pipedream/dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Christian Rocha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
112 changes: 112 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Pipe Dream
==========

<p>
<a href="https://github.com/meowgorithm/pipedream/releases"><img src="https://img.shields.io/github/release/meowgorithm/pipedream.svg" alt="Latest Release"></a>
<a href="https://pkg.go.dev/github.com/meowgorithm/pipedream?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
<a href="https://github.com/meowgorithm/pipedream/actions"><img src="https://github.com/meowgorithm/pipedream/workflows/build/badge.svg" alt="Build Status"></a>
</p>

Easy multipart uploads for Amazon S3, DigitalOcean Spaces and S3-compatible
services. Available as a CLI and Go library.

## CLI

### Install It

Download a build from the [releases][releases] page. macOS, Linux and Windows builds are available for various architectures.

macOS users can also use Homebrew:

```
brew install meowgorithm/homebrew-tap/pipedream
```

Or you can just use `go get`:

```bash
go get github.com/meowgorithm/pipedream/pipedream
```

[releases]: https://github.com/meowgorithm/pipedream/releases

### Usage

```bash
# Set your secrets, region and endpoint in the environment
export ACCESS_KEY="..."
export SECRET_KEY="..."
export ENDPOINT="sfo2.digitaloceanspaces.com" # for AWS set REGION

# Pipe in data or redirect in a file
pipedream --bucket images --path pets/puppy.jpg < puppy.jpg

# Get fancy
export now=$(date +"%Y-%m-%d_%H:%M:%S_%Z")
cat /data/dump.rdb | gzip | pipedream -bucket backups -path dump-$(now).rdb.gz

# For more info
pipedream -h
```

## Library

The library uses an event based model, sending events through a channel.

```go
import "github.com/meowgorithm/pipedream"

// Create a new multipart upload object
m := pipedream.MultipartUpload{
AccessKey: os.Getenv("ACCESS_KEY"),
SecretKey: os.Getenv("SECRET_KEY"),
Endpoint: "sfo2.digitaloceanspaces.com", // you could use Region for AWS
Bucket: "my-fave-bucket",
}

// Get an io.Reader, like an *os.File or os.Stdout
f, err := os.Open("big-redis-dump.rdb")
if err != nil {
fmt.Printf("Rats: %v\n", err)
os.Exit(1)
}
defer f.Close()

// Send up the data. Pipdream returns a channel where you can listen for events
ch := m.Send(f, "backups/dump.rdb")
done := make(chan struct{})

// Listen for activity. For more detailed reporting, see the docs
go func() {
for {
e := <-ch
switch e.(type) {
case pipedream.Complete:
fmt.Println("It worked!")
close(done)
return
case pipedream.Error:
fmt.Println("Rats, it didn't work.")
close(done)
return
}
}
}()

<-done
```

[Full source][example] of this example. For an example with more detailed
reporting, see the source code in the [CLI][cli].

[example]: https://github.com/meowgorithm/pipedream/blob/master/example/main.go
[cli]: https://github.com/meowgorithm/pipedream/tree/master/pipedream

## Awknowledgements

Thanks to to Apoorva Manjunath‘s [S3 multipart upload example](https://github.com/apoorvam/aws-s3-multipart-upload)
for the S3 implementation details.

## License

[MIT](https://github.com/meowgorithm/pipedream/raw/master/LICENSE)
49 changes: 49 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"fmt"
"os"

"github.com/meowgorithm/pipedream"
)

func main() {

m := pipedream.MultipartUpload{
AccessKey: os.Getenv("ACCESS_KEY"),
SecretKey: os.Getenv("SECRET_KEY"),
Endpoint: "sfo2.digitaloceanspaces.com", // you could use Region for AWS
Bucket: "my-fave-bucket",
}

// Get an io.Reader
f, err := os.Open("big-redis-dump.rdb")
if err != nil {
fmt.Printf("Rats: %v\n", err)
os.Exit(1)
}
defer f.Close()

// Send it up! Pipdream returns a channel where you can listen for events.
ch := m.Send(f, "backups/dump.rdb")
done := make(chan struct{})

// Listen for activity. For more detailed reporting, see the docs.
go func() {
for {
e := <-ch
switch e.(type) {
case pipedream.Complete:
fmt.Println("It worked!")
close(done)
return
case pipedream.Error:
fmt.Println("Rats, it didn't work.")
close(done)
return
}
}
}()

<-done
}
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/meowgorithm/pipedream

go 1.14

require (
github.com/aws/aws-sdk-go v1.33.7
github.com/dustin/go-humanize v1.0.0
github.com/meowgorithm/babyenv v1.3.0
github.com/muesli/reflow v0.1.0
github.com/muesli/termenv v0.7.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect
)
Loading

0 comments on commit 971195d

Please sign in to comment.