tlnet

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: BSD-3-Clause Imports: 22 Imported by: 9

README

tlnet Lightweight high-performance http service framework [中文文档]

Function Description

  1. Ease of Use: Similar in style to the built-in http, but simpler to use.
  2. Efficiency: Provides extremely high performance thanks to a routing algorithm based on caching and trees.
  3. Basic Routing: Supports common HTTP methods (GET, POST, PUT, DELETE, PATCH, etc.).
  4. Interceptors: Supports interceptors, including URL interception based on regex matching.
  5. WebSocket: Supports WebSocket with the same simplicity as regular HTTP services.
  6. Static File Service: Allows setting paths to serve static files, with interceptor support for static services.
  7. RESTful: Supports building RESTful API services, such as /path/:id/:name/order.
  8. Wildcards: Supports using wildcards to define routes, such as /path/*/order.
  9. Thrift: Supports Thrift HTTP protocol services.
  10. Lightweight: Quick to start, minimal resource usage, no redundant features.

GitHub Repository

Applicable Scenarios

  1. If you are looking for a more efficient and lightweight HTTP framework compared to gin, echo, or native http, tlnet is a great choice. It provides fundamental HTTP service functionality with good scalability, stability, and high concurrency support. Due to tlnet’s cache and tree-based implementation, routing has an average time complexity of O(1), offering better performance than traditional tree structures.
  2. tlnet is well-suited for building high-performance, lightweight web applications, APIs, or microservices.
  3. tlnet does not include full-stack development features. For scenarios that require a lot of built-in features, complex business logic, and full-stack development support, frameworks like Beego or Revel might offer more comprehensive functionality.

Quick Start

Installation

go get github.com/donnie4w/tlnet

Example 1:

tl := NewTlnet()
tl.GET("/g", getHandle)
tl.HttpStart(":8000")

func getHandle(hc *HttpContext) {
    hc.ResponseString("hello tlnet")
}

Example 2:

tl := NewTlnet()
tl.POST("/p", postHandle)   // POST request
tl.HandleStatic("/js/", "/html/js", nil) // Set up static resource service
tl.HttpStart(":8000")

func postHandle(hc *HttpContext) {
    hc.ResponseString("hello tlnet")
}

Example 3:

tl := NewTlnet()
tl.GET("/user/:id/:name/order", userOrderHandler)   // RESTful API
tl.HttpStart(":8000")

func userOrderHandler(hc *HttpContext) {
    hc.ResponseString(hc.GetParam("id") + ":" + hc.GetParam("name"))
}

Interceptor Use Case:

tl := NewTlnet()
tl.HandleWithFilter("/", interceptFilter(), func(hc *HttpContext) {hc.ResponseString("uri:"+hc.ReqInfo.Uri)})  // General HTTP handling with an interceptor
tl.HandleStaticWithFilter("/js/", "/html/js", interceptFilter(), nil)
tl.HttpStart(":8000")

func interceptFilter() *Filter {
    f := NewFilter()
    // Built-in suffix interceptor
    f.AddSuffixIntercept([]string{".jpg"}, func(hc *HttpContext) bool {
        logging.Debug("suffix path:" + hc.ReqInfo.Path)
        return false
    })
    // Built-in "page not found" interceptor
    f.AddPageNotFoundIntercept(func(hc *HttpContext) bool {
        hc.Error("page not found:" + hc.ReqInfo.Uri, http.StatusNotFound)
        return true
    })
    // Custom URL regex matching interceptor
    f.AddIntercept(".*?", func(hc *HttpContext) bool {
        logging.Debug("intercept:", hc.ReqInfo.Uri)
        if hc.ReqInfo.Path == "" {
            hc.Error("path is empty:" + hc.ReqInfo.Uri, http.StatusForbidden)
            return true
        }
        return false
    })
    return f
}

Basic WebSocket Usage:

func TestWebsocket(t *testing.T) {
    tl := NewTlnet()
    tl.HandleWebSocket("/ws", websocketHandler)
    tl.HttpStart(":8000")
}

func websocketHandler(hc *HttpContext) {
    wsId := hc.WS.Id // Each WebSocket connection generates a unique ID
    msg := string(hc.WS.Read()) // Read client request data
    hc.WS.Send("Service ID " + fmt.Sprint(wsId) + " received your message: " + msg) // Respond to client
}

Additional tlnet Functionality Examples:

SetLogger(true) // Enable logging, disabled by default

tl := NewTlnet() // Create a Tlnet instance

tl.SetMaxBytesReader(1 << 20)  // Set the maximum HTTP request data limit to 1 MB

tl.HandleWebSocketBindOrigin("/ws", "http://tlnet.top/", websocketFunc)  // Define Origin as http://tlnet.top/

tl.HandleWebSocketBindConfig("/ws", websocketFunc, newWebsocketConfig()) // Define config for WebSocket error handling, connection success, etc.

tl.ReadTimeout(10 * time.Second) // Set read timeout

tl.HttpsStart(":8000", certFile, keyFile)  // Start HTTPS service with certFile (certificate path) and keyFile (key path)

tl.HttpsStartWithBytes(":8000", certFileBs, keyFileBs) // Start HTTPS service with certFileBs (certificate data) and keyFileBs (key data)

tl.Close()  // Close the Tlnet instance service

Tlnet Performance

tlnet vs. native http vs. gin vs. echo

《Tlnet Performance Benchmark: tlnet vs gin vs echo vs native http》

Benchmark Program Repository

URL processor has been registered, that is, the URL can be found
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2356797               507.6 ns/op          1040 B/op          9 allocs/op
BenchmarkGin-8           2428094               500.5 ns/op          1040 B/op          9 allocs/op
BenchmarkHttp
BenchmarkHttp-4          3405583               346.5 ns/op           344 B/op          9 allocs/op
BenchmarkHttp-8          3551180               330.7 ns/op           344 B/op          9 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         6224007               187.6 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         6570204               184.3 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          2333074               535.3 ns/op          1024 B/op         10 allocs/op
BenchmarkEcho-8          2366791               528.6 ns/op          1024 B/op         10 allocs/op
PASS
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2290322               494.4 ns/op          1040 B/op          9 allocs/op
BenchmarkGin-8           2491639               487.8 ns/op          1040 B/op          9 allocs/op
BenchmarkGin-16          2560693               493.1 ns/op          1041 B/op          9 allocs/op
BenchmarkHttp
BenchmarkHttp-4          3565180               323.4 ns/op           344 B/op          9 allocs/op
BenchmarkHttp-8          3544458               339.9 ns/op           344 B/op          9 allocs/op
BenchmarkHttp-16         3596947               307.0 ns/op           344 B/op          9 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         5572468               189.7 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         6420810               189.5 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-16        5862798               197.4 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          2356166               504.5 ns/op          1024 B/op         10 allocs/op
BenchmarkEcho-8          2238975               540.4 ns/op          1024 B/op         10 allocs/op
BenchmarkEcho-16         1740646               639.0 ns/op          1024 B/op         10 allocs/op
PASS
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2445027               484.4 ns/op          1040 B/op          9 allocs/op
BenchmarkGin-8           2465703               489.2 ns/op          1040 B/op          9 allocs/op
BenchmarkGin-16          2567120               462.3 ns/op          1040 B/op          9 allocs/op
BenchmarkHttp
BenchmarkHttp-4          3700851               332.5 ns/op           344 B/op          9 allocs/op
BenchmarkHttp-8          3507562               385.1 ns/op           344 B/op          9 allocs/op
BenchmarkHttp-16         3458373               318.5 ns/op           344 B/op          9 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         7283329               166.9 ns/op           288 B/op          6 allocs/op
BenchmarkTlnet-8         7045941               163.3 ns/op           288 B/op          6 allocs/op
BenchmarkTlnet-16        7091187               162.7 ns/op           288 B/op          6 allocs/op
BenchmarkEcho
BenchmarkEcho-4          2395107               501.3 ns/op          1024 B/op         10 allocs/op
BenchmarkEcho-8          2230350               541.2 ns/op          1024 B/op         10 allocs/op
BenchmarkEcho-16         2118523               571.2 ns/op          1025 B/op         10 allocs/op

URL processor is not registered, that is, the URL can be found
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2695962               436.6 ns/op           992 B/op          8 allocs/op
BenchmarkGin-8           2682855               448.6 ns/op           992 B/op          8 allocs/op
BenchmarkGin-16          2692042               456.7 ns/op           993 B/op          8 allocs/op
BenchmarkHttp
BenchmarkHttp-4          1462479               806.5 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-8          1378512               868.7 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-16         1359558               898.3 ns/op          1201 B/op         19 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         6343191               182.1 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         6371780               193.3 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-16        6292598               182.6 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          1387812               854.2 ns/op          1489 B/op         16 allocs/op
BenchmarkEcho-8          1000000              1031 ns/op            1489 B/op         16 allocs/op
BenchmarkEcho-16          871554              1220 ns/op            1491 B/op         16 allocs/op
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2695962               436.6 ns/op           992 B/op          8 allocs/op
BenchmarkGin-8           2682855               448.6 ns/op           992 B/op          8 allocs/op
BenchmarkGin-16          2692042               456.7 ns/op           993 B/op          8 allocs/op
BenchmarkHttp
BenchmarkHttp-4          1462479               806.5 ns/op           1200 B/op         19 allocs/op
BenchmarkHttp-8          1378512               868.7 ns/op           1200 B/op         19 allocs/op
BenchmarkHttp-16         1359558               898.3 ns/op           1201 B/op         19 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         6343191               182.1 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         6371780               193.3 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-16        6292598               182.6 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          1387812               854.2 ns/op           1489 B/op         16 allocs/op
BenchmarkEcho-8          1000000               1031 ns/op            1489 B/op         16 allocs/op
BenchmarkEcho-16          871554               1220 ns/op            1491 B/op         16 allocs/op
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2758132               436.3 ns/op           992 B/op          8 allocs/op
BenchmarkGin-8           2667070               447.5 ns/op           992 B/op          8 allocs/op
BenchmarkGin-16          2778464               423.7 ns/op           992 B/op          8 allocs/op
BenchmarkHttp
BenchmarkHttp-4          1484661               809.1 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-8          1470441               831.8 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-16         1466318               841.5 ns/op          1201 B/op         19 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         6568359               178.0 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         6523093               185.5 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-16        6733190               172.9 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          1412888               828.2 ns/op          1488 B/op         16 allocs/op
BenchmarkEcho-8          1404442               892.6 ns/op          1489 B/op         16 allocs/op
BenchmarkEcho-16         1306354               932.2 ns/op          1491 B/op         16 allocs/op
goarch: amd64
pkg: test/httpserver
cpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
BenchmarkGin
BenchmarkGin-4           2715367               441.7 ns/op           992 B/op          8 allocs/op
BenchmarkGin-8           2552917               463.5 ns/op           992 B/op          8 allocs/op
BenchmarkGin-16          2607180               448.3 ns/op           993 B/op          8 allocs/op
BenchmarkHttp
BenchmarkHttp-4          1500954               808.5 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-8          1417261               861.2 ns/op          1200 B/op         19 allocs/op
BenchmarkHttp-16         1334204               899.6 ns/op          1201 B/op         19 allocs/op
BenchmarkTlnet
BenchmarkTlnet-4         6459314               182.8 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-8         5938984               195.5 ns/op           288 B/op          5 allocs/op
BenchmarkTlnet-16        6510511               191.6 ns/op           288 B/op          5 allocs/op
BenchmarkEcho
BenchmarkEcho-4          1414153               840.8 ns/op          1489 B/op         16 allocs/op
BenchmarkEcho-8          1344892               896.2 ns/op          1489 B/op         16 allocs/op
BenchmarkEcho-16         1244558              1139 ns/op            1490 B/op         16 allocs/op

Documentation

Index

Constants

View Source
const (
	JSON tf_pco_type
	BINARY
	COMPACT
)
View Source
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

func ParseFormFile(file multipart.File, fileHeader *multipart.FileHeader, savePath, namePrefix string) (fileName string, err error)

func SetLogger

func SetLogger(on bool)

Types

type Filter

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

func NewFilter

func NewFilter() *Filter

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) FormFiles

func (t *HttpContext) FormFiles(key string) *multipart.Form

func (*HttpContext) GetCookie

func (t *HttpContext) GetCookie(name string) (_r string, err 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) Redirect

func (t *HttpContext) Redirect(path string)

Redirect 重定向 302

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

type Tlnet struct {
	Server *http.Server
	// contains filtered or unexported fields
}

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) Close

func (t *Tlnet) Close() (err error)

Close close tlnet service

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 (t *Tlnet) HandleWebSocketBindOriginFunc(pattern string, handlerctx func(hc *HttpContext), originFunc func(origin *url.URL) bool)

func (*Tlnet) HandleWithFilter

func (t *Tlnet) HandleWithFilter(pattern string, _filter *Filter, handlerctx func(hc *HttpContext))

func (*Tlnet) HttpStart

func (t *Tlnet) HttpStart(addr string) (err error)

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

func (t *Tlnet) HttpsStart(addr string, server_crt, server_key string) (err error)

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

func (t *Tlnet) HttpsStartWithBytes(addr string, crtBytes, keyBytes []byte) (err error)

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

func (t *Tlnet) IdleTimeout(idleTimeout time.Duration)

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

func (t *Tlnet) MaxHeaderBytes(maxHeaderBytes int)

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

func (t *Tlnet) ReadHeaderTimeout(readHeaderTimeout time.Duration)

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

func (t *Tlnet) ReadTimeout(readTimeout time.Duration)

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

func (t *Tlnet) SetMaxBytesReader(maxBytes int64)

SetMaxBytesReader Sets the request body size limit

func (*Tlnet) TLSConfig

func (t *Tlnet) TLSConfig(tlsConfig *tls.Config)

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

func (t *Tlnet) UseServeMux() *Tlnet

UseServeMux use net/http ServeMux as an HTTP request multiplexer https://pkg.go.dev/net/http#ServeMux

func (*Tlnet) UseTlnetMux

func (t *Tlnet) UseTlnetMux() *Tlnet

func (*Tlnet) UseTlnetMuxWithLimit

func (t *Tlnet) UseTlnetMuxWithLimit(limit int) *Tlnet

func (*Tlnet) WriteTimeout

func (t *Tlnet) WriteTimeout(writeTimeout time.Duration)

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

func NewTlnetMuxWithLimit

func NewTlnetMuxWithLimit(limit int) TlnetMux

type Websocket

type Websocket struct {
	Id int64

	Conn  *websocket.Conn
	Error error
	// contains filtered or unexported fields
}

func (*Websocket) Close

func (t *Websocket) Close() (err error)

func (*Websocket) Read

func (t *Websocket) Read() []byte

func (*Websocket) Send

func (t *Websocket) Send(v any) (err error)

type WebsocketConfig

type WebsocketConfig struct {
	Origin          string
	OriginFunc      func(origin *url.URL) bool
	MaxPayloadBytes int
	OnError         func(self *Websocket)
	OnOpen          func(hc *HttpContext)
}

Directories

Path Synopsis
db module

Jump to

Keyboard shortcuts

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