Firebase Cloud Messaging for application servers implemented using the Go programming language.

Overview

Firebase Cloud Notifications Client

Go Report Card Build StatusMIT Licence Coverage Status

Firebase Cloud Messaging for application servers implemented using the Go programming language. It's designed for simple push notification sending via HTTP API

Getting started

To install fcm, use go get:

go get gopkg.in/maddevsio/fcm.v1

Import fcm with the following:

import "gopkg.in/maddevsio/fcm.v1"

Sample usage

package main

import (
	"fmt"
	"log"

	"gopkg.in/maddevsio/fcm.v1"
)

func main() {
	data := map[string]string{
		"msg": "Hello World1",
		"sum": "Happy Day",
	}
	c := fcm.NewFCM("serverKey")
	token := "token"
	response, err := c.Send(fcm.Message{
		Data:             data,
		RegistrationIDs:  []string{token},
		ContentAvailable: true,
		Priority:         fcm.PriorityHigh,
		Notification: fcm.Notification{
			Title: "Hello",
			Body:  "World",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Status Code   :", response.StatusCode)
	fmt.Println("Success       :", response.Success)
	fmt.Println("Fail          :", response.Fail)
	fmt.Println("Canonical_ids :", response.CanonicalIDs)
	fmt.Println("Topic MsgId   :", response.MsgID)
}

More examples can be found in /_examples/ directory

License

MIT License

Copyright (c) 2017 Mad Devs Developers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Change type of multicast_id from int to uint64

    Change type of multicast_id from int to uint64

    With using this library we get an error on unmarshalling multicast_id to int, like this

    Sending the notification failed: json: cannot unmarshal number 5618853696839826700 into Go struct field Response.multicast_id of type int
    

    This PR changes is to use unsigned int which is capable to fit the large number.

    opened by tobiasKaminsky 6
  • honor Retry-After header for status codes 5xx

    honor Retry-After header for status codes 5xx

    According to specification: Errors in the 500-599 range (such as 500 or 503) indicate that there was an internal error in the FCM connection server while trying to process the request, or that the server is temporarily unavailable (for example, because of timeouts). Sender must retry later, honoring any Retry-After header included in the response. Application servers must implement exponential back-off.

    opened by sev3ryn 4
  • Add support for custom http.Client

    Add support for custom http.Client

    In appengine you cant use the default http.Client. I needed a custom urlfetch.Client (wich maches the http.Client interface).

    However there was no way to submit a custom client. My simple code change allows this. Its backwards compatible.

    The log file from Appengine logs:

    Post https://fcm.googleapis.com/fcm/send: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/

    opened by tjerkw 4
  • Unmarshal downstream results into a struct

    Unmarshal downstream results into a struct

    Downstream message response results seem to have a stable message structure:

    https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream

    So this just puts those result into a struct.

    opened by themartorana 2
  • fcm.go incorrect logic

    fcm.go incorrect logic

    Hello, just wanted to point out that there is some inconsistency in file fcm.go in line 88:

    image

    (resp.StatusCode >= 500 && resp.StatusCode > 600) - this clause will never proccess 5xx statuses, which is this code for (due to commit messsage).

    I hope this would help you!

    opened by Bogdamned 1
  • cannot use

    cannot use "gopkg.in/maddevsio/fcm.v1".Message literal (type "gopkg.in/maddevsio/fcm.v1".Message) as type *"gopkg.in/maddevsio/fcm.v1".Message in argument to cfcm.Send

    I'm trying to use this module with go gin, so just changed c to cfm in the test code:

    func SendNotiPost(c *gin.Context) {
    	data := map[string]string{
    		"msg": "Hello World1",
    		"sum": "Happy Day",
    	}
    	cfcm := fcm.NewFCM("myServerKy")
    	token := myMobiletoken"
    	response, err := cfcm.Send(fcm.Message{
    		Data:             data,
    		RegistrationIDs:  []string{token},
    		ContentAvailable: true,
    		Priority:         fcm.PriorityHigh,
    		Notification: fcm.Notification{
    			Title: "Hello",
    			Body:  "World",
    		},
    	})
    	if err != nil {
    		log.Fatal(err)
    	}
    	fmt.Println("Status Code   :", response.StatusCode)
    	fmt.Println("Success       :", response.Success)
    	fmt.Println("Fail          :", response.Fail)
    	fmt.Println("Canonical_ids :", response.CanonicalIDs)
    	fmt.Println("Topic MsgId   :", response.MsgID)
    
    	c.JSON(200, gin.H{"message": "Notifications sent"})
    }
    

    But I get:

    controller/firebase.go:39: cannot use "gopkg.in/maddevsio/fcm.v1".Message literal (type "gopkg.in/maddevsio/fcm.v1".Message) as type *"gopkg.in/maddevsio/fcm.v1".Message in argument to cfcm.Send
    controller/firebase.go:47: cannot use "gopkg.in/maddevsio/fcm.v1".Notification literal (type "gopkg.in/maddevsio/fcm.v1".Notification) as type *"gopkg.in/maddevsio/fcm.v1".Notification in field value
    
    

    What's wrong here? How to fix it?

    opened by k0fi 1
  • Move from pointers to values where practical

    Move from pointers to values where practical

    Refactors some FCM basics to use values instead of pointers in some areas.

    I'll be using this in a highly-concurrent environment, and wanted to make most structs safe to pass across go-routine boundaries.

    I didn't see anything that would preclude using pass-by-value (the structs are not particularly big, necessarily), so I tried to move away from pointers where possible for safety purposes.

    opened by themartorana 1
  • Implement exponential backoff for 500-599 status codes

    Implement exponential backoff for 500-599 status codes

    Errors in the 500-599 range (such as 500 or 503) indicate that there was an internal error in the FCM connection server while trying to process the request, or that the server is temporarily unavailable (for example, because of timeouts). Sender must retry later, honoring any Retry-After header included in the response. Application servers must implement exponential back-off.

    opened by gen1us2k 0
  • notification click does not start application

    notification click does not start application

    Hello,

    When I send a notification, I receive it but and when I click on it, it does not start my app when app is in background.

    When I send using firebase console I can start my app even when app is in background.

    I think I missed something on the payload to send or something.

    Any help ?

    Thank you

    opened by AhmedX6 0
Owner
Mad Devs
Mad Devs
Leave Discord servers using the folder names.

leavemealone ------------ Leave Discord servers using the folder names. Usage ----- 1. `export TOKEN="<token>"` 2. `go run . <folder_name>` 3. Chec

null 5 Feb 4, 2022
Instagram Messaging API GO SDK

Instagram Messaging API GO SDK Introduction Instabot, Instagram Messaging API GO SDK makes it easy to work with instagram messaging API. It uses Insta

Shahin Mahmud 31 Nov 13, 2022
A demonstration of the transactional outbox messaging pattern (+ Log Trailing) with Amazon DynamoDB (+ Streams) written in Go.

Transactional Outbox Pattern in Amazon DynamoDB A demonstration of the transactional outbox messaging pattern (+ Log Trailing) with Amazon DynamoDB (+

A. Ruiz 3 Apr 12, 2022
A collection of cloud security icons :cloud::lock:

Cloud Security Icons These icons are published under the extremely permissive Creative Commons Zero v1.0 Universal license. Downloads We provide all i

Aqua Security 125 Jan 7, 2023
AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Amazon Web Services 8.1k Dec 31, 2022
Simple Shopify API for the Go Programming Language

go-shopify Simple API made with go to make CRUD request to your Shopify Store. Installation go get github.com/rapito/go-shopify How-to-use Get Reques

Robert Peralta 25 Dec 7, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

null 0 Dec 7, 2021
A GitHub action for the Go! programming language (by Francis McCabe, 2004)

Setup Go! (GitHub Action) This project is a GitHub action for the Go! programmin

Sean P. Myrick V19.1.7.2 2 Oct 22, 2022
Stack-oriented programming language

aiur Stack-oriented programming language TODO Operators If statements Loops Procedures Include statements Package manager Syntax Conditional <conditio

Kaqtus 3 May 20, 2022
Pulumi - Modern Infrastructure as Code. Any cloud, any language 🚀

Pulumi's Infrastructure as Code SDK is the easiest way to create and deploy cloud software that use containers, serverless functions, hosted services,

Pulumi 14.6k Dec 30, 2022
Go library for querying Source servers

go-steam go-steam is a Go library for querying Source servers. Requirements Go 1.1 or above Installation go get -u github.com/sostronk/go-steam To us

SoStronk 29 Oct 28, 2022
DiscSpam is the best free and open source tool to spam/raid Discord servers.

DiscSpam Fast, Free, Easy to use Discord.com raid tool Report Bug , Request Feature About The Project There are a few Discord raid tools on GitHub, ho

null 53 Dec 27, 2022
A compute service that lets you run code without provisioning or managing servers

AWS Lambda for Go Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda runs your code on a high-availab

Ibrahim Dauda 0 Oct 13, 2021
Trojan discord bot, used for grieving discord servers

disc-TROJAN-go Trojan discord bot, used for grieving discord servers How Does It Work? disc-TROJAN-go is a discord bot with hidden features. At the ti

null 3 Feb 28, 2022
A very simple local client-server calculator project built using Cobra and socket programming, written in Go.

Golculator Introduction A very simple local client-server calculator project built using Cobra and socket programming, written in Go. Setup and run Fi

Amir Iravanimanesh 8 Apr 3, 2022
An API client for the Notion API implemented in Golang

An API client for the Notion API implemented in Golang

Anatoly Nosov 354 Dec 30, 2022
This repository will have code implemented for the 100 days of golang.

golang_100 This repository will have code implemented for the 100 days of golang. The resources I will use to do this 100 days golang programming are:

Vasileios Tsakalos 0 Jan 10, 2022
Nerftoken implemented in Golang

NerfToken - GolangEdition _ _ __ _______ _ | \ | | / _|__ __| | | | \| | ___

TNP IT Security 10 Sep 3, 2022
Helps me find good enough stocks that pay enough dividends using IEX Cloud data provider.

divyield Helps me find good enough stocks that pay enough dividends using IEX Cloud data provider. Create database using the postgres/scripts/createdb

Péter Szakszon 0 Feb 4, 2022