{"id":37098728,"url":"https://github.com/twiglab/twig","last_synced_at":"2026-01-14T12:00:42.989Z","repository":{"id":57485535,"uuid":"163139846","full_name":"twiglab/twig","owner":"twiglab","description":"Twig - less is more's web server for golang","archived":false,"fork":false,"pushed_at":"2019-07-14T03:15:26.000Z","size":225,"stargazers_count":99,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-15T09:15:43.998Z","etag":null,"topics":["framework","go","golang","goweb","http2","httpcontext","httpserver","mico","micorservice","middleware","muxer","router","twig","twig-server","webapi","webframework","webserver","websocket"],"latest_commit_sha":null,"homepage":"https://twig.twiglab.dev/doc/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twiglab.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}},"created_at":"2018-12-26T05:28:33.000Z","updated_at":"2024-02-06T09:41:40.000Z","dependencies_parsed_at":"2022-09-02T00:02:31.930Z","dependency_job_id":null,"html_url":"https://github.com/twiglab/twig","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/twiglab/twig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiglab%2Ftwig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiglab%2Ftwig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiglab%2Ftwig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiglab%2Ftwig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twiglab","download_url":"https://codeload.github.com/twiglab/twig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twiglab%2Ftwig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["framework","go","golang","goweb","http2","httpcontext","httpserver","mico","micorservice","middleware","muxer","router","twig","twig-server","webapi","webframework","webserver","websocket"],"created_at":"2026-01-14T12:00:39.059Z","updated_at":"2026-01-14T12:00:42.985Z","avatar_url":"https://github.com/twiglab.png","language":"Go","readme":"# twig\ntwig 是一个面向webapi的简单的webserver，Twig的目标是成为构建Golang微服务的基石\n\n\u003e Twig 采用QQ群提供技术支持，QQ群号：472900117\n\n## 性能测试\n\n```\ngoos: linux\ngoarch: amd64\npkg: web\nBenchmarkTwigStatic-2      \t   20000\t     71232 ns/op\t     870 B/op\t       0 allocs/op\nBenchmarkTwigGitHubAPI-2   \t   10000\t    101092 ns/op\t     878 B/op\t       0 allocs/op\nBenchmarkTwigGplusAPI-2    \t  300000\t      5613 ns/op\t      57 B/op\t       0 allocs/op\nBenchmarkTwigParseAPI-2    \t  200000\t     10660 ns/op\t     173 B/op\t       0 allocs/op\n\nBenchmarkEchoStatic-2      \t   20000\t     63527 ns/op\t    2126 B/op\t     157 allocs/op\nBenchmarkEchoGitHubAPI-2   \t   20000\t     91821 ns/op\t    2496 B/op\t     203 allocs/op\nBenchmarkEchoGplusAPI-2    \t  300000\t      5072 ns/op\t     161 B/op\t      13 allocs/op\nBenchmarkEchoParseAPI-2    \t  200000\t      9195 ns/op\t     381 B/op\t      26 allocs/op\n\nBenchmarkGinStatic-2       \t   20000\t     75786 ns/op\t    8405 B/op\t     157 allocs/op\nBenchmarkGinGitHubAPI-2    \t   10000\t    103458 ns/op\t   10619 B/op\t     203 allocs/op\nBenchmarkGinGplusAPI-2     \t  200000\t      6049 ns/op\t     710 B/op\t      13 allocs/op\nBenchmarkGinParseAPI-2     \t  200000\t     11559 ns/op\t    1421 B/op\t      26 allocs/op\nPASS\nok  \tweb\t24.538s\n```\n\n*Twig 比Gin更快，更好用!*\n\n## 安装\n\ngo get github.com/twiglab/twig\n\n*Twig 支持 go mod*\n\n## 入门\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/twiglab/twig\"\n)\n\nfunc main() {\n\tweb := twig.TODO()\n\tweb.AddServer(twig.NewServer(\":4321\")) // twig支持多server\n\n    // twig支持多路由， 在默认路由上增加handler\n\tweb.Config().\n\t\tGet(\"/hello\", func(c twig.Ctx) error {\n\t\t\treturn c.String(twig.OK, \"Hello Twig!\")\n\t\t})\n\n\tweb.Start()\n\n\ttwig.Signal(twig.Graceful(web, 15*time.Second), os.Interrupt)\n}\n```\n\n- Twig的默认监听端口是4321, 或者自定义自己的Server\n- 使用twig.TODO()创建`默认的`Twig，默认的Twig包括，默认的路由实现（RadixTree)，默认的Logger和默认的HttpErrorHandler\n- twig.Config是Twig提供的配置工具，Twig没有像别的webserver一样提供GET，POST等方法，所有的配置工作都通过Config完成\n- Twig要求所有的Server的实现必须是*非堵塞*的，Start方法将启动Twig，Twig提供了Signal组件用于堵塞应用，处理系统信号，完成和shell的交互\n\n\nTwig最大的特点是简洁，灵活，Twig的所有组建都以接口方式提供，支持重写，Twig也提供了Plugger模块，集成其他组建，用于增强Twig的功能\n\n\n至此讲述的内容，已经足够让您运行并使用Twig。 *祝您使用Twig愉快！*\n\n----\n\n## Twig的结构\n\nTwig 是一个仔细设计过的webserver， 与其他的webserver不同，Twig的设计的目标是成为 `构建应用程序的基石`\n\nTwig 的设计分为，核心，外围， 工具三个部分\n\n## 核心\n\nTwig 的核心组件包括：请求执行环境，服务器与连接器，日志，请求处理中间件，以及Twig本身\n\n连接器和服务器完成对网络协议处理构成请求，请求处理中间件负责对请求过滤执行，执行环境用于提供应用执行所需要的上下文，用于业务处理，Twig把所有的组建继承成为一个完整的应用\n\n### 服务器与连接器\n\n（coming soon...）\n\n### 请求执行环境\n\n请求执行环境的功能是为应用提供一个上下文（Ctx），有下列组件构成：\n\n- Lookuper（路由执行器）用于查找符合当前请求路径的handler，并返回执行环境Ctx\n- Ctx （执行上下文）提供请求上下文\n\n除此之外，执行环境还包括：\n\n- Register（注册器）提供handler注册功能，可以用Config工具进行配置\n- Muxer（路由器）描述接口\n- HandlerFunc（请求处理）\n\n执行环境的核心是Lookuper和Register 用于路由查找和路由注册（即Muxer接口）。Twig 通过路由查找器的Lookup方法查找并执行路由，返回Ctx，用于执行Handler\n\n\n---\n\nCtx和HandlerFunc\n\n### 中间件\n\n\n（coming soon...）\n\n## 插件 （Plugin）\n\n## 多Server支持\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwiglab%2Ftwig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwiglab%2Ftwig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwiglab%2Ftwig/lists"}