Documentation
¶
Index ¶
- Constants
- func ParseFormFile(file multipart.File, fileHeader *multipart.FileHeader, ...) (fileName string, err error)
- func SetLogger(on bool)
- type Filter
- type HttpContext
- func (t *HttpContext) Error(error string, code int)
- func (t *HttpContext) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (t *HttpContext) FormFiles(key string) *multipart.Form
- func (t *HttpContext) GetCookie(name string) (_r string, err error)
- func (t *HttpContext) GetParam(key string) (_r string)
- func (t *HttpContext) GetParamTrimSpace(key string) (_r string)
- func (t *HttpContext) MaxBytesReader(_max int64)
- func (t *HttpContext) PostParam(key string) (_r string)
- func (t *HttpContext) PostParamTrimSpace(key string) (_r string)
- func (t *HttpContext) PostParams(key string) (_r []string)
- func (t *HttpContext) Redirect(path string)
- func (t *HttpContext) RedirectWithStatus(path string, status int)
- func (t *HttpContext) Request() *http.Request
- func (t *HttpContext) RequestBody() []byte
- func (t *HttpContext) ResponseBytes(status int, bs []byte) (_r int, err error)
- func (t *HttpContext) ResponseString(data string) (_r int, err error)
- func (t *HttpContext) SetCookie(name, value, path string, maxAge int)
- func (t *HttpContext) SetCookie2(cookie *http.Cookie)
- func (t *HttpContext) Writer() http.ResponseWriter
- type HttpInfo
- type Tlnet
- func (t *Tlnet) CONNECT(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) Close() (err error)
- func (t *Tlnet) DELETE(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) GET(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HEAD(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) Handle(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HandleBinaryProcessor(pattern string, processor thrift.TProcessor)
- func (t *Tlnet) HandleCompactProcessor(pattern string, processor thrift.TProcessor)
- func (t *Tlnet) HandleFunc(pattern string, f *Filter, ...)
- func (t *Tlnet) HandleJsonProcessor(pattern string, processor thrift.TProcessor)
- func (t *Tlnet) HandleStatic(pattern, dir string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HandleStaticFunc(pattern string, dir string, f *Filter, ...)
- func (t *Tlnet) HandleStaticWithFilter(pattern, dir string, _filter *Filter, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HandleWebSocket(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HandleWebSocketBindConfig(pattern string, handlerctx func(hc *HttpContext), config *WebsocketConfig)
- func (t *Tlnet) HandleWebSocketBindOrigin(pattern, origin string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HandleWebSocketBindOriginFunc(pattern string, handlerctx func(hc *HttpContext), ...)
- func (t *Tlnet) HandleWithFilter(pattern string, _filter *Filter, handlerctx func(hc *HttpContext))
- func (t *Tlnet) HttpStart(addr string) (err error)
- func (t *Tlnet) HttpsStart(addr string, server_crt, server_key string) (err error)
- func (t *Tlnet) HttpsStartWithBytes(addr string, crtBytes, keyBytes []byte) (err error)
- func (t *Tlnet) IdleTimeout(idleTimeout time.Duration)
- func (t *Tlnet) MaxHeaderBytes(maxHeaderBytes int)
- func (t *Tlnet) OPTIONS(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) PATCH(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) POST(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) PUT(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) ReadHeaderTimeout(readHeaderTimeout time.Duration)
- func (t *Tlnet) ReadTimeout(readTimeout time.Duration)
- func (t *Tlnet) SetMaxBytesReader(maxBytes int64)
- func (t *Tlnet) TLSConfig(tlsConfig *tls.Config)
- func (t *Tlnet) TRACE(pattern string, handlerctx func(hc *HttpContext))
- func (t *Tlnet) UseServeMux() *Tlnet
- func (t *Tlnet) UseTlnetMux() *Tlnet
- func (t *Tlnet) UseTlnetMuxWithLimit(limit int) *Tlnet
- func (t *Tlnet) WriteTimeout(writeTimeout time.Duration)
- type TlnetMux
- type Websocket
- type WebsocketConfig
Constants ¶
const ( JSON tf_pco_type BINARY COMPACT )
const ( HttpGet httpMethod = http.MethodGet HttpHead httpMethod = http.MethodHead HttpPost httpMethod = http.MethodPost HttpPut httpMethod = http.MethodPut HttpPatch httpMethod = http.MethodPatch HttpDelete httpMethod = http.MethodDelete HttpConnect httpMethod = http.MethodConnect HttpOptions httpMethod = http.MethodOptions HttpTrace httpMethod = http.MethodTrace )
Variables ¶
This section is empty.
Functions ¶
func ParseFormFile ¶
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
func (*Filter) AddIntercept ¶
func (t *Filter) AddIntercept(pattern string, handler func(hc *HttpContext) bool) (err error)
AddIntercept
定义拦截规则 pattern正则匹配
func (*Filter) AddPageNotFoundIntercept ¶
func (t *Filter) AddPageNotFoundIntercept(handler func(hc *HttpContext) bool)
AddPageNotFoundIntercept
url路径找不到 ,方法返回true则,则不执行Filter后的handlerFunc,直接返回
func (*Filter) AddSuffixIntercept ¶
func (t *Filter) AddSuffixIntercept(suffixs []string, handler func(hc *HttpContext) bool)
AddSuffixIntercept
suffixs 后缀拦截,方法返回true则,则不执行Filter后的handlerFunc,直接返回
type HttpContext ¶
type HttpContext struct { ReqInfo *HttpInfo WS *Websocket // contains filtered or unexported fields }
func (*HttpContext) Error ¶
func (t *HttpContext) Error(error string, code int)
Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.
func (*HttpContext) FormFile ¶
func (t *HttpContext) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
func (*HttpContext) GetParam ¶
func (t *HttpContext) GetParam(key string) (_r string)
GetParam gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.
func (*HttpContext) GetParamTrimSpace ¶
func (t *HttpContext) GetParamTrimSpace(key string) (_r string)
GetParamTrimSpace TrimSpace GetParam
func (*HttpContext) MaxBytesReader ¶
func (t *HttpContext) MaxBytesReader(_max int64)
func (*HttpContext) PostParam ¶
func (t *HttpContext) PostParam(key string) (_r string)
PostParam returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values. If key is not present, PostParam returns the empty string. To access multiple values of the same key, call PostParams
func (*HttpContext) PostParamTrimSpace ¶
func (t *HttpContext) PostParamTrimSpace(key string) (_r string)
PostParamTrimSpace TrimSpace PostParam
func (*HttpContext) PostParams ¶
func (t *HttpContext) PostParams(key string) (_r []string)
PostParams multiple values of the same key
func (*HttpContext) RedirectWithStatus ¶
func (t *HttpContext) RedirectWithStatus(path string, status int)
func (*HttpContext) Request ¶
func (t *HttpContext) Request() *http.Request
func (*HttpContext) RequestBody ¶
func (t *HttpContext) RequestBody() []byte
func (*HttpContext) ResponseBytes ¶
func (t *HttpContext) ResponseBytes(status int, bs []byte) (_r int, err error)
func (*HttpContext) ResponseString ¶
func (t *HttpContext) ResponseString(data string) (_r int, err error)
ResponseString return the data to the client
func (*HttpContext) SetCookie ¶
func (t *HttpContext) SetCookie(name, value, path string, maxAge int)
func (*HttpContext) SetCookie2 ¶
func (t *HttpContext) SetCookie2(cookie *http.Cookie)
func (*HttpContext) Writer ¶
func (t *HttpContext) Writer() http.ResponseWriter
type HttpInfo ¶
type HttpInfo struct { // Path represents the target path of the request (e.g., "/index.html"). Path string // Uri represents the full Uniform Resource Identifier of the request. Uri string // Method indicates the type of HTTP method used for the request (e.g., "GET", "POST"). Method string // Host specifies the hostname or IP address of the server being requested, possibly including the port number. Host string // RemoteAddr specifies the network address of the client making the request, useful for logging or security purposes. RemoteAddr string // UserAgent describes the software (such as a browser version) that made the request. UserAgent string // Referer is the URL of the page that linked to the current page being requested. Referer string // Header is a map containing all the headers sent with the request, allowing multiple values per key. Header http.Header }
HttpInfo is a struct that represents the header information of an HTTP request.
type Tlnet ¶
func NewTlnet ¶
func NewTlnet() *Tlnet
NewTlnet creates and returns a new instance of Tlnet.
This function initializes all necessary fields of the Tlnet structure and sets default values, preparing it to handle HTTP requests and WebSocket connections. The returned Tlnet instance can be used to configure routes, handle requests, and manage connections.
func (*Tlnet) CONNECT ¶
func (t *Tlnet) CONNECT(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) DELETE ¶
func (t *Tlnet) DELETE(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) GET ¶
func (t *Tlnet) GET(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) HEAD ¶
func (t *Tlnet) HEAD(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) Handle ¶
func (t *Tlnet) Handle(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) HandleBinaryProcessor ¶ added in v0.1.1
func (t *Tlnet) HandleBinaryProcessor(pattern string, processor thrift.TProcessor)
HandleBinaryProcessor binary protocol
func (*Tlnet) HandleCompactProcessor ¶ added in v0.1.1
func (t *Tlnet) HandleCompactProcessor(pattern string, processor thrift.TProcessor)
HandleCompactProcessor compact protocol
func (*Tlnet) HandleFunc ¶ added in v0.1.1
func (t *Tlnet) HandleFunc(pattern string, f *Filter, handlerFunc func(http.ResponseWriter, *http.Request))
HandleFunc 处理动态请求
func (*Tlnet) HandleJsonProcessor ¶ added in v0.1.1
func (t *Tlnet) HandleJsonProcessor(pattern string, processor thrift.TProcessor)
HandleJsonProcessor json protocol
func (*Tlnet) HandleStatic ¶
func (t *Tlnet) HandleStatic(pattern, dir string, handlerctx func(hc *HttpContext))
func (*Tlnet) HandleStaticFunc ¶ added in v0.1.1
func (t *Tlnet) HandleStaticFunc(pattern string, dir string, f *Filter, handlerFunc func(http.ResponseWriter, *http.Request))
HandleStaticFunc 处理静态资源
func (*Tlnet) HandleStaticWithFilter ¶
func (t *Tlnet) HandleStaticWithFilter(pattern, dir string, _filter *Filter, handlerctx func(hc *HttpContext))
func (*Tlnet) HandleWebSocket ¶
func (t *Tlnet) HandleWebSocket(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) HandleWebSocketBindConfig ¶
func (t *Tlnet) HandleWebSocketBindConfig(pattern string, handlerctx func(hc *HttpContext), config *WebsocketConfig)
func (*Tlnet) HandleWebSocketBindOrigin ¶
func (t *Tlnet) HandleWebSocketBindOrigin(pattern, origin string, handlerctx func(hc *HttpContext))
func (*Tlnet) HandleWebSocketBindOriginFunc ¶
func (*Tlnet) HandleWithFilter ¶
func (t *Tlnet) HandleWithFilter(pattern string, _filter *Filter, handlerctx func(hc *HttpContext))
func (*Tlnet) HttpStart ¶
HttpStart
addr optionally specifies the TCP address for the server to listen on, in the form "host:port". If empty, ":http" (port 80) is used. The service names are defined in RFC 6335 and assigned by IANA. See net.Dial for details of the address format.
e.g.
1. HttpStart(":8080")
2. HttpStart("127.0.0.1:8080")
func (*Tlnet) HttpsStart ¶
HttpsStart
addr optionally specifies the TCP address for the server to listen on, in the form "host:port". If empty, ":http" (port 80) is used. The service names are defined in RFC 6335 and assigned by IANA. See net.Dial for details of the address format.
e.g.
1. HttpsStart(":8080","server_crt","server_key")
2. HttpsStart("127.0.0.1:8080","server_crt","server_key")
func (*Tlnet) HttpsStartWithBytes ¶
HttpsStartWithBytes
addr optionally specifies the TCP address for the server to listen on, in the form "host:port". If empty, ":http" (port 80) is used. The service names are defined in RFC 6335 and assigned by IANA. See net.Dial for details of the address format.
e.g.
1. HttpsStartWithBytes(":8080",[]byte(crtBytes),[]byte(keyBytes))
2. HttpsStartWithBytes("127.0.0.1:8080",[]byte(crtBytes),[]byte(keyBytes))
func (*Tlnet) IdleTimeout ¶
IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled. If IdleTimeout is zero, the value of ReadTimeout is used. If both are zero, there is no timeout.
func (*Tlnet) MaxHeaderBytes ¶
MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body. If zero, DefaultMaxHeaderBytes is used.
func (*Tlnet) OPTIONS ¶
func (t *Tlnet) OPTIONS(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) PATCH ¶
func (t *Tlnet) PATCH(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) POST ¶
func (t *Tlnet) POST(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) PUT ¶
func (t *Tlnet) PUT(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) ReadHeaderTimeout ¶
ReadHeaderTimeout is the amount of time allowed to read request headers. The connection's read deadline is reset after reading the headers and the Handler can decide what is considered too slow for the body. If ReadHeaderTimeout is zero, the value of ReadTimeout is used. If both are zero, there is no timeout.
func (*Tlnet) ReadTimeout ¶
ReadTimeout is the maximum duration for reading the entire request, including the body. A zero or negative value means there will be no timeout.
Because ReadTimeout does not let Handlers make per-request decisions on each request body's acceptable deadline or upload rate, most users will prefer to use ReadHeaderTimeout. It is valid to use them both.
func (*Tlnet) SetMaxBytesReader ¶
SetMaxBytesReader Sets the request body size limit
func (*Tlnet) TLSConfig ¶
TLSConfig optionally provides a TLS configuration for use by ServeTLS and ListenAndServeTLS. Note that t value is cloned by ServeTLS and ListenAndServeTLS, so it's not possible to modify the configuration with methods like tls.Config.SetSessionTicketKeys. To use SetSessionTicketKeys, use Server.Serve with a TLS Listener instead.
func (*Tlnet) TRACE ¶
func (t *Tlnet) TRACE(pattern string, handlerctx func(hc *HttpContext))
func (*Tlnet) UseServeMux ¶
UseServeMux use net/http ServeMux as an HTTP request multiplexer https://pkg.go.dev/net/http#ServeMux
func (*Tlnet) UseTlnetMux ¶
func (*Tlnet) UseTlnetMuxWithLimit ¶
func (*Tlnet) WriteTimeout ¶
WriteTimeout is the maximum duration before timing out writes of the response. It is reset whenever a new request's header is read. Like ReadTimeout, it does not let Handlers make decisions on a per-request basis. A zero or negative value means there will be no timeout.
type TlnetMux ¶
type TlnetMux interface { ServeHTTP(http.ResponseWriter, *http.Request) Handle(string, http.Handler) HandleFunc(string, func(http.ResponseWriter, *http.Request)) }
func NewTlnetMux ¶
func NewTlnetMux() TlnetMux