Coder Social home page Coder Social logo

realtime-go's Introduction

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)
	}
}

realtime-go's People

Contributors

snassr avatar

Stargazers

SolaTyolo avatar Dedi Hartono avatar defiants.co avatar Stuart Malt avatar Jakub Kottnauer avatar Yağız avatar Abderrahim El imame avatar Dira avatar Melvin Vivas avatar  avatar david avatar Hardik Sachan avatar

realtime-go's Issues

cannot Unmarshal payload object

when i listening to realtime database changes it works but the response i got is this {realtime:public:subjects UPDATE map[columns:[map[name:id type:int8] map[name:created_at type:timestamptz] map[name:title type:varchar] map[name:content type:text]] commit_timestamp:2022-12-30T14:50:03Z errors:<nil> old_record:map[id:5] record:map[content:adadd created_at:2022-12-30T12:35:12.650686+00:00 id:5 title:sdds] schema:public table:subjects type:UPDATE] 0} 2022/12/30 15:50:03 ***ON UPDATE Subject.... map[columns:[map[name:id type:int8] map[name:created_at type:timestamptz] map[name:title type:varchar] map[name:content type:text]] commit_timestamp:2022-12-30T14:50:03Z errors:<nil> old_record:map[id:5] record:map[content:adadd created_at:2022-12-30T12:35:12.650686+00:00 id:5 title:sdds] schema:public table:subjects type:UPDATE]
in the Payload obejct but we cannot Unmarshal this object to access to attribute because it's not a valid json .
i hope you will help with this ASAP .Kind regards

Add integration tests

  • create/use framework for standing up or mocking phoneix realtime websocket connection
  • use framework to test INSERT/UPDATE/DELETE messages from a server

Handle server events

Handle necessary events coming from the server and update the channel according to the event.

  • Currently the package only handles EVENT_MESSAGE_INSERT, EVENT_MESSAGE_UPDATE, EVENT_MESSAGE_DELETE
  • There are reply messages sent from the server we should handle...? Such as, if there was a failure to join. Then we should attempt to reconnect or notify the client and remove the channel from the router.

Code Refs

Add unit tests

Add unit tests and coverage on structs/funcs that do not require phoneixserver/websocket

Bad handshake

I am getting this error connecting to a local realtime instance. Any ideas what could be the cause?

2022/05/24 18:30:31 connected to server: &{404 Not Found 404 HTTP/1.1 1 1 map[Cache-Control:[max-age=0, private, must-revalidate] Content-Length:[9] Content-Type:[text/html; charset=utf-8] Date:[Tue, 24 May 2022 10:30:31 GMT] Server:[Cowboy] X-Request-Id:[FvID1jiwVo3c7tAAAAUm]] {0xc0001840c0} 9 [] false false map[] 0xc000108100 <nil>}
2022/05/24 18:30:31 websocket: bad handshake

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.