Skip to content

Commit a2fe09b

Browse files
author
Jack Tang
committed
UPT: link without debug symbols
1 parent 637d9be commit a2fe09b

File tree

5 files changed

+444
-181
lines changed

5 files changed

+444
-181
lines changed

Makefile

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
.PHONY: all
22
all: get
3-
GOOS=windows GOARCH=amd64 go build -o tusc_windows_amd64.exe cmd/tusc.go
4-
GOOS=darwin GOARCH=amd64 go build -o tusc_darwin_amd64 cmd/tusc.go
5-
GOOS=linux GOARCH=amd64 go build -o tusc_linux_amd64 cmd/tusc.go
6-
GOOS=linux GOARCH=arm go build -o tusc_linux_arm cmd/tusc.go
3+
GOOS=windows GOARCH=amd64 go build -ldflags "-w -s" -o tusc_windows_amd64.exe cmd/tusc.go
4+
GOOS=darwin GOARCH=amd64 go build -ldflags "-w -s" -o tusc_darwin_amd64 cmd/tusc.go
5+
GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -o tusc_linux_amd64 cmd/tusc.go
6+
GOOS=linux GOARCH=arm go build -ldflags "-w -s" -o tusc_linux_arm cmd/tusc.go
77

88
.PHONY: get
99
get:
1010
go get
1111

1212
clean:
13-
rm -rf tusc*
13+
rm -rf tusc*
14+
15+
release-patch: all
16+
release-it -n -i patch
17+
18+
release-minor: all
19+
release-it -n -i minor
20+
21+
release-major: all
22+
release-it -n -i major

cmd/tusc.go

+14-176
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,25 @@
11
package main
22

33
import (
4-
"fmt"
5-
"github.com/docopt/docopt-go"
6-
"github.com/eventials/go-tus"
7-
"github.com/eventials/go-tus/leveldbstore"
8-
"github.com/tus/tusd/cmd/tusd/cli"
9-
"net/http"
10-
"os"
11-
"strconv"
4+
"github.com/jackhftang/tusc/internal"
5+
"os"
126
)
137

14-
const Version = "0.1.0"
15-
168
const usage = `Usage:
179
tusc (server|s) [options]
1810
tusc (client|c) <file> [<url>] [options]
19-
tusc --help
20-
tusc --version`
21-
22-
const serverUsage = `tusc server
23-
24-
Usage:
25-
tusc (server|s) [options]
26-
tusc (server|s) --help
27-
28-
Options:
29-
-h --host HOST Host to bind HTTP server to [default: 0.0.0.0]
30-
-p --port PORT Port to bind HTTP server to [default: 1080]
31-
-d --dir PATH Directory to store uploads in [default: ./data]
32-
-b --base-path PATH Basepath of the HTTP server [default: /files/]
33-
--unix-sock PATH If set will listen to a UNIX socket at this location instead of a TCP socket
34-
--max-size SIZE Maximum size of a single upload in bytes [default: 0]
35-
--store-size BYTE Size of space allowed for storage [default: 0]
36-
--timeout TIMEOUT Read timeout for connections in milliseconds. A zero value means that reads will not timeout [default: 30*1000]
37-
--s3-bucket BUCKET Use AWS S3 with this bucket as storage backend requires the AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY and AWS_REGION environment variables to be set
38-
--s3-object-prefix Prefix for S3 object names
39-
--s3-endpoint PATH Endpoint to use S3 compatible implementations like minio requires s3-bucket to be pass
40-
--gcs-bucket BUCKET Use Google Cloud Storage with this bucket as storage backend requires the GCS_SERVICE_ACCOUNT_FILE environment variable to be set
41-
--gcs-object-prefix PREFIX Prefix for GCS object names can't contain underscore character
42-
--hooks-dir PATH Directory to search for available hooks scripts
43-
--hooks-http PATH An HTTP endpoint to which hook events will be sent to
44-
--hooks-http-retry NUM Number of times to retry on a 500 or network timeout [default: 3]
45-
--hooks-http-backoff SECOND Number of seconds to wait before retrying each retry [default: 1]
46-
--hooks-stop-code NUM Return code from post-receive hook which causes tusd to stop and delete the current upload. A zero value means that no uploads will be stopped [default: 0]
47-
--expose-metrics Expose metrics about tusd usage [default: true]
48-
--metrics-path PATH Path under which the metrics endpoint will be accessible [default: /metrics]
49-
--behind-proxy Respect X-Forwarded-* and similar headers which may be set by proxies [default: false]
50-
`
51-
52-
const clientUsage = `tusc client
53-
54-
Usage:
55-
tusc (client|c) <url> <file> [options]
56-
tusc (client|c) --help
57-
58-
Options:
59-
-r --resumable Save meta data for resumable uploads
60-
--store PATH Path to save meta data for resume [default: ./.tusc]
61-
--chuck-size BYTE Size of chucks of file [default: 2097152]
62-
--override-patch-method Sending a POST request instead of PATCH [default: false]
63-
`
64-
65-
func exitWithMessage(msg ...interface{}) {
66-
for _, m := range msg {
67-
fmt.Fprintln(os.Stderr, m)
68-
}
69-
//fmt.Fprintln(os.Stderr, msg...)
70-
os.Exit(1)
71-
}
72-
73-
func getInt64(arg docopt.Opts, key string) int64 {
74-
s, _ := arg.String(key)
75-
i, _ := strconv.ParseInt(s, 10, 64)
76-
return i
77-
}
78-
79-
func getBool(arg docopt.Opts, key string) bool {
80-
v, _ := arg[key]
81-
if b, ok := v.(bool); ok {
82-
return b
83-
}
84-
return false
85-
}
86-
87-
func getString(arg docopt.Opts, key string) string {
88-
v, _ := arg[key]
89-
if s, ok := v.(string); ok {
90-
return s
91-
}
92-
return ""
93-
}
94-
95-
func server() {
96-
arguments, _ := docopt.ParseArgs(serverUsage, nil, Version)
97-
cli.Flags.HttpHost, _ = arguments.String("--host")
98-
cli.Flags.HttpPort, _ = arguments.String("--port")
99-
cli.Flags.HttpSock, _ = arguments.String("--unix-sock")
100-
cli.Flags.MaxSize = getInt64(arguments, "--max-size")
101-
cli.Flags.UploadDir, _ = arguments.String("--dir")
102-
cli.Flags.StoreSize = getInt64(arguments, "--store-size")
103-
cli.Flags.Basepath, _ = arguments.String("--base-path")
104-
cli.Flags.Timeout = getInt64(arguments, "--timeout")
105-
cli.Flags.S3Bucket, _ = arguments.String("--s3-bucket")
106-
cli.Flags.S3ObjectPrefix, _ = arguments.String("--s3-object-prefix")
107-
cli.Flags.S3Endpoint, _ = arguments.String("--s3-endpoint")
108-
cli.Flags.GCSBucket, _ = arguments.String("--gcs-bucket")
109-
cli.Flags.GCSObjectPrefix, _ = arguments.String("--gcs-object-prefix")
110-
cli.Flags.FileHooksDir, _ = arguments.String("--hooks-dir")
111-
cli.Flags.HttpHooksEndpoint, _ = arguments.String("--hooks-http")
112-
cli.Flags.HttpHooksRetry, _ = arguments.Int("--hooks-http-retry")
113-
cli.Flags.HttpHooksBackoff, _ = arguments.Int("--hooks-http-backoff")
114-
cli.Flags.HooksStopUploadCode, _ = arguments.Int("--hooks-stop-code")
115-
cli.Flags.PluginHookPath, _ = arguments.String("--hooks-plugin")
116-
cli.Flags.ShowVersion, _ = arguments.Bool("--version")
117-
cli.Flags.ExposeMetrics, _ = arguments.Bool("--expose-metrics")
118-
cli.Flags.MetricsPath, _ = arguments.String("--metrics-path")
119-
cli.Flags.BehindProxy, _ = arguments.Bool("--behind-proxy")
120-
cli.CreateComposer()
121-
cli.Serve()
122-
}
123-
124-
func client() {
125-
arguments, _ := docopt.ParseArgs(clientUsage, nil, Version)
126-
127-
file, _ := arguments.String("<file>")
128-
url, _ := arguments.String("<url>")
129-
resume := getBool(arguments, "--resumable")
130-
131-
f, err := os.Open(file)
132-
if err != nil {
133-
exitWithMessage("Cannot open file: " + file)
134-
}
135-
defer f.Close()
136-
137-
// create the tus client
138-
var store tus.Store
139-
if resume {
140-
path := getString(arguments, "--store")
141-
store, err = leveldbstore.NewLeveldbStore(path)
142-
if err != nil {
143-
exitWithMessage("Cannot Open "+path, clientUsage)
144-
}
145-
}
146-
147-
client, _ := tus.NewClient(url, &tus.Config{
148-
ChunkSize: getInt64(arguments, "--chuck-size"),
149-
OverridePatchMethod: getBool(arguments, "--override-patch-method"),
150-
Resume: resume,
151-
Store: store,
152-
Header: make(http.Header),
153-
HttpClient: nil,
154-
})
155-
156-
// create an upload from a file.
157-
upload, _ := tus.NewUploadFromFile(f)
158-
159-
// create the uploader.
160-
var uploader *tus.Uploader
161-
if resume {
162-
uploader, err = client.CreateOrResumeUpload(upload)
163-
} else {
164-
uploader, err = client.CreateUpload(upload)
165-
}
166-
167-
fmt.Printf(uploader.Url())
168-
169-
// start the uploading process.
170-
if err = uploader.Upload(); err != nil {
171-
exitWithMessage("Upload incomplete")
172-
}
173-
}
11+
tusc --help`
17412

17513
func main() {
176-
if len(os.Args) < 2 {
177-
exitWithMessage("No command", usage)
178-
}
179-
switch cmd := os.Args[1]; cmd {
180-
case "server", "s":
181-
server()
182-
case "client", "c":
183-
client()
184-
default:
185-
exitWithMessage("Unknown command: "+cmd, usage)
186-
}
14+
if len(os.Args) < 2 {
15+
internal.ExitWithMessages("No command", usage)
16+
}
17+
switch cmd := os.Args[1]; cmd {
18+
case "server", "s":
19+
//internal.Server()
20+
case "client", "c":
21+
//internal.Client()
22+
default:
23+
internal.ExitWithMessages("Unknown command: "+cmd, usage)
24+
}
18725
}

internal/client.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package internal
2+
3+
import (
4+
"fmt"
5+
"github.com/docopt/docopt-go"
6+
"github.com/eventials/go-tus"
7+
"github.com/eventials/go-tus/leveldbstore"
8+
"net/http"
9+
"os"
10+
)
11+
12+
const clientUsage = `tusc client
13+
14+
Usage:
15+
tusc (client|c) <url> <file> [options]
16+
tusc (client|c) --help
17+
18+
Options:
19+
-r --resumable Save meta data for resumable uploads
20+
--store PATH Path to save meta data for resume [default: ./.tusc]
21+
--chuck-size BYTE Size of chucks of file [default: 2097152]
22+
--override-patch-method Sending a POST request instead of PATCH [default: false]
23+
`
24+
25+
func Client() {
26+
arguments, _ := docopt.ParseDoc(clientUsage)
27+
28+
file, _ := arguments.String("<file>")
29+
url, _ := arguments.String("<url>")
30+
resume := getBool(arguments, "--resumable")
31+
32+
f, err := os.Open(file)
33+
if err != nil {
34+
ExitWithMessages("Cannot open file: " + file)
35+
}
36+
defer f.Close()
37+
38+
// create the tus client
39+
var store tus.Store
40+
if resume {
41+
path := getString(arguments, "--store")
42+
store, err = leveldbstore.NewLeveldbStore(path)
43+
if err != nil {
44+
ExitWithMessages("Cannot Open "+path, clientUsage)
45+
}
46+
}
47+
48+
client, _ := tus.NewClient(url, &tus.Config{
49+
ChunkSize: getInt64(arguments, "--chuck-size"),
50+
OverridePatchMethod: getBool(arguments, "--override-patch-method"),
51+
Resume: resume,
52+
Store: store,
53+
Header: make(http.Header),
54+
HttpClient: nil,
55+
})
56+
57+
// create an upload from a file.
58+
upload, _ := tus.NewUploadFromFile(f)
59+
60+
// create the uploader.
61+
var uploader *tus.Uploader
62+
if resume {
63+
uploader, err = client.CreateOrResumeUpload(upload)
64+
} else {
65+
uploader, err = client.CreateUpload(upload)
66+
}
67+
68+
fmt.Println(uploader.Url())
69+
70+
// start the uploading process.
71+
if err = uploader.Upload(); err != nil {
72+
ExitWithMessages("Upload incomplete")
73+
}
74+
}

0 commit comments

Comments
 (0)