Skip to content

Commit a75b859

Browse files
chemidyhiranya911
authored andcommitted
add fcmOptions in WebpushConfig (#185)
* add fcm_options in WebpushConfig * revert formating * update goling path * update travis to golint only for go >= 1.9.x * fix test golint * remove support for go < 1.9 and fix fcmOptions name * fix test for fcm_options * fix indent * update doc
1 parent d12567f commit a75b859

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

.travis.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
language: go
22

33
go:
4-
- 1.6.x
5-
- 1.7.x
6-
- 1.8.x
74
- 1.9.x
85
- "1.10.x"
96
- master
@@ -18,16 +15,12 @@ matrix:
1815

1916
go_import_path: firebase.google.com/go
2017

21-
before_install:
22-
# Golint requires Go 1.7 or later.
23-
- if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.6\.([0-9]+|x)$ ]]; then go get github.com/golang/lint/golint; fi
24-
2518
install:
26-
# Prior to golang 1.8, this can trigger an error for packages containing only tests.
19+
- go get golang.org/x/lint/golint
2720
- go get -t -v $(go list ./... | grep -v integration)
2821

2922
script:
30-
- if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.6\.([0-9]+|x)+$ ]]; then golint -set_exit_status $(go list ./...); fi
23+
- golint -set_exit_status $(go list ./...)
3124
- ./.travis.gofmt.sh
3225
- go test -v -race -test.short ./... # Run tests with the race detector.
3326
- go vet -v ./... # Run Go static analyzer.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ requests, code review feedback, and also pull requests.
4141

4242
## Supported Go Versions
4343

44-
We support Go v1.6 and higher.
44+
We support Go v1.9 and higher.
4545
[Continuous integration](https://travis-ci.org/firebase/firebase-admin-go) system
46-
tests the code on Go v1.6 through v1.10.
46+
tests the code on Go v1.9 through v1.10.
4747

4848
## Documentation
4949

messaging/messaging.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
"firebase.google.com/go/internal"
2929
"golang.org/x/net/context"
30-
3130
"google.golang.org/api/transport"
3231
)
3332

@@ -225,6 +224,7 @@ type WebpushConfig struct {
225224
Headers map[string]string `json:"headers,omitempty"`
226225
Data map[string]string `json:"data,omitempty"`
227226
Notification *WebpushNotification `json:"notification,omitempty"`
227+
FcmOptions *WebpushFcmOptions `json:"fcmOptions,omitempty"`
228228
}
229229

230230
// WebpushNotificationAction represents an action that can be performed upon receiving a WebPush notification.
@@ -257,6 +257,11 @@ type WebpushNotification struct {
257257
CustomData map[string]interface{}
258258
}
259259

260+
// WebpushFcmOptions Options for features provided by the FCM SDK for Web.
261+
type WebpushFcmOptions struct {
262+
Link string `json:"link,omitempty"`
263+
}
264+
260265
// standardFields creates a map containing all the fields except the custom data.
261266
func (n *WebpushNotification) standardFields() map[string]interface{} {
262267
m := make(map[string]interface{})

messaging/messaging_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import (
2424
"testing"
2525
"time"
2626

27-
"golang.org/x/net/context"
28-
2927
"firebase.google.com/go/internal"
28+
"golang.org/x/net/context"
3029
"google.golang.org/api/option"
3130
)
3231

@@ -226,6 +225,9 @@ var validMessages = []struct {
226225
Vibrate: []int{100, 200, 100},
227226
CustomData: map[string]interface{}{"k1": "v1", "k2": "v2"},
228227
},
228+
FcmOptions: &WebpushFcmOptions{
229+
Link: "https://link.com",
230+
},
229231
},
230232
Topic: "test-topic",
231233
},
@@ -254,6 +256,9 @@ var validMessages = []struct {
254256
"k1": "v1",
255257
"k2": "v2",
256258
},
259+
"fcmOptions": map[string]interface{}{
260+
"link": "https://link.com",
261+
},
257262
},
258263
"topic": "test-topic",
259264
},
@@ -593,6 +598,32 @@ var invalidMessages = []struct {
593598
},
594599
want: `multiple specifications for the key "dir"`,
595600
},
601+
{
602+
name: "InvalidWebpushFcmOptionsLink",
603+
req: &Message{
604+
Webpush: &WebpushConfig{
605+
Notification: &WebpushNotification{},
606+
FcmOptions: &WebpushFcmOptions{
607+
Link: "link",
608+
},
609+
},
610+
Topic: "topic",
611+
},
612+
want: `invalid link URL: "link"`,
613+
},
614+
{
615+
name: "InvalidWebpushFcmOptionsLinkScheme",
616+
req: &Message{
617+
Webpush: &WebpushConfig{
618+
Notification: &WebpushNotification{},
619+
FcmOptions: &WebpushFcmOptions{
620+
Link: "http://link.com",
621+
},
622+
},
623+
Topic: "topic",
624+
},
625+
want: `invalid link URL: "http://link.com"; want scheme: "https"`,
626+
},
596627
}
597628

598629
var invalidTopicMgtArgs = []struct {

messaging/messaging_utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package messaging
1616

1717
import (
1818
"fmt"
19+
"net/url"
1920
"regexp"
2021
"strings"
2122
)
@@ -145,6 +146,15 @@ func validateWebpushConfig(webpush *WebpushConfig) error {
145146
return fmt.Errorf("multiple specifications for the key %q", k)
146147
}
147148
}
149+
if webpush.FcmOptions != nil {
150+
link := webpush.FcmOptions.Link
151+
p, err := url.ParseRequestURI(link)
152+
if err != nil {
153+
return fmt.Errorf("invalid link URL: %q", link)
154+
} else if p.Scheme != "https" {
155+
return fmt.Errorf("invalid link URL: %q; want scheme: %q", link, "https")
156+
}
157+
}
148158
return nil
149159
}
150160

0 commit comments

Comments
 (0)