ans

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anser

type Anser struct {

	// 讀取超時
	ReadTimeout time.Duration
	// contains filtered or unexported fields
}

func (*Anser) Disconnect added in v1.4.0

func (a *Anser) Disconnect(cid int32) error

func (*Anser) Handler

func (a *Anser) Handler()

持續檢查是否有未完成的工作,若有,則呼叫外部定義的 workHandler 函式

func (*Anser) Listen

func (a *Anser) Listen()

監聽連線並註冊

func (*Anser) Write

func (a *Anser) Write(cid int32, data *[]byte, length int32) error

type EndPoint added in v1.3.0

type EndPoint struct {

	// key: HttpMethod(GET/POST/...), value: handler functions
	Handlers map[string]HandlerChain
	// contains filtered or unexported fields
}

==================================================================================================== EndPoint ====================================================================================================

func NewEndPoint added in v1.3.0

func NewEndPoint() *EndPoint

func (*EndPoint) InitNodes added in v1.3.0

func (ep *EndPoint) InitNodes(nodes []*node)

func (*EndPoint) Macth added in v1.3.0

func (ep *EndPoint) Macth(routes []string) bool

func (*EndPoint) SetParam added in v1.3.0

func (ep *EndPoint) SetParam(key string, value any)

type HandlerChain

type HandlerChain []HandlerFunc

type HandlerFunc

type HandlerFunc func(c *ghttp.Context)

type HttpAnser

type HttpAnser struct {
	*Anser
	*Router

	// key1: Method(Get/Post); key2: node number of EndPoint; value: []*EndPoint
	EndPointHandlers []*EndPoint

	// ==================================================
	// CORS
	// ==================================================
	UseCors bool
	// 允許的來源
	CorsOrigins []string
	// ex: 'GET, POST'
	CorsMethods []string
	// ex: 'true'
	CorsCredentials bool
	// ex: 'Authorization'
	CorsAllowHeaders []string
	// ex: 'Authorization'
	CorsExposeHeaders []string
	// ex: '3600'
	CorsMaxAge int32
	// contains filtered or unexported fields
}

func (*HttpAnser) Cors added in v1.5.1

func (a *HttpAnser) Cors(origins ...string)

func (*HttpAnser) Finish added in v1.1.0

func (a *HttpAnser) Finish(c *ghttp.Context)

func (*HttpAnser) GetContext added in v1.1.0

func (a *HttpAnser) GetContext(cid int32) *ghttp.Context

func (*HttpAnser) Listen

func (a *HttpAnser) Listen()

監聽連線並註冊

func (*HttpAnser) Send added in v1.1.0

func (a *HttpAnser) Send(c *ghttp.Context)

func (*HttpAnser) SetWorkHandler

func (a *HttpAnser) SetWorkHandler()

由外部定義 workHandler,定義如何處理工作

type IAnswer

type IAnswer interface {
	// 開始監聽
	Listen()
	// 執行一次主迴圈
	Handler()
	// 數據寫出(寫到寫出緩存中)
	Write(int32, *[]byte, int32) error
	//
	Disconnect(cid int32) error
}

func NewAnser

func NewAnser(socketType define.SocketType, laddr *net.TCPAddr, nConnect int32, nWork int32) (IAnswer, error)

func NewHttpAnser

func NewHttpAnser(laddr *net.TCPAddr, nConnect int32, nWork int32) (IAnswer, error)

func NewTcp0Anser

func NewTcp0Anser(laddr *net.TCPAddr, nConnect int32, nWork int32) (IAnswer, error)

type Router

type Router struct {
	*HttpAnser

	Handlers HandlerChain
	// contains filtered or unexported fields
}

==================================================================================================== Router ====================================================================================================

func (*Router) DELETE added in v1.4.2

func (r *Router) DELETE(path string, handlers ...HandlerFunc)

func (*Router) GET

func (r *Router) GET(path string, handlers ...HandlerFunc)

func (*Router) HEAD added in v1.4.2

func (r *Router) HEAD(path string, handlers ...HandlerFunc)

func (*Router) NewRouter

func (r *Router) NewRouter(relativePath string, handlers ...HandlerFunc) *Router

每個 EndPoint 對應一個 Router,但每個 Router 不一定對應著一個 EndPoint

func (*Router) PATCH added in v1.4.2

func (r *Router) PATCH(path string, handlers ...HandlerFunc)

func (*Router) POST

func (r *Router) POST(path string, handlers ...HandlerFunc)

func (*Router) PUT added in v1.4.2

func (r *Router) PUT(path string, handlers ...HandlerFunc)

type Tcp0Anser

type Tcp0Anser struct {
	*Anser
	// contains filtered or unexported fields
}

func (*Tcp0Anser) Listen

func (a *Tcp0Anser) Listen()

監聽連線並註冊

func (*Tcp0Anser) SetWorkHandler

func (a *Tcp0Anser) SetWorkHandler(handler func(*base.Work))

由外部定義 workHandler,定義如何處理工作

Jump to

Keyboard shortcuts

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