echo

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 8 Imported by: 1

README

echo

echo is a golang runtime message tool currently support pub/sub

Install

go get github.com/johnhaha/echo@v0.0.17

Usage

Pub
echo.Pub(CHANNEL,CONTENT)
Pub Json
echo.PubJson(CHANNEL,JSON)
Sub
echo.Sub(CONTEXT,CHANNEL,HANDLER)

use suber to make multi sub

suber := echo.NewSuber()
suber.Add(CHANNEL,CONSUMER)
suber.Sub(ctx)

Documentation

Index

Constants

View Source
const (
	BoolTrue  = "True"
	BoolFalse = "False"
)

Variables

This section is empty.

Functions

func AddJsonDataToTimerHeap added in v0.0.13

func AddJsonDataToTimerHeap(channel string, data interface{}, time time.Time) error

add json data to timer heap

func AddManyEventToTimerHeap added in v0.0.13

func AddManyEventToTimerHeap(event []TimerEvent)

add many event to timer heap, can be used in initializing heap data

func AddToTimerHeap added in v0.0.13

func AddToTimerHeap(channel string, data string, time time.Time)

add channel and data to timer heap

func ConsumeQueue added in v0.0.17

func ConsumeQueue(ctx context.Context)

func GetBoolValue added in v0.0.11

func GetBoolValue(k string) (bool, error)

func GetJsonValue added in v0.0.11

func GetJsonValue(k string, data interface{}) error

func GetValue added in v0.0.11

func GetValue(k string) (string, error)

func Pub

func Pub(channel string, val string) error

pub string data to channel

func PubBool added in v0.0.11

func PubBool(channel string, val bool) error

pub bool data to channel

func PubJson

func PubJson(channel string, val interface{}) error

pub json encoded data

func PubJsonQueue added in v0.0.17

func PubJsonQueue(channel string, data interface{}) error

pub json data to queue

func PubQueue added in v0.0.17

func PubQueue(channel string, data string)

pub string data to queue

func RemValue added in v0.0.11

func RemValue(k string)

func RunTimerHeap added in v0.0.13

func RunTimerHeap(ctx context.Context)

run timer heap, this will block

func SetBoolValue added in v0.0.11

func SetBoolValue(k string, v bool)

func SetBuffer added in v0.0.10

func SetBuffer(count int)

func SetJsonValue added in v0.0.11

func SetJsonValue(k string, data interface{}) error

func SetQueueBuffer added in v0.0.17

func SetQueueBuffer(b int)

func SetQueueHandler added in v0.0.17

func SetQueueHandler(channel string, handler JobHandler)

set queue handler

func SetTimerHeapHandler added in v0.0.13

func SetTimerHeapHandler(channel string, handler JobHandler)

set timer heap handler

func SetValue added in v0.0.11

func SetValue(k string, v string)

func Sub

func Sub(ctx context.Context, channel string, consumer func(*SubCtx))

sub to some channel and take action

Types

type ChannelData added in v0.0.17

type ChannelData struct {
	Value
	Channel string
}

func GetChannelDataFromJson added in v0.0.17

func GetChannelDataFromJson(j string) (*ChannelData, error)

type ChannelQueue added in v0.0.17

type ChannelQueue struct {
	JobRouter
	DataChannel chan ChannelData
	Mtx         sync.RWMutex
}

func NewChannelQueue added in v0.0.17

func NewChannelQueue(buffer int) *ChannelQueue

new channel queue

func (*ChannelQueue) Consume added in v0.0.17

func (queue *ChannelQueue) Consume(ctx context.Context)

consume

func (*ChannelQueue) Pub added in v0.0.17

func (queue *ChannelQueue) Pub(channelData ChannelData)

insert data

type JobHandler added in v0.0.11

type JobHandler func(*SubCtx)

type JobRouter added in v0.0.13

type JobRouter struct {
	Handlers map[string]JobHandler
}

func (*JobRouter) Handle added in v0.0.13

func (r *JobRouter) Handle(channel string, ctx *SubCtx) error

func (*JobRouter) Set added in v0.0.13

func (r *JobRouter) Set(channel string, handler JobHandler)

type Sleeper added in v0.0.13

type Sleeper struct {
	Duration time.Duration
	Step     time.Duration
	Max      time.Duration
}

func NewSleeper added in v0.0.13

func NewSleeper(step time.Duration, max time.Duration) *Sleeper

func (*Sleeper) Reset added in v0.0.13

func (sleeper *Sleeper) Reset()

func (*Sleeper) Sleep added in v0.0.13

func (sleeper *Sleeper) Sleep()

type SubCtx

type SubCtx struct {
	Value
}

func (*SubCtx) Parser

func (c *SubCtx) Parser(data interface{}) error

type Suber added in v0.0.7

type Suber struct {
	JobRouter
}

func NewSuber added in v0.0.7

func NewSuber() *Suber

func (*Suber) Add added in v0.0.7

func (s *Suber) Add(channel string, consumer func(*SubCtx))

func (*Suber) Sub added in v0.0.7

func (s *Suber) Sub(ctx context.Context)

type TimerEvent added in v0.0.13

type TimerEvent struct {
	Value
	EventType string
	Ts        int64
}

type TimerEventHandler added in v0.0.13

type TimerEventHandler func(TimerEvent) error

type TimerEventHeap added in v0.0.13

type TimerEventHeap struct {
	Event  []TimerEvent
	Recent int64
	Remain int
	JobRouter
}

func NewTimerHeap added in v0.0.13

func NewTimerHeap() *TimerEventHeap

func (*TimerEventHeap) Extract added in v0.0.13

func (h *TimerEventHeap) Extract() (TimerEvent, error)

func (*TimerEventHeap) InitEvent added in v0.0.13

func (h *TimerEventHeap) InitEvent(event []TimerEvent)

func (*TimerEventHeap) Insert added in v0.0.13

func (h *TimerEventHeap) Insert(event TimerEvent)

func (TimerEventHeap) Len added in v0.0.13

func (h TimerEventHeap) Len() int

func (TimerEventHeap) Less added in v0.0.13

func (h TimerEventHeap) Less(i, j int) bool

func (*TimerEventHeap) LoadMoreEvent added in v0.0.13

func (h *TimerEventHeap) LoadMoreEvent(event []TimerEvent)

func (*TimerEventHeap) Pop added in v0.0.13

func (h *TimerEventHeap) Pop() interface{}

func (*TimerEventHeap) Push added in v0.0.13

func (h *TimerEventHeap) Push(x interface{})

func (TimerEventHeap) Swap added in v0.0.13

func (h TimerEventHeap) Swap(i, j int)

func (*TimerEventHeap) Update added in v0.0.13

func (h *TimerEventHeap) Update()

type Value added in v0.0.11

type Value struct {
	Data string
}

func (*Value) GetBool added in v0.0.11

func (v *Value) GetBool() bool

func (*Value) GetData added in v0.0.11

func (v *Value) GetData() string

func (*Value) GetJsonData added in v0.0.11

func (v *Value) GetJsonData(data interface{}) error

func (*Value) SetBool added in v0.0.11

func (v *Value) SetBool(data bool) *Value

func (*Value) SetJson added in v0.0.11

func (v *Value) SetJson(data interface{}) error

func (*Value) SetValue added in v0.0.11

func (v *Value) SetValue(data string) *Value

Jump to

Keyboard shortcuts

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