Skip to content

A simple Go implementation of the Firebase Functions https.onCall protocol.

License

Notifications You must be signed in to change notification settings

lonebits/callable

Repository files navigation

Firebase Callable

GoPkg Widget build Go Report Card

A simple implementation of the Firebase https.onCall protocol for Go cloud functions.

Install

go get -u github.com/lonebits/callable

Usage

package greeting

import (
	"context"
	"github.com/lonebits/callable"
	"net/http"
)

// Create types to represent input and output data:
//

type greetingRequest struct {
	Who string `json:"who"`
}

type greetingResponse struct {
	Greeting string `json:"greeting"`
}

// Implement the callable.Request interface:
//

func (r *greetingRequest) Handle(ctx context.Context, call callable.Call) (interface{}, error) {
	return greetingResponse{
		Greeting: "Hello " + r.Who,
	}, nil
}

// Use callable to implement the function:
//

func Greeting(w http.ResponseWriter, r *http.Request) {
	callable.New(&greetingRequest{}).ServeHTTP(w, r)
}

Authentication

The WithAuth option can be used to enable ID Token validation. Firebase Auth user ID is then passed inside callable.Call.UID.

About

A simple Go implementation of the Firebase Functions https.onCall protocol.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages