router

package
v0.0.0-...-3ed29f2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrUnknownCommand = "ERR command resp type not support`%s`"
	ErrArguments      = "ERR wrong number of arguments for '%s' command"
)
View Source
const (
	FlagWrite = 1 << iota
	FlagMasterOnly
	FlagMayWrite
	FlagNotAllow
)
View Source
const AbortIndex int8 = math.MaxInt8 / 2

Variables

View Source
var (
	ErrLocalWriter  = errors.New("client conn writer error")
	ErrLocalFlush   = errors.New("client conn flush error")
	ErrCmdTypeWrong = errors.New("Err command type wrong")
)
View Source
var FirstKeyIndex = []uint8{1}
View Source
var OpTable = make(map[string]OpInfo, 256)

Functions

func OddKey

func OddKey(arg []interface{}) []uint8

func RecursivelyWriteObjects

func RecursivelyWriteObjects(local *RESPHandle.WriterHandle, reply ...interface{}) (err error)

func WriteBulk

func WriteBulk(local *RESPHandle.WriterHandle, reply []byte) error

func WriteBulkStrings

func WriteBulkStrings(local *RESPHandle.WriterHandle, reply []string) error

func WriteError

func WriteError(local *RESPHandle.WriterHandle, err error) error

func WriteInt

func WriteInt(local *RESPHandle.WriterHandle, reply int64) error

func WriteObjects

func WriteObjects(local *RESPHandle.WriterHandle, reply ...interface{}) (err error)

func WriteSimpleString

func WriteSimpleString(local *RESPHandle.WriterHandle, reply string) error

Types

type Context

type Context struct {
	Writer *RESPHandle.WriterHandle
	// Args     [][]byte
	Args     []interface{}
	Cmd      string
	Handlers HandlersChain // Middleware and final handler functions
	Index    int8
	Op       OpFlag
	Reply    interface{}
}

func (*Context) Abort

func (c *Context) Abort()

Abort prevents pending Handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining Handlers for this request are not called.

func (*Context) IsAborted

func (c *Context) IsAborted() bool

IsAborted returns true if the current context was aborted.

func (*Context) Next

func (c *Context) Next() error

func (*Context) Reset

func (c *Context) Reset()

type HandlerFunc

type HandlerFunc func(*Context) error

func IgnoreCMDMiddleware

func IgnoreCMDMiddleware(enable bool, cmdList []string) HandlerFunc

Start the middleware according to the configuration

func Namespace

func Namespace(prefix []byte) HandlerFunc

func PubSubMiddleware

func PubSubMiddleware(router IRoutes, pubSub *p2p.PubSub) HandlerFunc

PubSubMiddleware Synchronize notification to peer node middleware

type HandlersChain

type HandlersChain []HandlerFunc

HandlersChain defines a HandlerFunc array.

func (HandlersChain) Last

func (c HandlersChain) Last() HandlerFunc

Last returns the last handler in the chain. ie. the last handler is the main one.

type IRoutes

type IRoutes interface {
	Use(...HandlerFunc) IRoutes
	AddCommand(string, ...HandlerFunc) IRoutes
	InitCMD()
	Handle(w *RESPHandle.WriterHandle, args []interface{}) error
	Sync(args []interface{}) error
	Close() error
}

type OpFlag

type OpFlag uint32

func (OpFlag) IsMasterOnly

func (f OpFlag) IsMasterOnly() bool

func (OpFlag) IsNotAllowed

func (f OpFlag) IsNotAllowed() bool

func (OpFlag) IsReadOnly

func (f OpFlag) IsReadOnly() bool

type OpInfo

type OpInfo struct {
	Name       string
	Flag       OpFlag
	ArgsVerify VerifyFunc
}

type VerifyFunc

type VerifyFunc func(argsLen int) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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