echo

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 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.14

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 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 PubBoolQ added in v0.0.11

func PubBoolQ(channel string, data bool)

func PubJson

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

pub json encoded data

func PubJsonQ added in v0.0.11

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

func PubQ added in v0.0.11

func PubQ(channel string, data string)

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

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 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 Queue added in v0.0.11

type Queue struct {
	Stream chan string
}

func (*Queue) Append added in v0.0.11

func (q *Queue) Append(data string) error

func (*Queue) AppendBool added in v0.0.11

func (q *Queue) AppendBool(data bool) error

func (*Queue) AppendJson added in v0.0.11

func (q *Queue) AppendJson(data interface{}) error

func (*Queue) Consume added in v0.0.11

func (q *Queue) Consume(ctx context.Context, consumer func(*SubCtx))

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 Streamer added in v0.0.11

type Streamer struct {
	QueueHandler map[string]func(*SubCtx)
}

func NewStreamer added in v0.0.11

func NewStreamer() *Streamer

func (*Streamer) Add added in v0.0.11

func (s *Streamer) Add(name string, handler JobHandler)

func (*Streamer) Stream added in v0.0.11

func (s *Streamer) Stream(ctx context.Context)

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)

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)

Jump to

Keyboard shortcuts

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