Documentation
¶
Index ¶
- Constants
- Variables
- type AndroidConfig
- type AndroidFCMOptions
- type AndroidMessagePriority
- type AndroidNotification
- type Client
- type ClientMock
- func (m *ClientMock) MinimockFinish()
- func (m *ClientMock) MinimockSendDone() bool
- func (m *ClientMock) MinimockSendInspect()
- func (m *ClientMock) MinimockWait(timeout mm_time.Duration)
- func (mmSend *ClientMock) Send(ctx context.Context, msg *Message) (err error)
- func (mmSend *ClientMock) SendAfterCounter() uint64
- func (mmSend *ClientMock) SendBeforeCounter() uint64
- type ClientMockSendExpectation
- type ClientMockSendParams
- type ClientMockSendResults
- type Color
- type Error
- type FastHTTPAdapter
- type FastHTTPDoer
- type LightSettings
- type Message
- type NoopTokenSource
- type Notification
- type NotificationPriority
- type Option
- type SimpleClient
- type Visibility
Constants ¶
const ( NotificationPriorityUnspecified NotificationPriority = "PRIORITY_UNSPECIFIED" NotificationPriorityMin NotificationPriority = "PRIORITY_MIN" NotificationPriorityLow NotificationPriority = "PRIORITY_LOW" NotificationPriorityDefault NotificationPriority = "PRIORITY_DEFAULT" NotificationPriorityHigh NotificationPriority = "PRIORITY_HIGH" NotificationPriorityMax NotificationPriority = "PRIORITY_MAX" VisibilityPrivate Visibility = "PRIVATE" VisibilityPublic Visibility = "PUBLIC" VisibilitySecret Visibility = "SECRET" AndroidMessagePriorityNormal AndroidMessagePriority = "NORMAL" AndroidMessagePriorityHigh AndroidMessagePriority = "HIGH" )
const ( // DefaultEndpoint contains endpoint URL of FCM service. // this constant value are used as audience value for the auth token // be careful in in case of changes DefaultEndpoint = "https://fcm.googleapis.com/" )
Variables ¶
var ( // ErrInvalidMessage occurs if push notitication message is nil. ErrInvalidMessage = errors.New("message is invalid") // ErrInvalidTarget occurs if message topic is empty. ErrInvalidTarget = errors.New("topic is invalid or registration ids are not set") )
var DefaultHTTPAdapter = NewFastHTTPAdapter(&fasthttp.Client{})
Functions ¶
This section is empty.
Types ¶
type AndroidConfig ¶
type AndroidConfig struct { CollapseKey string `json:"collapse_key,omitempty"` Priority AndroidMessagePriority `json:"priority,omitempty"` Ttl string `json:"ttl,omitempty"` RestrictedPackageName string `json:"restricted_package_name,omitempty"` Data map[string]string `json:"data,omitempty"` Notification *AndroidNotification `json:"notification,omitempty"` FCMOptions *AndroidFCMOptions `json:"fcm_options,omitempty"` DirectBootOk bool `json:"direct_boot_ok,omitempty"` }
See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig
type AndroidFCMOptions ¶
type AndroidFCMOptions struct {
AnalyticsLabel string `json:"analytics_label,omitempty"`
}
AndroidFCMOptions contains additional options for features provided by the FCM Android SDK.
type AndroidMessagePriority ¶
type AndroidMessagePriority string
type AndroidNotification ¶
type AndroidNotification struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` Icon string `json:"icon,omitempty"` Color string `json:"color,omitempty"` Sound string `json:"sound,omitempty"` Tag string `json:"tag,omitempty"` ClickAction string `json:"click_action,omitempty"` BodyLocKey string `json:"body_loc_key,omitempty"` BodyLocArgs []string `json:"body_loc_args,omitempty"` TitleLocKey string `json:"title_loc_key,omitempty"` TitleLocArgs []string `json:"title_loc_args,omitempty"` ChannelId string `json:"channel_id,omitempty"` Ticker string `json:"ticker,omitempty"` Sticky bool `json:"sticky,omitempty"` EventName string `json:"event_name,omitempty"` LocalOnly bool `json:"local_only,omitempty"` NotificationPriority NotificationPriority `json:"notification_priority,omitempty"` DefaultSound bool `json:"default_sound,omitempty"` DefaultVibrateTimings bool `json:"default_vibrate_timings,omitempty"` DefaultLightSettings bool `json:"default_light_settings,omitempty"` VibrateTimings []string `json:"vibrate_timings,omitempty"` Visibility Visibility `json:"visibility,omitempty"` NotificationCount int `json:"notification_count,omitempty"` LightSettings *LightSettings `json:"light_settings,omitempty"` Image string `json:"image,omitempty"` }
Notification specifies the predefined, user-visible key-value pairs of the notification payload. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#AndroidNotification
type Client ¶
type Client interface { // Send sends a message to the FCM server without retrying in case of service // unavailability. A non-nil error is returned if a non-recoverable error // occurs (i.e. if the sendResponse status code is not between 200 and 299). Send(ctx context.Context, msg *Message) error }
SimpleClient abstracts the interaction between the application server and the FCM server via HTTP protocol. It uses Service Account Private Key for authentication.
If the `HTTP` field is nil, a zeroed http.SimpleClient will be allocated and used to send messages.
type ClientMock ¶
type ClientMock struct { SendMock mClientMockSend // contains filtered or unexported fields }
ClientMock implements Client
func NewClientMock ¶
func NewClientMock(t minimock.Tester) *ClientMock
NewClientMock returns a mock for Client
func (*ClientMock) MinimockFinish ¶
func (m *ClientMock) MinimockFinish()
MinimockFinish checks that all mocked methods have been called the expected number of times
func (*ClientMock) MinimockSendDone ¶
func (m *ClientMock) MinimockSendDone() bool
MinimockSendDone returns true if the count of the Send invocations corresponds the number of defined expectations
func (*ClientMock) MinimockSendInspect ¶
func (m *ClientMock) MinimockSendInspect()
MinimockSendInspect logs each unmet expectation
func (*ClientMock) MinimockWait ¶
func (m *ClientMock) MinimockWait(timeout mm_time.Duration)
MinimockWait waits for all mocked methods to be called the expected number of times
func (*ClientMock) Send ¶
func (mmSend *ClientMock) Send(ctx context.Context, msg *Message) (err error)
Send implements Client
func (*ClientMock) SendAfterCounter ¶
func (mmSend *ClientMock) SendAfterCounter() uint64
SendAfterCounter returns a count of finished ClientMock.Send invocations
func (*ClientMock) SendBeforeCounter ¶
func (mmSend *ClientMock) SendBeforeCounter() uint64
SendBeforeCounter returns a count of ClientMock.Send invocations
type ClientMockSendExpectation ¶
type ClientMockSendExpectation struct { Counter uint64 // contains filtered or unexported fields }
ClientMockSendExpectation specifies expectation struct of the Client.Send
func (*ClientMockSendExpectation) Then ¶
func (e *ClientMockSendExpectation) Then(err error) *ClientMock
Then sets up Client.Send return parameters for the expectation previously defined by the When method
type ClientMockSendParams ¶
type ClientMockSendParams struct {
// contains filtered or unexported fields
}
ClientMockSendParams contains parameters of the Client.Send
type ClientMockSendResults ¶
type ClientMockSendResults struct {
// contains filtered or unexported fields
}
ClientMockSendResults contains results of the Client.Send
type Error ¶
type Error string
This error can be caused by missing registration tokens, unregistered or expired tokens.
type FastHTTPAdapter ¶
func NewFastHTTPAdapter ¶
func NewFastHTTPAdapter(c *fasthttp.Client) *FastHTTPAdapter
type FastHTTPDoer ¶
type FastHTTPDoer interface {
Do(ctx context.Context, req *fasthttp.Request, resp *fasthttp.Response) error
}
FastHTTPDoer defines methods used to perform http requests using fasthttp library.
type LightSettings ¶
type Message ¶
type Message struct { Name string `json:"name,omitempty"` Data map[string]string `json:"data,omitempty"` Notification *Notification `json:"notification,omitempty"` Android *AndroidConfig `json:"android,omitempty"` // one of Token string `json:"token,omitempty"` Topic string `json:"topic,omitempty"` Condition string `json:"condition,omitempty"` }
Message represents list of targets, options, and payload for HTTP JSON messages. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message easyjson:json
func (Message) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Message) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Message) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Message) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type NoopTokenSource ¶
type NoopTokenSource struct{}
type Notification ¶
type Notification struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` Image string `json:"image,omitempty"` }
See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Notification
type NotificationPriority ¶
type NotificationPriority string
type Option ¶
type Option func(*SimpleClient) error
Option configurates SimpleClient with defined option.
func WithCredentialsData ¶
func WithEndpoint ¶
WithEndpoint returns Option to configure FCM Endpoint.
func WithHTTPClient ¶
func WithHTTPClient(httpClient FastHTTPDoer) Option
WithHTTPClient returns Option to configure HTTP Client.
type SimpleClient ¶
type SimpleClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(serviceAccountJSONData []byte, opts ...Option) *SimpleClient
NewClient creates new Firebase Cloud Messaging SimpleClient based on API key and with default endpoint and http client.
func (*SimpleClient) Send ¶
func (c *SimpleClient) Send(ctx context.Context, msg *Message) error
Send implementation of Client interface. Docs for the reference: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
type Visibility ¶
type Visibility string