apiserver

package
Version: v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(f handlerFunc, middleware []MiddlewareFunc) *handler

Types

type ClientCommandDesciption

type ClientCommandDesciption struct {
	Name   string
	Params interface{}
}

type Closer added in v0.0.2

type Closer interface {
	Close()
}

type CmdLogger added in v0.1.1

type CmdLogger interface {
	LogRequest(session interface{}, in *PacketIn, out *PacketOut)
	LogPush(session interface{}, out *PacketOut)
}

type CmdNamer

type CmdNamer interface {
	CmdName() string
}

type CommandIn

type CommandIn struct {
	Name string          `json:"name"`
	Data json.RawMessage `json:"data,omitempty"`
}

type CommandOut

type CommandOut struct {
	Name string      `json:"name"`
	Data interface{} `json:"data,omitempty"`
}

type Conn

type Conn interface {
	// public method for pushes
	Send(cmds ...CmdNamer) error

	Session() interface{}
	SetSession(v interface{})
	Close()
	// contains filtered or unexported methods
}

type Connection

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

func (*Connection) Close

func (self *Connection) Close()

func (*Connection) Send

func (self *Connection) Send(cmds ...CmdNamer) error

func (*Connection) Session

func (self *Connection) Session() interface{}

func (*Connection) SetSession added in v0.0.2

func (self *Connection) SetSession(v interface{})

func (*Connection) Start

func (self *Connection) Start()

type Describer

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

func NewDescriber

func NewDescriber(tm map[reflect.Type]string) *Describer

func (*Describer) Describe

func (self *Describer) Describe(t reflect.Type) interface{}

type EmptyLogger added in v0.0.2

type EmptyLogger struct{}

func (EmptyLogger) Println added in v0.0.2

func (EmptyLogger) Println(v ...interface{})

type ErrorCommand added in v0.0.3

type ErrorCommand struct {
	Type    string `json:"type"`
	Message string `json:"msg"`
}

func ApiError

func ApiError(typ, message string) *ErrorCommand

func (ErrorCommand) CmdName added in v0.0.3

func (ErrorCommand) CmdName() string

func (ErrorCommand) Error added in v0.0.3

func (e ErrorCommand) Error() string

type FakeConn

type FakeConn struct {
	SessionValue interface{}
	Written      [][]byte
	Mu           sync.Mutex
}

func NewFakeConn

func NewFakeConn() *FakeConn

func (*FakeConn) Close

func (*FakeConn) Close()

func (*FakeConn) Send

func (self *FakeConn) Send(cmds ...CmdNamer) error

func (*FakeConn) Session

func (self *FakeConn) Session() interface{}

func (*FakeConn) SetSession added in v0.0.2

func (self *FakeConn) SetSession(v interface{})

type IRouter

type IRouter interface {
	RegisterApiHandler(version int, command string, handler handlerFunc)
}

type Logger added in v0.0.2

type Logger interface {
	Println(v ...interface{})
}

type MiddlewareFunc added in v0.0.3

type MiddlewareFunc func(conn Conn) (commands []CmdNamer, next bool)

type PacketIn

type PacketIn struct {
	Commands []CommandIn `json:"cmds"`
	Cid      int32       `json:"cid,omitempty"`
}

type PacketOut

type PacketOut struct {
	Commands []CommandOut `json:"cmds"`
	Cid      int32        `json:"cid,omitempty"`
}

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) DescribeApi

func (self *Router) DescribeApi(tm map[reflect.Type]string) (scmds []*ServerCommandDesciption, ccmds []*ClientCommandDesciption)

func (*Router) ProcessCommand

func (self *Router) ProcessCommand(conn Conn, version int, command string, data json.RawMessage) (res []CommandOut)

func (*Router) ProcessPacket

func (self *Router) ProcessPacket(conn Conn, packetBuf []byte)

func (*Router) RegisterApiHandler

func (self *Router) RegisterApiHandler(version int, command string, handler handlerFunc)

handlerFunc Must be func(*Conn,*SomeType) *SomeRetType,error Or func(*Conn,*SomeType) *SomeRetType,*SomeOtherRetType,error Or func(*Conn,*SomeType) []interface{},error Or func(*Conn,*SomeType) error

func (*Router) RegisterApiHandlerWithMiddleware added in v0.0.3

func (self *Router) RegisterApiHandlerWithMiddleware(version int, command string, handler handlerFunc, middle []MiddlewareFunc)

func (*Router) RegisterGetVersion

func (self *Router) RegisterGetVersion(cb func(conn Conn) int)

func (*Router) SetCmdLogger added in v0.1.1

func (self *Router) SetCmdLogger(l CmdLogger)

func (*Router) With added in v0.0.3

func (self *Router) With(mw MiddlewareFunc) *middlewareWrapper

type Server

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

func NewServer

func NewServer(opts ServerOpts) (*Server, error)

func (*Server) HandleWs

func (self *Server) HandleWs(ws *websocket.Conn)

func (*Server) ServeHTTP

func (self *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

type ServerCommandDesciption

type ServerCommandDesciption struct {
	Name           string
	ReplayCommands []string
	Params         interface{}
}

type ServerOpts added in v0.0.2

type ServerOpts struct {
	Router       *Router
	NewSessionFn func() interface{}
	Logger       Logger
	CmdLogger    CmdLogger
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL