lemo

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

README

package main

import (
	"net/http/httputil"
	"net/url"
	"os"

	"github.com/Lemo-yxk/lemo"
	"github.com/Lemo-yxk/lemo/console"
	"github.com/Lemo-yxk/lemo/exception"
	"github.com/Lemo-yxk/lemo/utils"
)

func main() {

	var httpServer = lemo.HttpServer{Host: "0.0.0.0", Port: 8666}

	var httpServerRouter = &lemo.HttpServerRouter{}

	httpServer.Use(func(next lemo.HttpServerMiddle) lemo.HttpServerMiddle {
		return func(stream *lemo.Stream) {
			if stream.Request.Header.Get("Upgrade") == "websocket" {
				httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: "0.0.0.0:8667"}).ServeHTTP(stream.Response, stream.Request)
			} else {
				next(stream)
			}
		}
	})

	httpServerRouter.Group("/hello").Handler(func(handler *lemo.HttpServerRouteHandler) {
		handler.Get("/world").Handler(func(t *lemo.Stream) exception.Error {
			// console.Log(t.Json.Empty("a"))
			// console.Log(t.Query.Get("a"))
			// console.Log(t.Form.Get("a"))
			// console.Log(t.Files.Get("a"))
			return t.JsonFormat("SUCCESS", 200, "hello world")
		})
	})

	go httpServer.SetRouter(httpServerRouter).Start()

	var webSocketServer = &lemo.WebSocketServer{Host: "0.0.0.0", Port: 8667, Path: "/"}

	var webSocketServerRouter = &lemo.WebSocketServerRouter{}

	webSocketServer.Use(func(next lemo.WebSocketServerMiddle) lemo.WebSocketServerMiddle {
		return func(conn *lemo.WebSocket, receive *lemo.ReceivePackage) {
			console.Log(1)
			next(conn, receive)
			console.Log(2)
		}
	})

	webSocketServerRouter.Group("/hello").Handler(func(handler *lemo.WebSocketServerRouteHandler) {
		handler.Route("/world").Handler(func(conn *lemo.WebSocket, receive *lemo.Receive) exception.Error {
			console.Log(3)
			return conn.JsonFormat(lemo.JsonPackage{
				Event: "/hello/world",
				Message: &lemo.JsonMessage{
					Status: "",
					Code:   0,
					Msg:    nil,
				},
			})
		})
	})

	go webSocketServer.SetRouter(webSocketServerRouter).Start()

	console.Log("start success")

	utils.Signal.ListenAll().Done(func(sig os.Signal) {
		console.Log(sig)
	})
}


Documentation

Index

Constants

View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
	Host          = "Host"
)

Variables

This section is empty.

Functions

func SetHttpGlobalAfter

func SetHttpGlobalAfter(after ...HttpServerAfter)

func SetHttpGlobalBefore

func SetHttpGlobalBefore(before ...HttpServerBefore)

func SetSocketClientAfter

func SetSocketClientAfter(after ...SocketClientAfter)

func SetSocketClientBefore

func SetSocketClientBefore(before ...SocketClientBefore)

func SetSocketServerAfter

func SetSocketServerAfter(after ...SocketServerAfter)

func SetSocketServerBefore

func SetSocketServerBefore(before ...SocketServerBefore)

func SetWebSocketClientAfter

func SetWebSocketClientAfter(after ...WebSocketClientAfter)

func SetWebSocketClientBefore

func SetWebSocketClientBefore(before ...WebSocketClientBefore)

func SetWebSocketServerAfter

func SetWebSocketServerAfter(after ...WebSocketServerAfter)

func SetWebSocketServerBefore

func SetWebSocketServerBefore(before ...WebSocketServerBefore)

func Udp

func Udp()

Types

type A

type A []interface{}

type Array

type Array []jsoniter.Any

func (Array) Float64

func (a Array) Float64() []float64

func (Array) Int

func (a Array) Int() []int

func (Array) String

func (a Array) String() []string

type Context

type Context interface{}

type Files

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

func (Files) All

func (f Files) All() map[string][]*multipart.FileHeader

func (Files) Get

func (f Files) Get(fileName string) *multipart.FileHeader

func (Files) GetAll

func (f Files) GetAll(fileName string) []*multipart.FileHeader

type HttpServer

type HttpServer struct {
	// Host 服务Host
	Host string
	// Port 服务端口
	Port int
	// Protocol 协议
	Protocol string
	// TLS FILE
	CertFile string
	// TLS KEY
	KeyFile string

	// AutoBind
	AutoBind bool

	OnOpen    func(stream *Stream)
	OnMessage func(stream *Stream)
	OnClose   func(stream *Stream)
	OnError   func(stream *Stream)
	// contains filtered or unexported fields
}

func (*HttpServer) GetRouter

func (h *HttpServer) GetRouter() *HttpServerRouter

func (*HttpServer) Ready

func (h *HttpServer) Ready()

func (*HttpServer) ServeHTTP

func (h *HttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HttpServer) SetRouter

func (h *HttpServer) SetRouter(router *HttpServerRouter) *HttpServer

func (*HttpServer) Shutdown

func (h *HttpServer) Shutdown()

func (*HttpServer) Start

func (h *HttpServer) Start()

Start Http

func (*HttpServer) Use

func (h *HttpServer) Use(middle ...func(next HttpServerMiddle) HttpServerMiddle)

type HttpServerAfter

type HttpServerAfter func(stream *Stream) exception.Error

type HttpServerBefore

type HttpServerBefore func(stream *Stream) (Context, exception.Error)

type HttpServerFunction

type HttpServerFunction func(stream *Stream) exception.Error

type HttpServerGroup

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

func (*HttpServerGroup) After

func (group *HttpServerGroup) After(after ...HttpServerAfter) *HttpServerGroup

func (*HttpServerGroup) Before

func (group *HttpServerGroup) Before(before ...HttpServerBefore) *HttpServerGroup

func (*HttpServerGroup) Handler

func (group *HttpServerGroup) Handler(fn HttpServerGroupFunction)

func (*HttpServerGroup) Route

func (group *HttpServerGroup) Route(path string) *HttpServerGroup

type HttpServerGroupFunction

type HttpServerGroupFunction func(handler *HttpServerRouteHandler)

type HttpServerMiddle

type HttpServerMiddle func(*Stream)

type HttpServerRoute

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

func (*HttpServerRoute) After

func (route *HttpServerRoute) After(after ...HttpServerAfter) *HttpServerRoute

func (*HttpServerRoute) Before

func (route *HttpServerRoute) Before(before ...HttpServerBefore) *HttpServerRoute

func (*HttpServerRoute) ForceAfter

func (route *HttpServerRoute) ForceAfter() *HttpServerRoute

func (*HttpServerRoute) ForceBefore

func (route *HttpServerRoute) ForceBefore() *HttpServerRoute

func (*HttpServerRoute) Handler

func (route *HttpServerRoute) Handler(fn HttpServerFunction)

func (*HttpServerRoute) PassAfter

func (route *HttpServerRoute) PassAfter() *HttpServerRoute

func (*HttpServerRoute) PassBefore

func (route *HttpServerRoute) PassBefore() *HttpServerRoute

type HttpServerRouteHandler

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

func (*HttpServerRouteHandler) Delete

func (handler *HttpServerRouteHandler) Delete(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Get

func (handler *HttpServerRouteHandler) Get(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Option

func (handler *HttpServerRouteHandler) Option(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Patch

func (handler *HttpServerRouteHandler) Patch(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Post

func (handler *HttpServerRouteHandler) Post(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Put

func (handler *HttpServerRouteHandler) Put(path string) *HttpServerRoute

func (*HttpServerRouteHandler) Route

func (handler *HttpServerRouteHandler) Route(method string, path string) *HttpServerRoute

type HttpServerRouter

type HttpServerRouter struct {
	IgnoreCase bool
	// contains filtered or unexported fields
}

func (*HttpServerRouter) GetAllRouters

func (router *HttpServerRouter) GetAllRouters() []*httpServerNode

func (*HttpServerRouter) Group

func (router *HttpServerRouter) Group(path string) *HttpServerGroup

func (*HttpServerRouter) Route

func (router *HttpServerRouter) Route(method string, path string) *HttpServerRoute

func (*HttpServerRouter) SetDefaultIndex

func (router *HttpServerRouter) SetDefaultIndex(index string)

func (*HttpServerRouter) SetStaticPath

func (router *HttpServerRouter) SetStaticPath(prefixPath string, staticPath string)

type Json

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

func (Json) Array

func (j Json) Array(path ...interface{}) Array

func (Json) Bytes

func (j Json) Bytes() []byte

func (Json) Empty

func (j Json) Empty(key string) bool

func (Json) Get

func (j Json) Get(path ...interface{}) Value

func (Json) Has

func (j Json) Has(key string) bool

func (Json) Iter

func (j Json) Iter() jsoniter.Any

GetByID 获取

func (Json) Path

func (j Json) Path(path ...interface{}) jsoniter.Any

func (Json) Reset

func (j Json) Reset(data interface{}) jsoniter.Any

func (Json) String

func (j Json) String() string

type JsonFormat

type JsonFormat struct {
	Status string      `json:"status"`
	Code   int         `json:"code"`
	Msg    interface{} `json:"msg"`
}

func JM

func JM(status string, code int, msg interface{}) *JsonFormat

type JsonMessage

type JsonMessage struct {
	Event string      `json:"event"`
	Data  interface{} `json:"data"`
}

func EM

func EM(event string, data interface{}) *JsonMessage

type JsonPackage

type JsonPackage struct {
	Event   string
	Message interface{}
}

type M

type M map[string]interface{}

type Params

type Params struct {
	Keys   []string
	Values []string
}

func (Params) ByName

func (ps Params) ByName(name string) string

type ProtoBufPackage

type ProtoBufPackage struct {
	Event   string
	Message proto.Message
}

type PushInfo

type PushInfo struct {
	MessageType int
	FD          uint32
	Message     []byte
}

type Receive

type Receive struct {
	Context Context
	Params  Params
	Body    *ReceivePackage
}

type ReceivePackage

type ReceivePackage struct {
	MessageType int
	Event       string
	Message     []byte
	ProtoType   int
	Raw         []byte
}

type Socket

type Socket struct {
	FD      uint32
	Conn    net.Conn
	Server  *SocketServer
	Context Context
}

func (*Socket) ClientIP

func (conn *Socket) ClientIP() string

func (*Socket) Close

func (conn *Socket) Close() error

func (*Socket) Json

func (conn *Socket) Json(msg interface{}) error

func (*Socket) JsonEmit

func (conn *Socket) JsonEmit(msg JsonPackage) error

func (*Socket) ProtoBuf

func (conn *Socket) ProtoBuf(msg proto.Message) error

func (*Socket) ProtoBufEmit

func (conn *Socket) ProtoBufEmit(msg ProtoBufPackage) error

func (*Socket) Push

func (conn *Socket) Push(msg []byte) error

type SocketClient

type SocketClient struct {
	Host string
	Port int

	Conn              net.Conn
	AutoHeartBeat     bool
	HeartBeatTimeout  int
	HeartBeatInterval int
	HeartBeat         func(c *SocketClient) error
	Reconnect         bool
	ReconnectInterval int
	ReadBufferSize    int
	WriteBufferSize   int
	HandshakeTimeout  int

	// 消息处理
	OnOpen    func(c *SocketClient)
	OnClose   func(c *SocketClient)
	OnMessage func(c *SocketClient, messageType int, msg []byte)
	OnError   func(err exception.Error)
	Status    bool

	Context Context

	PingHandler func(c *SocketClient) func(appData string) error

	PongHandler func(c *SocketClient) func(appData string) error
	// contains filtered or unexported fields
}

func (*SocketClient) Close

func (client *SocketClient) Close() error

func (*SocketClient) Connect

func (client *SocketClient) Connect()

func (*SocketClient) GetRouter

func (client *SocketClient) GetRouter() *SocketClientRouter

func (*SocketClient) Json

func (client *SocketClient) Json(msg interface{}) error

Json 发送JSON字符

func (*SocketClient) JsonEmit

func (client *SocketClient) JsonEmit(msg JsonPackage) error

func (*SocketClient) ProtoBuf

func (client *SocketClient) ProtoBuf(msg proto.Message) error

func (*SocketClient) ProtoBufEmit

func (client *SocketClient) ProtoBufEmit(msg ProtoBufPackage) error

func (*SocketClient) Push

func (client *SocketClient) Push(message []byte) error

Push 发送消息

func (*SocketClient) SetRouter

func (client *SocketClient) SetRouter(router *SocketClientRouter) *SocketClient

func (*SocketClient) Use

func (client *SocketClient) Use(middle ...func(SocketClientMiddle) SocketClientMiddle)

type SocketClientAfter

type SocketClientAfter func(c *SocketClient, receive *Receive) exception.Error

type SocketClientBefore

type SocketClientBefore func(c *SocketClient, receive *Receive) (Context, exception.Error)

type SocketClientFunction

type SocketClientFunction func(c *SocketClient, receive *Receive) exception.Error

type SocketClientGroup

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

func (*SocketClientGroup) After

func (group *SocketClientGroup) After(after ...SocketClientAfter) *SocketClientGroup

func (*SocketClientGroup) Before

func (group *SocketClientGroup) Before(before ...SocketClientBefore) *SocketClientGroup

func (*SocketClientGroup) Handler

func (group *SocketClientGroup) Handler(fn SocketClientGroupFunction)

func (*SocketClientGroup) Route

func (group *SocketClientGroup) Route(path string) *SocketClientGroup

type SocketClientGroupFunction

type SocketClientGroupFunction func(handler *SocketClientRouteHandler)

type SocketClientMiddle

type SocketClientMiddle func(c *SocketClient, receive *ReceivePackage)

type SocketClientNode

type SocketClientNode struct {
	Info                 string
	Route                []byte
	SocketClientFunction SocketClientFunction
	Before               []SocketClientBefore
	After                []SocketClientAfter
}

type SocketClientRoute

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

func (*SocketClientRoute) After

func (route *SocketClientRoute) After(after ...SocketClientAfter) *SocketClientRoute

func (*SocketClientRoute) Before

func (route *SocketClientRoute) Before(before ...SocketClientBefore) *SocketClientRoute

func (*SocketClientRoute) ForceAfter

func (route *SocketClientRoute) ForceAfter() *SocketClientRoute

func (*SocketClientRoute) ForceBefore

func (route *SocketClientRoute) ForceBefore() *SocketClientRoute

func (*SocketClientRoute) Handler

func (route *SocketClientRoute) Handler(fn SocketClientFunction)

func (*SocketClientRoute) PassAfter

func (route *SocketClientRoute) PassAfter() *SocketClientRoute

func (*SocketClientRoute) PassBefore

func (route *SocketClientRoute) PassBefore() *SocketClientRoute

type SocketClientRouteHandler

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

func (*SocketClientRouteHandler) Route

func (handler *SocketClientRouteHandler) Route(path string) *SocketClientRoute

type SocketClientRouter

type SocketClientRouter struct {
	IgnoreCase bool
	// contains filtered or unexported fields
}

func (*SocketClientRouter) GetAllRouters

func (router *SocketClientRouter) GetAllRouters() []*SocketClientNode

func (*SocketClientRouter) Group

func (router *SocketClientRouter) Group(path string) *SocketClientGroup

func (*SocketClientRouter) Route

func (router *SocketClientRouter) Route(path string) *SocketClientRoute

type SocketServer

type SocketServer struct {
	Host      string
	Port      int
	AutoBind  bool
	OnClose   func(conn *Socket)
	OnMessage func(conn *Socket, messageType int, msg []byte)
	OnOpen    func(conn *Socket)
	OnError   func(err exception.Error)

	HeartBeatTimeout  int
	HeartBeatInterval int
	ReadBufferSize    int
	WriteBufferSize   int
	WaitQueueSize     int
	HandshakeTimeout  int

	PingHandler func(connection *Socket) func(appData string) error

	PongHandler func(connection *Socket) func(appData string) error
	// contains filtered or unexported fields
}

func (*SocketServer) Close

func (socket *SocketServer) Close(fd uint32) error

func (*SocketServer) GetConnection

func (socket *SocketServer) GetConnection(fd uint32) (*Socket, bool)

func (*SocketServer) GetConnections

func (socket *SocketServer) GetConnections() chan *Socket

func (*SocketServer) GetConnectionsCount

func (socket *SocketServer) GetConnectionsCount() uint32

func (*SocketServer) GetRouter

func (socket *SocketServer) GetRouter() *SocketServerRouter

func (*SocketServer) Json

func (socket *SocketServer) Json(fd uint32, msg interface{}) error

Push Json 发送消息

func (*SocketServer) JsonEmit

func (socket *SocketServer) JsonEmit(fd uint32, msg JsonPackage) error

func (*SocketServer) JsonEmitAll

func (socket *SocketServer) JsonEmitAll(msg JsonPackage) (int, int)

func (*SocketServer) ProtoBuf

func (socket *SocketServer) ProtoBuf(fd uint32, msg proto.Message) error

func (*SocketServer) ProtoBufEmit

func (socket *SocketServer) ProtoBufEmit(fd uint32, msg ProtoBufPackage) error

func (*SocketServer) ProtoBufEmitAll

func (socket *SocketServer) ProtoBufEmitAll(msg ProtoBufPackage) (int, int)

func (*SocketServer) Push

func (socket *SocketServer) Push(fd uint32, msg []byte) error

Push 发送消息

func (*SocketServer) Ready

func (socket *SocketServer) Ready()

func (*SocketServer) SetRouter

func (socket *SocketServer) SetRouter(router *SocketServerRouter) *SocketServer

func (*SocketServer) Shutdown

func (socket *SocketServer) Shutdown()

func (*SocketServer) Start

func (socket *SocketServer) Start()

func (*SocketServer) Use

func (socket *SocketServer) Use(middle ...func(SocketServerMiddle) SocketServerMiddle)

type SocketServerAfter

type SocketServerAfter func(conn *Socket, receive *Receive) exception.Error

type SocketServerBefore

type SocketServerBefore func(conn *Socket, receive *Receive) (Context, exception.Error)

type SocketServerFunction

type SocketServerFunction func(conn *Socket, receive *Receive) exception.Error

type SocketServerGroup

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

func (*SocketServerGroup) After

func (group *SocketServerGroup) After(after ...SocketServerAfter) *SocketServerGroup

func (*SocketServerGroup) Before

func (group *SocketServerGroup) Before(before ...SocketServerBefore) *SocketServerGroup

func (*SocketServerGroup) Handler

func (group *SocketServerGroup) Handler(fn SocketServerGroupFunction)

func (*SocketServerGroup) Route

func (group *SocketServerGroup) Route(path string) *SocketServerGroup

type SocketServerGroupFunction

type SocketServerGroupFunction func(handler *SocketServerRouteHandler)

type SocketServerMiddle

type SocketServerMiddle func(conn *Socket, receive *ReceivePackage)

type SocketServerNode

type SocketServerNode struct {
	Info                 string
	Route                []byte
	SocketServerFunction SocketServerFunction
	Before               []SocketServerBefore
	After                []SocketServerAfter
}

type SocketServerRoute

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

func (*SocketServerRoute) After

func (route *SocketServerRoute) After(after ...SocketServerAfter) *SocketServerRoute

func (*SocketServerRoute) Before

func (route *SocketServerRoute) Before(before ...SocketServerBefore) *SocketServerRoute

func (*SocketServerRoute) ForceAfter

func (route *SocketServerRoute) ForceAfter() *SocketServerRoute

func (*SocketServerRoute) ForceBefore

func (route *SocketServerRoute) ForceBefore() *SocketServerRoute

func (*SocketServerRoute) Handler

func (route *SocketServerRoute) Handler(fn SocketServerFunction)

func (*SocketServerRoute) PassAfter

func (route *SocketServerRoute) PassAfter() *SocketServerRoute

func (*SocketServerRoute) PassBefore

func (route *SocketServerRoute) PassBefore() *SocketServerRoute

type SocketServerRouteHandler

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

func (*SocketServerRouteHandler) Route

func (handler *SocketServerRouteHandler) Route(path string) *SocketServerRoute

type SocketServerRouter

type SocketServerRouter struct {
	IgnoreCase bool
	// contains filtered or unexported fields
}

func (*SocketServerRouter) GetAllRouters

func (router *SocketServerRouter) GetAllRouters() []*SocketServerNode

func (*SocketServerRouter) Group

func (router *SocketServerRouter) Group(path string) *SocketServerGroup

func (*SocketServerRouter) Route

func (router *SocketServerRouter) Route(path string) *SocketServerRoute

type Store

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

func (Store) Add

func (store Store) Add(key string, value string)

func (Store) AllValues

func (store Store) AllValues() [][]string

func (Store) Empty

func (store Store) Empty(key string) bool

func (Store) Get

func (store Store) Get(key string) Value

func (Store) GetAll

func (store Store) GetAll(key string) []string

func (Store) Has

func (store Store) Has(key string) bool

func (Store) Keys

func (store Store) Keys() []string

func (Store) Remove

func (store Store) Remove(key string)

func (Store) String

func (store Store) String() string

func (Store) Values

func (store Store) Values() []string

type Stream

type Stream struct {
	Server   *HttpServer
	Response http.ResponseWriter
	Request  *http.Request
	Params   Params
	Context  Context
	Query    Store
	Form     Store
	Json     Json
	Files    Files
	// contains filtered or unexported fields
}

func NewStream

func NewStream(h *HttpServer, w http.ResponseWriter, r *http.Request) *Stream

func (*Stream) AutoGet

func (stream *Stream) AutoGet(key string) Value

func (*Stream) AutoParse

func (stream *Stream) AutoParse()

func (*Stream) ClientIP

func (stream *Stream) ClientIP() string

func (*Stream) End

func (stream *Stream) End(data interface{}) error

func (*Stream) EndBytes

func (stream *Stream) EndBytes(data []byte) error

func (*Stream) EndFile

func (stream *Stream) EndFile(fileName string, content interface{}) error

func (*Stream) EndJson

func (stream *Stream) EndJson(data interface{}) error

func (*Stream) EndString

func (stream *Stream) EndString(data string) error

func (*Stream) Forward

func (stream *Stream) Forward(fn HttpServerFunction) exception.Error

func (*Stream) Host

func (stream *Stream) Host() string

func (*Stream) JsonFormat

func (stream *Stream) JsonFormat(status string, code int, msg interface{}) exception.Error

func (*Stream) LastError

func (stream *Stream) LastError() interface{}

func (*Stream) Match

func (stream *Stream) Match() bool

func (*Stream) ParseFiles

func (stream *Stream) ParseFiles() Files

func (*Stream) ParseForm

func (stream *Stream) ParseForm() Store

func (*Stream) ParseJson

func (stream *Stream) ParseJson() Json

func (*Stream) ParseMultipart

func (stream *Stream) ParseMultipart() Store

func (*Stream) ParseQuery

func (stream *Stream) ParseQuery() Store

func (*Stream) Scheme

func (stream *Stream) Scheme() string

func (*Stream) SetHeader

func (stream *Stream) SetHeader(header string, content string)

func (*Stream) SetMaxMemory

func (stream *Stream) SetMaxMemory(maxMemory int64)

func (*Stream) String

func (stream *Stream) String() string

func (*Stream) Url

func (stream *Stream) Url() string

type Value

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

func (Value) Bool

func (v Value) Bool() bool

func (Value) Bytes

func (v Value) Bytes() []byte

func (Value) Float64

func (v Value) Float64() float64

func (Value) Int

func (v Value) Int() int

func (Value) String

func (v Value) String() string

type WebSocket

type WebSocket struct {
	FD       uint32
	Conn     *websocket.Conn
	Server   *WebSocketServer
	Response http.ResponseWriter
	Request  *http.Request
	Context  Context
}

WebSocket WebSocket

func (*WebSocket) ClientIP

func (conn *WebSocket) ClientIP() string

func (*WebSocket) Close

func (conn *WebSocket) Close() error

func (*WebSocket) Host

func (conn *WebSocket) Host() string

func (*WebSocket) Json

func (conn *WebSocket) Json(msg interface{}) error

func (*WebSocket) JsonEmit

func (conn *WebSocket) JsonEmit(msg JsonPackage) error

func (*WebSocket) JsonFormat

func (conn *WebSocket) JsonFormat(msg JsonPackage) exception.Error

func (*WebSocket) ProtoBuf

func (conn *WebSocket) ProtoBuf(msg proto.Message) error

func (*WebSocket) ProtoBufEmit

func (conn *WebSocket) ProtoBufEmit(msg ProtoBufPackage) error

func (*WebSocket) Push

func (conn *WebSocket) Push(messageType int, msg []byte) error

type WebSocketClient

type WebSocketClient struct {
	// 服务器信息
	Protocol string
	Host     string
	Port     int
	Path     string

	// 客户端信息
	Conn              *websocket.Conn
	Response          *http.Response
	AutoHeartBeat     bool
	HeartBeatTimeout  int
	HeartBeatInterval int
	HeartBeat         func(c *WebSocketClient) error
	Reconnect         bool
	ReconnectInterval int
	WriteBufferSize   int
	ReadBufferSize    int
	HandshakeTimeout  int

	// 消息处理
	OnOpen    func(c *WebSocketClient)
	OnClose   func(c *WebSocketClient)
	OnMessage func(c *WebSocketClient, messageType int, msg []byte)
	OnError   func(err exception.Error)
	Status    bool

	Context interface{}

	PingHandler func(c *WebSocketClient) func(appData string) error

	PongHandler func(c *WebSocketClient) func(appData string) error
	// contains filtered or unexported fields
}

WebSocketClient 客户端

func (*WebSocketClient) Close

func (client *WebSocketClient) Close() error

func (*WebSocketClient) Connect

func (client *WebSocketClient) Connect()

Connect 连接服务器

func (*WebSocketClient) GetRouter

func (client *WebSocketClient) GetRouter() *WebSocketClientRouter

func (*WebSocketClient) Json

func (client *WebSocketClient) Json(msg interface{}) error

Json 发送JSON字符

func (*WebSocketClient) JsonEmit

func (client *WebSocketClient) JsonEmit(msg JsonPackage) error

func (*WebSocketClient) JsonFormat

func (client *WebSocketClient) JsonFormat(msg JsonPackage) exception.Error

func (*WebSocketClient) ProtoBuf

func (client *WebSocketClient) ProtoBuf(msg proto.Message) error

func (*WebSocketClient) ProtoBufEmit

func (client *WebSocketClient) ProtoBufEmit(msg ProtoBufPackage) error

func (*WebSocketClient) Push

func (client *WebSocketClient) Push(messageType int, message []byte) error

Push 发送消息

func (*WebSocketClient) SetRouter

func (client *WebSocketClient) SetRouter(router *WebSocketClientRouter) *WebSocketClient

func (*WebSocketClient) Use

func (client *WebSocketClient) Use(middle ...func(WebSocketClientMiddle) WebSocketClientMiddle)

type WebSocketClientAfter

type WebSocketClientAfter func(c *WebSocketClient, receive *Receive) exception.Error

type WebSocketClientBefore

type WebSocketClientBefore func(c *WebSocketClient, receive *Receive) (Context, exception.Error)

type WebSocketClientFunction

type WebSocketClientFunction func(c *WebSocketClient, receive *Receive) exception.Error

type WebSocketClientGroup

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

func (*WebSocketClientGroup) After

func (*WebSocketClientGroup) Before

func (*WebSocketClientGroup) Handler

func (*WebSocketClientGroup) Route

func (group *WebSocketClientGroup) Route(path string) *WebSocketClientGroup

type WebSocketClientGroupFunction

type WebSocketClientGroupFunction func(handler *WebSocketClientRouteHandler)

type WebSocketClientMiddle

type WebSocketClientMiddle func(c *WebSocketClient, receive *ReceivePackage)

type WebSocketClientNode

type WebSocketClientNode struct {
	Info                    string
	Route                   []byte
	WebSocketClientFunction WebSocketClientFunction
	Before                  []WebSocketClientBefore
	After                   []WebSocketClientAfter
}

type WebSocketClientRoute

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

func (*WebSocketClientRoute) After

func (*WebSocketClientRoute) Before

func (*WebSocketClientRoute) ForceAfter

func (route *WebSocketClientRoute) ForceAfter() *WebSocketClientRoute

func (*WebSocketClientRoute) ForceBefore

func (route *WebSocketClientRoute) ForceBefore() *WebSocketClientRoute

func (*WebSocketClientRoute) Handler

func (route *WebSocketClientRoute) Handler(fn WebSocketClientFunction)

func (*WebSocketClientRoute) PassAfter

func (route *WebSocketClientRoute) PassAfter() *WebSocketClientRoute

func (*WebSocketClientRoute) PassBefore

func (route *WebSocketClientRoute) PassBefore() *WebSocketClientRoute

type WebSocketClientRouteHandler

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

func (*WebSocketClientRouteHandler) Route

type WebSocketClientRouter

type WebSocketClientRouter struct {
	IgnoreCase bool
	// contains filtered or unexported fields
}

func (*WebSocketClientRouter) GetAllRouters

func (router *WebSocketClientRouter) GetAllRouters() []*WebSocketClientNode

func (*WebSocketClientRouter) Group

func (router *WebSocketClientRouter) Group(path string) *WebSocketClientGroup

func (*WebSocketClientRouter) Route

func (router *WebSocketClientRouter) Route(path string) *WebSocketClientRoute

type WebSocketServer

type WebSocketServer struct {

	// Host 服务Host
	Host string
	// Port 服务端口
	Port int
	// Protocol 协议
	Protocol string
	// TLS FILE
	CertFile string
	// TLS KEY
	KeyFile string

	AutoBind bool

	OnClose   func(conn *WebSocket)
	OnMessage func(conn *WebSocket, messageType int, msg []byte)
	OnOpen    func(conn *WebSocket)
	OnError   func(err exception.Error)

	HeartBeatTimeout  int
	HeartBeatInterval int
	HandshakeTimeout  int
	ReadBufferSize    int
	WriteBufferSize   int
	WaitQueueSize     int
	CheckOrigin       func(r *http.Request) bool
	Path              string

	PingHandler func(connection *WebSocket) func(appData string) error

	PongHandler func(connection *WebSocket) func(appData string) error
	// contains filtered or unexported fields
}

WebSocketServer conn

func (*WebSocketServer) CheckPath

func (socket *WebSocketServer) CheckPath(p1 string, p2 string) bool

func (*WebSocketServer) Close

func (socket *WebSocketServer) Close(fd uint32) error

func (*WebSocketServer) GetConnection

func (socket *WebSocketServer) GetConnection(fd uint32) (*WebSocket, bool)

func (*WebSocketServer) GetConnections

func (socket *WebSocketServer) GetConnections() chan *WebSocket

func (*WebSocketServer) GetConnectionsCount

func (socket *WebSocketServer) GetConnectionsCount() uint32

func (*WebSocketServer) GetRouter

func (socket *WebSocketServer) GetRouter() *WebSocketServerRouter

func (*WebSocketServer) Json

func (socket *WebSocketServer) Json(fd uint32, msg interface{}) error

Push Json 发送消息

func (*WebSocketServer) JsonEmit

func (socket *WebSocketServer) JsonEmit(fd uint32, msg JsonPackage) error

func (*WebSocketServer) JsonEmitAll

func (socket *WebSocketServer) JsonEmitAll(msg JsonPackage) (int, int)

func (*WebSocketServer) JsonFormat

func (socket *WebSocketServer) JsonFormat(fd uint32, msg JsonPackage) exception.Error

func (*WebSocketServer) JsonFormatAll

func (socket *WebSocketServer) JsonFormatAll(msg JsonPackage) (int, int)

func (*WebSocketServer) ProtoBuf

func (socket *WebSocketServer) ProtoBuf(fd uint32, msg proto.Message) error

func (*WebSocketServer) ProtoBufEmit

func (socket *WebSocketServer) ProtoBufEmit(fd uint32, msg ProtoBufPackage) error

func (*WebSocketServer) ProtoBufEmitAll

func (socket *WebSocketServer) ProtoBufEmitAll(msg ProtoBufPackage) (int, int)

func (*WebSocketServer) Push

func (socket *WebSocketServer) Push(fd uint32, messageType int, msg []byte) error

Push 发送消息

func (*WebSocketServer) Ready

func (socket *WebSocketServer) Ready()

func (*WebSocketServer) ServeHTTP

func (socket *WebSocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WebSocketServer) SetRouter

func (socket *WebSocketServer) SetRouter(router *WebSocketServerRouter) *WebSocketServer

func (*WebSocketServer) Shutdown

func (socket *WebSocketServer) Shutdown()

func (*WebSocketServer) Start

func (socket *WebSocketServer) Start()

Start Http

func (*WebSocketServer) Use

func (socket *WebSocketServer) Use(middle ...func(next WebSocketServerMiddle) WebSocketServerMiddle)

type WebSocketServerAfter

type WebSocketServerAfter func(conn *WebSocket, receive *Receive) exception.Error

type WebSocketServerBefore

type WebSocketServerBefore func(conn *WebSocket, receive *Receive) (Context, exception.Error)

type WebSocketServerFunction

type WebSocketServerFunction func(conn *WebSocket, receive *Receive) exception.Error

type WebSocketServerGroup

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

func (*WebSocketServerGroup) After

func (*WebSocketServerGroup) Before

func (*WebSocketServerGroup) Handler

func (*WebSocketServerGroup) Route

func (group *WebSocketServerGroup) Route(path string) *WebSocketServerGroup

type WebSocketServerGroupFunction

type WebSocketServerGroupFunction func(handler *WebSocketServerRouteHandler)

type WebSocketServerMiddle

type WebSocketServerMiddle func(conn *WebSocket, receive *ReceivePackage)

type WebSocketServerNode

type WebSocketServerNode struct {
	Info                    string
	Route                   []byte
	WebSocketServerFunction WebSocketServerFunction
	Before                  []WebSocketServerBefore
	After                   []WebSocketServerAfter
}

type WebSocketServerRoute

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

func (*WebSocketServerRoute) After

func (*WebSocketServerRoute) Before

func (*WebSocketServerRoute) ForceAfter

func (route *WebSocketServerRoute) ForceAfter() *WebSocketServerRoute

func (*WebSocketServerRoute) ForceBefore

func (route *WebSocketServerRoute) ForceBefore() *WebSocketServerRoute

func (*WebSocketServerRoute) Handler

func (route *WebSocketServerRoute) Handler(fn WebSocketServerFunction)

func (*WebSocketServerRoute) PassAfter

func (route *WebSocketServerRoute) PassAfter() *WebSocketServerRoute

func (*WebSocketServerRoute) PassBefore

func (route *WebSocketServerRoute) PassBefore() *WebSocketServerRoute

type WebSocketServerRouteHandler

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

func (*WebSocketServerRouteHandler) Route

type WebSocketServerRouter

type WebSocketServerRouter struct {
	IgnoreCase bool
	// contains filtered or unexported fields
}

func (*WebSocketServerRouter) GetAllRouters

func (router *WebSocketServerRouter) GetAllRouters() []*WebSocketServerNode

func (*WebSocketServerRouter) Group

func (router *WebSocketServerRouter) Group(path string) *WebSocketServerGroup

func (*WebSocketServerRouter) Route

func (router *WebSocketServerRouter) Route(path string) *WebSocketServerRoute

Directories

Path Synopsis
container

Jump to

Keyboard shortcuts

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