forked from appleboy/go-fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
40 lines (35 loc) · 825 Bytes
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package fcm
import (
"errors"
"net/http"
"time"
)
// Option configurates Client with defined option.
type Option func(*Client) error
// WithEndpoint returns Option to configure FCM Endpoint.
func WithEndpoint(endpoint string) Option {
return func(c *Client) error {
if endpoint == "" {
return errors.New("invalid endpoint")
}
c.endpoint = endpoint
return nil
}
}
// WithHTTPClient returns Option to configure HTTP Client.
func WithHTTPClient(httpClient *http.Client) Option {
return func(c *Client) error {
c.client = httpClient
return nil
}
}
// WithTimeout returns Option to configure HTTP Client timeout.
func WithTimeout(d time.Duration) Option {
return func(c *Client) error {
if d.Nanoseconds() <= 0 {
return errors.New("invalid timeout duration")
}
c.timeout = d
return nil
}
}