Skip to content

Commit 5b34bd1

Browse files
committed
small improvements and fixes, updated the packages due security
1 parent 6988cf7 commit 5b34bd1

File tree

7 files changed

+1075
-58
lines changed

7 files changed

+1075
-58
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13-
dist
13+
dist
14+
.idea

Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
all: clean win_64 win_32 linux_64 linux_32 darwin_64 darwin_32 freebsd_64 freebsd_32
2+
all: clean win_64 win_32 linux_64 linux_32 darwin_64
33

44
win_64:
55
env GOOS=windows GOARCH=amd64 go build -o "dist/pubsub-push.exe" ./cmd/pubsub-push
@@ -26,11 +26,6 @@ darwin_64:
2626
gzip dist/pubsub-push -c > "dist/pubsub-push_$(shell cat VERSION)_$@.gz"
2727
rm -f dist/pubsub-push
2828

29-
darwin_32:
30-
env GOOS=darwin GOARCH=386 go build -o dist/pubsub-push ./cmd/pubsub-push
31-
gzip dist/pubsub-push -c > "dist/pubsub-push_$(shell cat VERSION)_$@.gz"
32-
rm -f dist/pubsub-push
33-
3429
clean:
3530
rm -rf dist/*
3631

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1
1+
0.2

cmd/pubsub-push/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,35 @@ func main() {
4646

4747
_, b := os.LookupEnv(credentialsVarName)
4848
if !b {
49-
fmt.Printf("You need to define %s variable with the correct credentials.\n", credentialsVarName)
50-
os.Exit(-1)
49+
fmt.Printf("define %s with the correct credential or the default credential will be used.\n", credentialsVarName)
5150
}
5251

5352
ctx := context.Background()
5453
client, err := pubsub.NewClient(ctx, settings.ProjectID)
5554

5655
if err != nil {
57-
log.Fatalf("Failed to create client: %v", err)
58-
os.Exit(-1)
56+
log.Fatalf("failed to create client: %v", err)
5957
}
6058

61-
fmt.Printf("Listening subscription %s:\n", settings.Subscription)
6259
sub := client.Subscription(settings.Subscription)
60+
ok, err := sub.Exists(ctx)
61+
62+
if !ok || err != nil {
63+
log.Fatalf("failed to connect to subscription: %s", settings.Subscription)
64+
}
65+
66+
fmt.Printf("listening subscription %s:\n", sub.String())
6367
err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
6468
b, size := push.EncodeMessage(m)
6569
buff := bytes.NewBuffer(b)
6670

6771
resp, err := push.PostMessage(settings.Endpoint, messageMimetype, buff, &settings.Headers)
6872

6973
if err != nil {
70-
log.Fatalf("Error on send message to endpoint: %v\n", err)
74+
log.Printf("[ERROR]: %v\n", err)
7175
m.Nack()
7276
} else {
73-
fmt.Printf("Message with %d bytes was sent to %s, got HTTP %d. Message: ", size, settings.Endpoint, resp.StatusCode)
77+
fmt.Printf("[SUCCESS]: message of %d bytes sent to %s: got HTTP %d. Message: ", size, settings.Endpoint, resp.StatusCode)
7478
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
7579
fmt.Printf("ACK\n")
7680
m.Ack()

go.mod

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ module github.com/klassmann/pubsub-push
33
go 1.12
44

55
require (
6-
cloud.google.com/go v0.43.0
7-
github.com/hashicorp/golang-lru v0.5.3 // indirect
8-
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 // indirect
9-
golang.org/x/arch v0.0.0-20190312162104-788fe5ffcd8c // indirect
10-
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
11-
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 // indirect
12-
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64 // indirect
13-
google.golang.org/grpc v1.22.1 // indirect
6+
cloud.google.com/go v0.110.0 // indirect
7+
cloud.google.com/go/iam v0.12.0 // indirect
8+
cloud.google.com/go/pubsub v1.28.0
9+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
10+
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 // indirect
1411
)

go.sum

Lines changed: 1053 additions & 33 deletions
Large diffs are not rendered by default.

pubsubpush.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (h *Headers) applyHeaders(ht *http.Request) {
5353
}
5454

5555
// EncodeMessage prepares the message to be like the HTTP Push from PubSub
56-
// It is an JSON with a data field containing a base64 value
56+
// It is a JSON with a data field containing a base64 value
5757
func EncodeMessage(m *pubsub.Message) ([]byte, int) {
5858
data := m.Data
5959
req := request{}
@@ -70,7 +70,7 @@ func EncodeMessage(m *pubsub.Message) ([]byte, int) {
7070
return b, len(b)
7171
}
7272

73-
// PostMessage sends the the message to endpoint
73+
// PostMessage sends the message to endpoint
7474
func PostMessage(url string, contentType string, body io.Reader, h *Headers) (*http.Response, error) {
7575
req, err := http.NewRequest("POST", url, body)
7676
if err != nil {

0 commit comments

Comments
 (0)