{"id":42545870,"url":"https://github.com/donnie4w/tlnet","last_synced_at":"2026-01-28T18:42:15.368Z","repository":{"id":65265941,"uuid":"589134762","full_name":"donnie4w/tlnet","owner":"donnie4w","description":"Lightweight high-performance http service framework","archived":false,"fork":false,"pushed_at":"2025-01-15T02:47:13.000Z","size":4614,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-15T04:02:20.717Z","etag":null,"topics":["golang","http-server","tlnet","web","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/donnie4w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-15T07:03:19.000Z","updated_at":"2025-01-15T02:45:08.000Z","dependencies_parsed_at":"2024-04-17T05:28:29.208Z","dependency_job_id":"4af0cfa3-8c86-4fa2-bffe-6b9b13fd08a4","html_url":"https://github.com/donnie4w/tlnet","commit_stats":{"total_commits":56,"total_committers":1,"mean_commits":56.0,"dds":0.0,"last_synced_commit":"8071ff2ed5a040145aebb426e1503f2bc71009c1"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/donnie4w/tlnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnie4w%2Ftlnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnie4w%2Ftlnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnie4w%2Ftlnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnie4w%2Ftlnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donnie4w","download_url":"https://codeload.github.com/donnie4w/tlnet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnie4w%2Ftlnet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28849160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","http-server","tlnet","web","websocket-server"],"created_at":"2026-01-28T18:42:11.050Z","updated_at":"2026-01-28T18:42:15.360Z","avatar_url":"https://github.com/donnie4w.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### tlnet   Lightweight high-performance http service framework [[中文文档]](https://github.com/donnie4w/tlnet/blob/main/README_zh.md \"[中文文档]\")\n\n### Function Description\n\n1. **Ease of Use**: Similar in style to the built-in `http`, but simpler to use.\n2. **Efficiency**: Provides extremely high performance thanks to a routing algorithm based on caching and trees.\n3. **Basic Routing**: Supports common HTTP methods (GET, POST, PUT, DELETE, PATCH, etc.).\n4. **Interceptors**: Supports interceptors, including URL interception based on regex matching.\n5. **WebSocket**: Supports WebSocket with the same simplicity as regular HTTP services.\n6. **Static File Service**: Allows setting paths to serve static files, with interceptor support for static services.\n7. **RESTful**: Supports building RESTful API services, such as `/path/:id/:name/order`.\n8. **Wildcards**: Supports using wildcards to define routes, such as `/path/*/order`.\n9. **Thrift**: Supports Thrift HTTP protocol services.\n10. **Lightweight**: Quick to start, minimal resource usage, no redundant features.\n\n### [GitHub Repository](http://github.com/donnie4w/tlnet \"GitHub Repository\")\n\n### Applicable Scenarios\n\n1. 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.\n2. `tlnet` is well-suited for building high-performance, lightweight web applications, APIs, or microservices.\n3. `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.\n\n------\n\n# Quick Start\n\n### Installation\n\n```bash\ngo get github.com/donnie4w/tlnet\n```\n\n#### Example 1:\n\n```go\ntl := NewTlnet()\ntl.GET(\"/g\", getHandle)\ntl.HttpStart(\":8000\")\n\nfunc getHandle(hc *HttpContext) {\n    hc.ResponseString(\"hello tlnet\")\n}\n```\n\n#### Example 2:\n\n```go\ntl := NewTlnet()\ntl.POST(\"/p\", postHandle)   // POST request\ntl.HandleStatic(\"/js/\", \"/html/js\", nil) // Set up static resource service\ntl.HttpStart(\":8000\")\n\nfunc postHandle(hc *HttpContext) {\n    hc.ResponseString(\"hello tlnet\")\n}\n```\n\n#### Example 3:\n\n```go\ntl := NewTlnet()\ntl.GET(\"/user/:id/:name/order\", userOrderHandler)   // RESTful API\ntl.HttpStart(\":8000\")\n\nfunc userOrderHandler(hc *HttpContext) {\n    hc.ResponseString(hc.GetParam(\"id\") + \":\" + hc.GetParam(\"name\"))\n}\n```\n\n### Interceptor Use Case:\n\n```go\ntl := NewTlnet()\ntl.HandleWithFilter(\"/\", interceptFilter(), func(hc *HttpContext) {hc.ResponseString(\"uri:\"+hc.ReqInfo.Uri)})  // General HTTP handling with an interceptor\ntl.HandleStaticWithFilter(\"/js/\", \"/html/js\", interceptFilter(), nil)\ntl.HttpStart(\":8000\")\n\nfunc interceptFilter() *Filter {\n    f := NewFilter()\n    // Built-in suffix interceptor\n    f.AddSuffixIntercept([]string{\".jpg\"}, func(hc *HttpContext) bool {\n        logging.Debug(\"suffix path:\" + hc.ReqInfo.Path)\n        return false\n    })\n    // Built-in \"page not found\" interceptor\n    f.AddPageNotFoundIntercept(func(hc *HttpContext) bool {\n        hc.Error(\"page not found:\" + hc.ReqInfo.Uri, http.StatusNotFound)\n        return true\n    })\n    // Custom URL regex matching interceptor\n    f.AddIntercept(\".*?\", func(hc *HttpContext) bool {\n        logging.Debug(\"intercept:\", hc.ReqInfo.Uri)\n        if hc.ReqInfo.Path == \"\" {\n            hc.Error(\"path is empty:\" + hc.ReqInfo.Uri, http.StatusForbidden)\n            return true\n        }\n        return false\n    })\n    return f\n}\n```\n\n### Basic WebSocket Usage:\n\n```go\nfunc TestWebsocket(t *testing.T) {\n    tl := NewTlnet()\n    tl.HandleWebSocket(\"/ws\", websocketHandler)\n    tl.HttpStart(\":8000\")\n}\n\nfunc websocketHandler(hc *HttpContext) {\n    wsId := hc.WS.Id // Each WebSocket connection generates a unique ID\n    msg := string(hc.WS.Read()) // Read client request data\n    hc.WS.Send(\"Service ID \" + fmt.Sprint(wsId) + \" received your message: \" + msg) // Respond to client\n}\n```\n\n### Additional `tlnet` Functionality Examples:\n\n```go\nSetLogger(true) // Enable logging, disabled by default\n\ntl := NewTlnet() // Create a Tlnet instance\n\ntl.SetMaxBytesReader(1 \u003c\u003c 20)  // Set the maximum HTTP request data limit to 1 MB\n\ntl.HandleWebSocketBindOrigin(\"/ws\", \"http://tlnet.top/\", websocketFunc)  // Define Origin as http://tlnet.top/\n\ntl.HandleWebSocketBindConfig(\"/ws\", websocketFunc, newWebsocketConfig()) // Define config for WebSocket error handling, connection success, etc.\n\ntl.ReadTimeout(10 * time.Second) // Set read timeout\n\ntl.HttpsStart(\":8000\", certFile, keyFile)  // Start HTTPS service with certFile (certificate path) and keyFile (key path)\n\ntl.HttpsStartWithBytes(\":8000\", certFileBs, keyFileBs) // Start HTTPS service with certFileBs (certificate data) and keyFileBs (key data)\n\ntl.Close()  // Close the Tlnet instance service\n```\n\n------------\n\n### Tlnet Performance\n\n#### `tlnet` vs. `native http` vs. `gin` vs. `echo`\n\n[《Tlnet Performance Benchmark: tlnet vs gin vs echo vs native http》](https://tlnet.top/article/22425190)\n\n[Benchmark Program Repository](https://github.com/donnie4w/test/tree/main/httpserver)\n\n\n##### URL processor has been registered, that is, the URL can be found\n```text\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2356797               507.6 ns/op          1040 B/op          9 allocs/op\nBenchmarkGin-8           2428094               500.5 ns/op          1040 B/op          9 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          3405583               346.5 ns/op           344 B/op          9 allocs/op\nBenchmarkHttp-8          3551180               330.7 ns/op           344 B/op          9 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         6224007               187.6 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         6570204               184.3 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          2333074               535.3 ns/op          1024 B/op         10 allocs/op\nBenchmarkEcho-8          2366791               528.6 ns/op          1024 B/op         10 allocs/op\nPASS\n```\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2290322               494.4 ns/op          1040 B/op          9 allocs/op\nBenchmarkGin-8           2491639               487.8 ns/op          1040 B/op          9 allocs/op\nBenchmarkGin-16          2560693               493.1 ns/op          1041 B/op          9 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          3565180               323.4 ns/op           344 B/op          9 allocs/op\nBenchmarkHttp-8          3544458               339.9 ns/op           344 B/op          9 allocs/op\nBenchmarkHttp-16         3596947               307.0 ns/op           344 B/op          9 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         5572468               189.7 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         6420810               189.5 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-16        5862798               197.4 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          2356166               504.5 ns/op          1024 B/op         10 allocs/op\nBenchmarkEcho-8          2238975               540.4 ns/op          1024 B/op         10 allocs/op\nBenchmarkEcho-16         1740646               639.0 ns/op          1024 B/op         10 allocs/op\nPASS\n```\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2445027               484.4 ns/op          1040 B/op          9 allocs/op\nBenchmarkGin-8           2465703               489.2 ns/op          1040 B/op          9 allocs/op\nBenchmarkGin-16          2567120               462.3 ns/op          1040 B/op          9 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          3700851               332.5 ns/op           344 B/op          9 allocs/op\nBenchmarkHttp-8          3507562               385.1 ns/op           344 B/op          9 allocs/op\nBenchmarkHttp-16         3458373               318.5 ns/op           344 B/op          9 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         7283329               166.9 ns/op           288 B/op          6 allocs/op\nBenchmarkTlnet-8         7045941               163.3 ns/op           288 B/op          6 allocs/op\nBenchmarkTlnet-16        7091187               162.7 ns/op           288 B/op          6 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          2395107               501.3 ns/op          1024 B/op         10 allocs/op\nBenchmarkEcho-8          2230350               541.2 ns/op          1024 B/op         10 allocs/op\nBenchmarkEcho-16         2118523               571.2 ns/op          1025 B/op         10 allocs/op\n```\n------\n\n##### URL processor is not registered, that is, the URL can be found\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2695962               436.6 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-8           2682855               448.6 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-16          2692042               456.7 ns/op           993 B/op          8 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          1462479               806.5 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-8          1378512               868.7 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-16         1359558               898.3 ns/op          1201 B/op         19 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         6343191               182.1 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         6371780               193.3 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-16        6292598               182.6 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          1387812               854.2 ns/op          1489 B/op         16 allocs/op\nBenchmarkEcho-8          1000000              1031 ns/op            1489 B/op         16 allocs/op\nBenchmarkEcho-16          871554              1220 ns/op            1491 B/op         16 allocs/op\n```\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2695962               436.6 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-8           2682855               448.6 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-16          2692042               456.7 ns/op           993 B/op          8 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          1462479               806.5 ns/op           1200 B/op         19 allocs/op\nBenchmarkHttp-8          1378512               868.7 ns/op           1200 B/op         19 allocs/op\nBenchmarkHttp-16         1359558               898.3 ns/op           1201 B/op         19 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         6343191               182.1 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         6371780               193.3 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-16        6292598               182.6 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          1387812               854.2 ns/op           1489 B/op         16 allocs/op\nBenchmarkEcho-8          1000000               1031 ns/op            1489 B/op         16 allocs/op\nBenchmarkEcho-16          871554               1220 ns/op            1491 B/op         16 allocs/op\n```\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2758132               436.3 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-8           2667070               447.5 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-16          2778464               423.7 ns/op           992 B/op          8 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          1484661               809.1 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-8          1470441               831.8 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-16         1466318               841.5 ns/op          1201 B/op         19 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         6568359               178.0 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         6523093               185.5 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-16        6733190               172.9 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          1412888               828.2 ns/op          1488 B/op         16 allocs/op\nBenchmarkEcho-8          1404442               892.6 ns/op          1489 B/op         16 allocs/op\nBenchmarkEcho-16         1306354               932.2 ns/op          1491 B/op         16 allocs/op\n```\n\n```text\ngoarch: amd64\npkg: test/httpserver\ncpu: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz\nBenchmarkGin\nBenchmarkGin-4           2715367               441.7 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-8           2552917               463.5 ns/op           992 B/op          8 allocs/op\nBenchmarkGin-16          2607180               448.3 ns/op           993 B/op          8 allocs/op\nBenchmarkHttp\nBenchmarkHttp-4          1500954               808.5 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-8          1417261               861.2 ns/op          1200 B/op         19 allocs/op\nBenchmarkHttp-16         1334204               899.6 ns/op          1201 B/op         19 allocs/op\nBenchmarkTlnet\nBenchmarkTlnet-4         6459314               182.8 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-8         5938984               195.5 ns/op           288 B/op          5 allocs/op\nBenchmarkTlnet-16        6510511               191.6 ns/op           288 B/op          5 allocs/op\nBenchmarkEcho\nBenchmarkEcho-4          1414153               840.8 ns/op          1489 B/op         16 allocs/op\nBenchmarkEcho-8          1344892               896.2 ns/op          1489 B/op         16 allocs/op\nBenchmarkEcho-16         1244558              1139 ns/op            1490 B/op         16 allocs/op\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnie4w%2Ftlnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonnie4w%2Ftlnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnie4w%2Ftlnet/lists"}