Categorygithub.com/overseedio/realtime-go
modulepackage
0.0.0
Repository: https://github.com/overseedio/realtime-go.git
Documentation: pkg.go.dev

# README

realtime-go

Realtime-go is a client library for supabase/realtime.

The package interface closely mirrors the supabase/realtime-js library.

Usage

package main

import (
	"log"
	realtimego "github.com/overseedio/realtime-go"
)

func main() {
	// phoneix realtime server endpoint
	const ENDPOINT = "https://{SUPABASE_DB_ID}.supabase.co"
	// gateway api key
	const API_KEY = "..."
	// (optional) auth token
	const RLS_TOKEN = "..."

	// create client
	c, err := realtimego.NewClient(ENDPOINT, API_KEY,
		realtimego.WithUserToken(RLS_TOKEN),
	)
	if err != nil {
		log.Fatal(err)
	}

	// connect to server
	err = c.Connect()
	if err != nil {
		log.Fatal(err)
	}

	// create and subscribe to channel
	db := "realtime"
	schema := "public"
	table := "my_table"
	ch, err := c.Channel(realtimego.WithTable(&db, &schema, &table))
	if err != nil {
		log.Fatal(err)
	}

	// setup hooks
	ch.OnInsert = func(m realtimego.Message) {
		log.Println("***ON INSERT....", m)
	}
	ch.OnDelete = func(m realtimego.Message) {
		log.Println("***ON DELETE....", m)
	}
	ch.OnUpdate = func(m realtimego.Message) {
		log.Println("***ON UPDATE....", m)
	}

	// subscribe to channel
	err = ch.Subscribe()
	if err != nil {
		log.Fatal(err)
	}
}

# Functions

NewClient returns a realtime client.
WithHeartbeatInterval option sets the heartbeat interval () on the socket connection.
WithParams option sets the request parameters used when sending data to the server.
WithTable option sets the database/schema/table for a channel.
WithUserToken option sets the user_token parameter for user auth when communicating with the server.

# Constants

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
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Channel manages a subscription to a realtime socket.
Client manages connections to the realtime server topics.
No description provided by the author

# Type aliases

ChannelOption represents the channel configuration options.
ClientOption represents the client configuration options.
No description provided by the author
No description provided by the author