firebase

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 7 Imported by: 0

README

Firebase Module

Firebase integration module for Go applications.

Installation

liquor app enable firebase
# or
go get github.com/go-liquor/liquor-sdk/modules/firebase

Configuration

In your configuration file:

firebase:
  configFile: "path/to/firebase-credentials.json"

Add in your main.go:

package main

import (
	"github.com/go-liquor/framework/internal/adapters/server/http"
	"github.com/go-liquor/framework/internal/app/services"
	"github.com/go-liquor/liquor-sdk/app"
    "github.com/go-liquor/liquor-sdk/modules/firebase" // add this
)

func main() {
	app.NewApp(
        firebase.FirebaseModule, // add this
		http.Server,
		app.RegisterService(
			services.NewInitialService,
		),
	)
}

Usage

Authentication

type Service struct {
    client *firebase.Auth
}

func NewService(client *firebase.Auth) *Service {
    return &Service{client: client}
}

func (s *Service) Run(ctx context.Context, idToken string) {
   token, err := s.client.VerifyIDToken(ctx, idToken)
    if err != nil {
        // Handle error
    }
}
Firestore Database

type Service struct {
    client *firebase.FirestoreClient
}

func NewService(client *firebase.FirestoreClient) *Service {
    return &Service{client: client}
}

func (s *Service) Run(ctx context.Context) {
    // Use Firestore client
    doc := s.client.Collection("users").Doc("user1")
}

Features

  • Firebase App initialization
  • Authentication client
  • Firestore database client

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FirebaseModule = fx.Module("liquor-module-firebase", fx.Provide(
	NewApp,
	NewAuth,
	NewFirestore,
))

Functions

func NewApp

func NewApp(cfg *config.Config) (*firebase.App, error)

NewApp creates a new Firebase App instance using the provided configuration.

Parameters:

  • cfg: Configuration object containing Firebase settings

Returns:

  • *firebase.App: Firebase application instance
  • error: nil if successful, error otherwise

Example:

app, err := firebase.NewApp(config)

func NewAuth

func NewAuth(app *firebase.App) (*auth.Client, error)

NewAuth creates a new Firebase Auth client from the Firebase App instance.

Parameters:

  • app: Firebase application instance

Returns:

  • *auth.Client: Firebase authentication client
  • error: nil if successful, error otherwise

Example:

auth, err := firebase.NewAuth(app)

func NewFirestore

func NewFirestore(app *firebase.App) (*firestore.Client, error)

NewFirestore creates a new Firestore client from the Firebase App instance.

Parameters:

  • app: Firebase application instance

Returns:

  • *firestore.Client: Firestore database client
  • error: nil if successful, error otherwise

Example:

firestore, err := firebase.NewFirestore(app)

Types

This section is empty.

Jump to

Keyboard shortcuts

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