apiserver

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshallCommands added in v0.0.2

func MarshallCommands(cmds ...CmdNamer) []byte

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 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 {
	Send([]byte) error
	Session() interface{}
	SetSession(v interface{})
	Close()
}

type Connection

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

func (*Connection) Close

func (self *Connection) Close()

func (*Connection) Send

func (self *Connection) Send(buf []byte) 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
}

func NewFakeConn

func NewFakeConn() *FakeConn

func (*FakeConn) Close

func (*FakeConn) Close()

func (*FakeConn) Send

func (self *FakeConn) Send(buf []byte) 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) SetLogger added in v0.0.2

func (self *Router) SetLogger(l Logger)

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
}

Jump to

Keyboard shortcuts

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