functions

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 6 Imported by: 3

README

functions-go

Golang client library to interact with Supabase Functions.

Quick start

Installation

Install the package using:

go get github.com/supabase-community/functions-go
Usage

The following example demonstrates how to create a client, marshal data into JSON, and make a request to execute a function on the server.

package main

import (
 "fmt"
 "log"

 "github.com/supabase-community/functions-go"
)

func main() {
 client := functions.NewClient("https://abc.supabase.co/functions/v1", "<service-token>", nil)

 // Define your data struct
 type Post struct {
  Title   string `json:"title"`
  Content string `json:"content"`
 }
 post := Post{Title: "Hello, world!", Content: "This is a new post."}

 // Invoke the function with the post data
 response, err := client.Invoke("createPost", post)
 if err != nil {
  log.Fatal(err)
 }

 fmt.Println("Response from server:", response)
}

This code will marshal the Post struct into JSON, send it to the createPost function, and print the response.

License

This repository is licensed under the MIT License.

Credits

For further inspiration and a JavaScript-based client, visit:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(rawUrl string, token string, headers map[string]string) *Client

NewClient constructs a new client given a URL to a functions-go instance

Usage:

client := functions.NewClient("https://abc.functions.supabase.co", "<service-token>", nil)

Inspired By Postgrest and storage-go.

func (*Client) Invoke

func (c *Client) Invoke(functionName string, payload interface{}) (string, error)

func (*Client) TokenAuth

func (c *Client) TokenAuth(token string) *Client

TokenAuth sets authorization headers for subsequent requests.

Jump to

Keyboard shortcuts

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