Categorygithub.com/patrickkabwe/go-fcm
modulepackage
1.2.0
Repository: https://github.com/patrickkabwe/go-fcm.git
Documentation: pkg.go.dev

# README

FCM Client Library

This library provides a simple interface to interact with Firebase Cloud Messaging (FCM v1) for sending notifications to devices.

Features

šŸ“² Send messages to devices using FCM.
šŸ“¢ Send messages to topics.
šŸ”‘ Set service account credentials.
šŸ”§ Customize HTTP client for requests.

Installation

To use this library, simply import it into your Go project:

import "path/to/fcm"

Ensure you have the necessary dependencies installed:

go get -u github.com/patrickkabwe/go-fcm

Usage

Creating a New Client

To start sending messages, you need to create a new FCM client instance:

client := fcm.NewClient()

Setting Service Account Credentials

Before sending messages, set your service account credentials:

client = client.SetCredentialFile("path/to/serviceAccountKey.json")

OR

credentials := &fcm.Credentials{
    ProjectID: "your-project-id",
    PrivateKeyID: "your-private-key-id",
    PrivateKey: "yout-private-key",
    ClientEmail: "your-client-email",
    ClientID: "your-client-id",
    AuthURI: "your-auth-uri",
    TokenURI: "your-token-uri",
    AuthProviderX509CertURL: "your-auth-provider-x509-cert-url",
    ClientX509CertURL: "your-client-x509-cert-url",
}

client = client.SetCredential(credentials)

Sending a Message

To send a message, create a MessagePayload and use the Send method:

msg := &MessagePayload{
    // Populate your message payload
}
err := client.Send(msg)
if err != nil {
    log.Fatalf("Failed to send message: %v", err)
}

log.Println("Message sent successfully")

Sending a Message to a Topic

To send a message to a specific topic:

msg := &MessagePayload{
    // Populate your message payload
    Topic: "news",
}

err := client.SendToTopic(msg)
if err != nil {
    log.Fatalf("Failed to send message: %v", err)
}

log.Println("Message sent successfully")

Customizing HTTP Client

You can customize the HTTP client used for making requests:

customClient := &http.Client{Timeout: time.Second * 10}
client = client.SetHTTPClient(customClient)

Contributing

Contributions to this library are welcome. Please ensure to follow the coding standards and write tests for new features.

License

This library is licensed under the MIT License. See the LICENSE file for details.

# Functions

NewClient creates a new FCMClient instance with the default HTTP client.

# Constants

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Credentials represents the service account credentials required to authenticate with the FCM server.
FCMClient represents a client for interacting with the Firebase Cloud Messaging (FCM) service.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

HttpClient is an interface that represents an HTTP client.