Skip to content

Commit 971195d

Browse files
committed
Initial commit; add everything
0 parents  commit 971195d

File tree

11 files changed

+1045
-0
lines changed

11 files changed

+1045
-0
lines changed

.github/workflows/go.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
build:
12+
name: Build
13+
runs-on: ${{ matrix.platform }}
14+
strategy:
15+
matrix:
16+
platform: [ubuntu-latest, macos-latest, windows-latest]
17+
go-version: [1.11.x, 1.12.x, 1.13.x, 1.14.x]
18+
env:
19+
GO111MODULE: "on"
20+
steps:
21+
22+
- name: Set up Go 1.x
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: ${{ matrix.go-version }}
26+
id: go
27+
28+
- name: Check out code into the Go module directory
29+
uses: actions/checkout@v2
30+
31+
- name: Get dependencies
32+
run: |
33+
go get -v -t -d ./...
34+
35+
- name: Build
36+
run: go build -v ./...

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/pipedream/pipedream
2+
/example/example
3+
/pipedream/dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Christian Rocha
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Pipe Dream
2+
==========
3+
4+
<p>
5+
<a href="https://github.com/meowgorithm/pipedream/releases"><img src="https://img.shields.io/github/release/meowgorithm/pipedream.svg" alt="Latest Release"></a>
6+
<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>
7+
<a href="https://github.com/meowgorithm/pipedream/actions"><img src="https://github.com/meowgorithm/pipedream/workflows/build/badge.svg" alt="Build Status"></a>
8+
</p>
9+
10+
Easy multipart uploads for Amazon S3, DigitalOcean Spaces and S3-compatible
11+
services. Available as a CLI and Go library.
12+
13+
## CLI
14+
15+
### Install It
16+
17+
Download a build from the [releases][releases] page. macOS, Linux and Windows builds are available for various architectures.
18+
19+
macOS users can also use Homebrew:
20+
21+
```
22+
brew install meowgorithm/homebrew-tap/pipedream
23+
```
24+
25+
Or you can just use `go get`:
26+
27+
```bash
28+
go get github.com/meowgorithm/pipedream/pipedream
29+
```
30+
31+
[releases]: https://github.com/meowgorithm/pipedream/releases
32+
33+
### Usage
34+
35+
```bash
36+
# Set your secrets, region and endpoint in the environment
37+
export ACCESS_KEY="..."
38+
export SECRET_KEY="..."
39+
export ENDPOINT="sfo2.digitaloceanspaces.com" # for AWS set REGION
40+
41+
# Pipe in data or redirect in a file
42+
pipedream --bucket images --path pets/puppy.jpg < puppy.jpg
43+
44+
# Get fancy
45+
export now=$(date +"%Y-%m-%d_%H:%M:%S_%Z")
46+
cat /data/dump.rdb | gzip | pipedream -bucket backups -path dump-$(now).rdb.gz
47+
48+
# For more info
49+
pipedream -h
50+
```
51+
52+
## Library
53+
54+
The library uses an event based model, sending events through a channel.
55+
56+
```go
57+
import "github.com/meowgorithm/pipedream"
58+
59+
// Create a new multipart upload object
60+
m := pipedream.MultipartUpload{
61+
AccessKey: os.Getenv("ACCESS_KEY"),
62+
SecretKey: os.Getenv("SECRET_KEY"),
63+
Endpoint: "sfo2.digitaloceanspaces.com", // you could use Region for AWS
64+
Bucket: "my-fave-bucket",
65+
}
66+
67+
// Get an io.Reader, like an *os.File or os.Stdout
68+
f, err := os.Open("big-redis-dump.rdb")
69+
if err != nil {
70+
fmt.Printf("Rats: %v\n", err)
71+
os.Exit(1)
72+
}
73+
defer f.Close()
74+
75+
// Send up the data. Pipdream returns a channel where you can listen for events
76+
ch := m.Send(f, "backups/dump.rdb")
77+
done := make(chan struct{})
78+
79+
// Listen for activity. For more detailed reporting, see the docs
80+
go func() {
81+
for {
82+
e := <-ch
83+
switch e.(type) {
84+
case pipedream.Complete:
85+
fmt.Println("It worked!")
86+
close(done)
87+
return
88+
case pipedream.Error:
89+
fmt.Println("Rats, it didn't work.")
90+
close(done)
91+
return
92+
}
93+
}
94+
}()
95+
96+
<-done
97+
```
98+
99+
[Full source][example] of this example. For an example with more detailed
100+
reporting, see the source code in the [CLI][cli].
101+
102+
[example]: https://github.com/meowgorithm/pipedream/blob/master/example/main.go
103+
[cli]: https://github.com/meowgorithm/pipedream/tree/master/pipedream
104+
105+
## Awknowledgements
106+
107+
Thanks to to Apoorva Manjunath‘s [S3 multipart upload example](https://github.com/apoorvam/aws-s3-multipart-upload)
108+
for the S3 implementation details.
109+
110+
## License
111+
112+
[MIT](https://github.com/meowgorithm/pipedream/raw/master/LICENSE)

example/main.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/meowgorithm/pipedream"
8+
)
9+
10+
func main() {
11+
12+
m := pipedream.MultipartUpload{
13+
AccessKey: os.Getenv("ACCESS_KEY"),
14+
SecretKey: os.Getenv("SECRET_KEY"),
15+
Endpoint: "sfo2.digitaloceanspaces.com", // you could use Region for AWS
16+
Bucket: "my-fave-bucket",
17+
}
18+
19+
// Get an io.Reader
20+
f, err := os.Open("big-redis-dump.rdb")
21+
if err != nil {
22+
fmt.Printf("Rats: %v\n", err)
23+
os.Exit(1)
24+
}
25+
defer f.Close()
26+
27+
// Send it up! Pipdream returns a channel where you can listen for events.
28+
ch := m.Send(f, "backups/dump.rdb")
29+
done := make(chan struct{})
30+
31+
// Listen for activity. For more detailed reporting, see the docs.
32+
go func() {
33+
for {
34+
e := <-ch
35+
switch e.(type) {
36+
case pipedream.Complete:
37+
fmt.Println("It worked!")
38+
close(done)
39+
return
40+
case pipedream.Error:
41+
fmt.Println("Rats, it didn't work.")
42+
close(done)
43+
return
44+
}
45+
}
46+
}()
47+
48+
<-done
49+
}

go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/meowgorithm/pipedream
2+
3+
go 1.14
4+
5+
require (
6+
github.com/aws/aws-sdk-go v1.33.7
7+
github.com/dustin/go-humanize v1.0.0
8+
github.com/meowgorithm/babyenv v1.3.0
9+
github.com/muesli/reflow v0.1.0
10+
github.com/muesli/termenv v0.7.0
11+
github.com/spf13/cobra v1.0.0
12+
github.com/spf13/pflag v1.0.5 // indirect
13+
golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect
14+
)

0 commit comments

Comments
 (0)