hero

package
v0.0.0-...-0b5b6e3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteErrorToConn

func WriteErrorToConn(conn net.Conn, err error, isEncrypted bool, encryptionKey []byte) (int, error)

func WriteMsgToConn

func WriteMsgToConn(conn net.Conn, action string, body interface{}, isEncrypted bool, encryptionKey []byte) (int, error)

Types

type Context

type Context interface {
	SetEncryptionKey(key []byte)
	GetEncryptionKey() []byte
	TurnEncryptionOn() error
	TurnEncryptionOff() error
	RemoteAddr() net.Addr
	Get(key string) interface{}
	Set(key string, value interface{})
	Bind(i interface{}) error
	Hero() *Hero
	Conn() net.Conn
	JSON(string, interface{}) error
	WriteMsg(action string, body interface{}) error
	ReadMsg(i interface{}) error
	Action() string
}

type DecrypterFunc

type DecrypterFunc func(key []byte, buf []byte) ([]byte, error)

type EncrypterFunc

type EncrypterFunc func(key []byte, buf []byte) ([]byte, error)

type HandlerFunc

type HandlerFunc func(Context) error

type Hero

type Hero struct {
	Address string

	EncrypterFunc EncrypterFunc
	DecrypterFunc DecrypterFunc
	// contains filtered or unexported fields
}

func NewHero

func NewHero(address string) *Hero

func (*Hero) Action

func (h *Hero) Action(name string, handler HandlerFunc)

func (*Hero) AddMiddleware

func (h *Hero) AddMiddleware(handler HandlerFunc)

func (*Hero) Connect

func (h *Hero) Connect(ctx context.Context, address string, startState string) error

func (*Hero) Shutdown

func (h *Hero) Shutdown() error

func (*Hero) Start

func (h *Hero) Start(ctx context.Context) error

type Message

type Message struct {
	Action string `json:"action"`
	Error  string `json:"error"`
	Body   []byte `json:"body"`
}

func ReadMsgFromConn

func ReadMsgFromConn(conn net.Conn, isEncrypted bool, encryptionKey []byte) (*Message, error)

Jump to

Keyboard shortcuts

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