Skip to content

Commit 6d59654

Browse files
committed
Cleans up code a bit
1 parent 0c136cc commit 6d59654

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
VERSION := v1.0.0
1+
VERSION := v1.0.1
22

3-
compile: deps
3+
compile:
44
go build
55

66
install:
@@ -10,7 +10,6 @@ deps:
1010
go get github.com/c4milo/github-release
1111

1212
release:
13-
set -x; \
1413
latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
1514
comparison="$$latest_tag..HEAD"; \
1615
if [ -z "$$latest_tag" ]; then comparison=""; fi; \

main.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ Please refer to https://help.github.com/articles/creating-an-access-token-for-co
8585
log.Println("Done")
8686
}
8787

88+
func uploadFile(uploadURL, path string) {
89+
file, err := os.Open(path)
90+
if err != nil {
91+
log.Printf("Error: %s\n", err.Error())
92+
return
93+
}
94+
defer file.Close()
95+
96+
size, err := fileSize(file)
97+
if err != nil {
98+
log.Printf("Error: %s\n", err.Error())
99+
return
100+
}
101+
102+
body, err := doRequest("POST", uploadURL+"?name="+file.Name(), "application/octet-stream", file, size)
103+
if err != nil {
104+
log.Printf("Error: %s\n", err.Error())
105+
}
106+
107+
if DEBUG {
108+
log.Println("========= UPLOAD RESPONSE ===========")
109+
log.Println(string(body[:]))
110+
}
111+
}
112+
88113
// Creates a Github Release, attaching the given files as release assets
89114
// If a release already exist, up in Github, this function will attempt to attach the given files to it
90115
func CreateRelease(tag, branch, desc string, filepaths []string) {
@@ -125,29 +150,7 @@ func CreateRelease(tag, branch, desc string, filepaths []string) {
125150
for i := range filepaths {
126151
wg.Add(1)
127152
func(index int) {
128-
file, err := os.Open(filepaths[i])
129-
if err != nil {
130-
log.Printf("Error: %s\n", err.Error())
131-
return
132-
}
133-
defer file.Close()
134-
135-
size, err := fileSize(file)
136-
if err != nil {
137-
log.Printf("Error: %s\n", err.Error())
138-
return
139-
}
140-
141-
body, err := doRequest("POST", uploadURL+"?name="+file.Name(), "application/octet-stream", file, size)
142-
if err != nil {
143-
log.Printf("Error: %s\n", err.Error())
144-
}
145-
146-
if DEBUG {
147-
log.Println("========= UPLOAD RESPONSE ===========")
148-
log.Println(string(body[:]))
149-
}
150-
153+
uploadFile(uploadURL, filepaths[index])
151154
wg.Done()
152155
}(i)
153156
}

0 commit comments

Comments
 (0)