Skip to content

Commit

Permalink
🎨 Update pubsub message
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmr-jp committed May 11, 2022
1 parent 62df5bb commit 905df2c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ ifeq ($(URL),)
$(error "Please specify URL")
endif
gcloud pubsub topics publish $(FUNC_NAME)-topic \
--attribute=url=$(URL)
--message=$(URL)

log:
gcloud beta functions logs read $(FUNC_NAME) --gen2 --limit=100

open:
open https://console.cloud.google.com/functions/details/asia-northeast1/$(FUNC_NAME)?env=gen2
open https://console.cloud.google.com/cloudpubsub/topic/detail/$(FUNC_NAME)-topic
open https://console.cloud.google.com/storage/browser?project=$(PROJECT_ID)
10 changes: 2 additions & 8 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,12 @@ func parseURL(s string) string {
return url.Host + url.Path
}

func parseEvent(event event.Event) (url string) {
func parseEvent(event event.Event) string {
var msg MessagePublishedData
if err := event.DataAs(&msg); err != nil {
zl.Error("DATA_AS_ERROR", err)
return
}
url = msg.Message.Attributes["url"]
if url == "" {
zl.Error("ATTRIBUTE_ERROR", fmt.Errorf("url is empty"))
return
}
return url
return string(msg.Message.Data)
}

func getEnv() (bucket string) {
Expand Down
4 changes: 1 addition & 3 deletions fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func NewTestFetch() *TestFetch {
func (f *TestFetch) setup(t *testing.T) {
msg := fetch.MessagePublishedData{
Message: pubsub.Message{
Attributes: map[string]string{
"url": "https://api.github.com/users/defunkt",
},
Data: []byte("https://api.github.com/users/defunkt"),
},
}
f.event = event.New()
Expand Down

0 comments on commit 905df2c

Please sign in to comment.