pusher

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Pusher

Simple use of publish/subscribe in web, grpc, graphQL

Contributing

You can commit PR to this repository

Overview
  • This is a sample pub/sub library, but useful
  • Irregularly updated
How to get it?
go get -u github.com/gobkc/pusher
Quick start
package main

import (
	"fmt"
	"github.com/gobkc/pusher"
	"sync"
)

type User struct {
	Name     string `json:"name"`
	Password string `json:"password"`
}

func main() {
	pushUser := User{
		Name:     "test user",
		Password: "123456",
	}
	topic := "test topic"
	wg := sync.WaitGroup{}
	wg.Add(2)
	pusher.Subs(topic, func(cb pusher.SubsCallback) {
		var user User
		cb.Bind(&user)
		fmt.Println(user)
		wg.Done()
	})
	pusher.Subs(topic, func(cb pusher.SubsCallback) {
		var user User
		cb.Bind(&user)
		fmt.Println(user)
		wg.Done()
	})
	pusher.Push(topic, pushUser)
	wg.Wait()
}
License

© Gobkc, 2022~time.Now

Released under the Apache License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CallBackTypeError = errors.New(`checkIsSlice:dest must be a struct pointer`)

Functions

func Push

func Push[T any](data T)

func Subs

func Subs[T Subscriber](receiver any, f func(cb T))

Types

type GoPusher added in v0.0.5

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

func (*GoPusher) Logger added in v0.0.6

func (p *GoPusher) Logger() *slog.Logger

func (*GoPusher) Push added in v0.0.5

func (p *GoPusher) Push(data any)

func (*GoPusher) ReportEventCompleted added in v0.1.1

func (p *GoPusher) ReportEventCompleted(d any)

func (*GoPusher) ReportEventRegistered added in v0.1.1

func (p *GoPusher) ReportEventRegistered(d any)

func (*GoPusher) ReportEventStart added in v0.1.1

func (p *GoPusher) ReportEventStart(d any)

func (*GoPusher) Subs added in v0.0.5

func (p *GoPusher) Subs(ds any, callback func(cdata any))

type Pusher added in v0.0.5

type Pusher interface {
	Push(data any)
	//Subs
	//d: this parameter represents the data used by the Push function.
	Subs(d any, callback func(msg any))
	Logger() *slog.Logger
}

func New added in v0.0.6

func New(functions ...func(settings *Setting)) Pusher

type Setting added in v0.0.5

type Setting struct {
	Interval        time.Duration
	ConcurrentLimit int
	EnabledLog      bool
}

type Subscriber added in v0.0.5

type Subscriber interface {
	Bind(data any) error
	Set(data any) Subscriber
}

type SubscriberCallBackImpl added in v0.0.5

type SubscriberCallBackImpl struct {
	Data any
}

func (SubscriberCallBackImpl) Bind added in v0.0.5

func (s SubscriberCallBackImpl) Bind(data any) error

func (SubscriberCallBackImpl) Set added in v0.0.6

Jump to

Keyboard shortcuts

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