fcm

package module
v0.0.0-...-a7ff472 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2019 License: MIT Imports: 7 Imported by: 0

README

go-fcm : FCM library in Go

Firebase Cloud Messaging ( FCM ) Library using golang ( Go )

This library uses HTTP/JSON Firebase Cloud Messaging connection server protocol

Usage

go get github.com/2tgroup/go-fcm

Docs

Firebase Cloud Messaging HTTP Protocol Specs
https://firebase.google.com/docs/cloud-messaging/http-server-ref
Firebase Cloud Messaging Developer docs
https://firebase.google.com/docs/cloud-messaging/

Example

package main

import (
	"log"
	"github.com/2tgroup/go-fcm"
	)

func main() {
	// init client
	client := fcm.NewClient("ApiKey")
	
	// You can use your HTTPClient 
	//client.SetHTTPClient(client)
	
	data := map[string]interface{}{
		"message": "From Go-FCM",
		"details": map[string]string{
			"name": "Name",
			"user": "Admin",
			"thing": "none",
		},
	}
	
	// You can use PushMultiple or PushSingle
	client.PushMultiple([]string{"token 1", "token 2"}, data)
	//client.PushSingle("token 1", data)
	
	// registrationIds remove and return map of invalid tokens
	badRegistrations := client.CleanRegistrationIds()
	log.Println(badRegistrations) 
	
	status, err := client.Send()
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	
	log.Println(status.Results)
}

Documentation

Index

Constants

View Source
const (
	// Methods
	GET  = "GET"
	POST = "POST"

	// Priorities
	HighPriority   = "high"
	NormalPriority = "normal"
)

Variables

View Source
var (
	// Errors
	ErrDataIsEmpty  = errors.New("data is empty")
	ErrToManyRegIDs = errors.New("too many registrations ids")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Message *message

	ApiFCM string
	ApiIID string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(key string) *Client

NewClient Create instance of client

func (*Client) AppendRegistrationIds

func (c *Client) AppendRegistrationIds(ids []string)

AppendRegistrationIds Append your list of RegistrationIds

func (*Client) CleanRegistrationIds

func (c *Client) CleanRegistrationIds() []string

CleanRegistrationIds remove invalid token of RegistrationIds and return map of BadTokens

func (*Client) GetTokenDetails

func (c *Client) GetTokenDetails(t string) (*tokenDetails, error)

GetTokenDetails get info about the token

func (*Client) PushMultiple

func (c *Client) PushMultiple(ids []string, d interface{})

SetMsgAndIds Set Message and ids for send

func (*Client) PushSingle

func (c *Client) PushSingle(to string, d interface{})

SetMsgAndTo 'To' this parameter specifies the recipient of a message.

func (*Client) Send

func (c *Client) Send() (*response, error)

Send Validate and Send FCM message

func (*Client) SetData

func (c *Client) SetData(d interface{})

SetData Set data for message

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client *http.Client)

SetHTTPClient set specific HTTPClient

type NotificationPayload

type NotificationPayload struct {
	Title            string `json:"title,omitempty"`
	Body             string `json:"body,omitempty"`
	BodyLocKey       string `json:"body_loc_key,omitempty"`
	BodyLocArgs      string `json:"body_loc_args,omitempty"`
	Icon             string `json:"icon,omitempty"`
	Tag              string `json:"tag,omitempty"`
	Sound            string `json:"sound,omitempty"`
	Badge            string `json:"badge,omitempty"`
	Color            string `json:"color,omitempty"`
	ClickAction      string `json:"click_action,omitempty"`
	TitleLocKey      string `json:"title_loc_key,omitempty"`
	TitleLocArgs     string `json:"title_loc_args,omitempty"`
	AndroidChannelID string `json:"android_channel_id,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL