一个多层次的可扩展Go HTTP框架
Find a file
dependabot[bot] 26eef27929
build(deps): bump golang.org/x/net from 0.53.0 to 0.56.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.53.0 to 0.56.0.
- [Commits](https://github.com/golang/net/compare/v0.53.0...v0.56.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.56.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-11 00:33:10 +00:00
.github Update test.yml 2026-03-28 01:34:45 +08:00
docs docs: 添加 httpc 集成文档和示例 2026-04-22 07:13:55 +08:00
examples fix: 修复 examples/httpc 中 c.String 非常量 format string 编译错误 2026-04-22 08:51:42 +08:00
licenses fix cfdt 2025-07-25 00:35:12 +08:00
.gitignore fix: streamline route matcher backtracking 2026-04-07 08:27:00 +08:00
about-touka.md feat: redesign server startup around Run options 2026-04-07 17:44:55 +08:00
adapter.go feat: add MPL 2.0 license headers to all go files 2025-07-24 08:07:38 +00:00
compat.go fix: 修正 GetHTTPC 注释中方法名 typo 2026-04-22 09:37:45 +08:00
context.go fix: Client()/HTTPC() 优先使用 per-request HTTPClient 字段 2026-04-22 09:17:02 +08:00
context_benchmark_test.go perf: reuse reverse proxy copy buffers 2026-04-10 06:08:55 +08:00
context_bodylimit_test.go fix(maxreader): treat non-positive limits as unlimited 2026-04-01 00:03:23 +08:00
context_httpc.go feat: httpc 集成改进,自动关联请求 Context 2026-04-21 22:55:26 +08:00
ecw.go fix(reverseproxy): align forwarding and tunnel semantics 2026-04-02 03:18:49 +08:00
ecw_benchmark_test.go perf: reuse reverse proxy copy buffers 2026-04-10 06:08:55 +08:00
engine.go feat: 引入 Logger 接口抽象,支持自定义日志实现 2026-04-21 19:43:56 +08:00
engine_benchmark_test.go fix: cut redirect and allow-path routing overhead 2026-04-07 09:06:56 +08:00
engine_test.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
fileserver.go fix StaticFS 2025-09-14 08:24:01 +08:00
go.mod build(deps): bump golang.org/x/net from 0.53.0 to 0.56.0 2026-06-11 00:33:10 +00:00
go.sum build(deps): bump golang.org/x/net from 0.53.0 to 0.56.0 2026-06-11 00:33:10 +00:00
http2xconnect.go refactor: improve TLS config handling and add bridge connection tests 2026-04-02 22:13:50 +08:00
iox_benchmark_test.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
LICENSE updaten license 2025-06-10 21:39:37 +08:00
logger.go feat: 引入 Logger 接口抽象,支持自定义日志实现 2026-04-21 19:43:56 +08:00
logreco.go feat: 引入 Logger 接口抽象,支持自定义日志实现 2026-04-21 19:43:56 +08:00
maxreader.go fix(maxreader): treat non-positive limits as unlimited 2026-04-01 00:03:23 +08:00
mergectx.go fix: orDone 使用 sync.Once 修复 close(done) 竞态条件 2026-04-22 09:37:19 +08:00
mergectx_test.go improve: MergeCtx 支持 cause 传播, 使用 WithCancelCause/WithDeadlineCause 2026-04-22 08:43:36 +08:00
midware_x.go feat: add MPL 2.0 license headers to all go files 2025-07-24 08:07:38 +00:00
path.go feat: add MPL 2.0 license headers to all go files 2025-07-24 08:07:38 +00:00
path_test.go use new resolveRoutePath replace path.Join && add UseIf 2025-06-17 14:20:14 +08:00
protocols_test.go feat: redesign server startup around Run options 2026-04-07 17:44:55 +08:00
README.md feat: redesign server startup around Run options 2026-04-07 17:44:55 +08:00
recovery.go refactor: improve binding, performance, and type safety 2026-03-17 12:02:49 +08:00
respw.go fix(reverseproxy): align forwarding and tunnel semantics 2026-04-02 03:18:49 +08:00
reverseproxy.go fix: address PR review for replacer — nil check, EscapedPath, scheme reuse, perf 2026-04-21 18:02:57 +08:00
reverseproxy_benchmark_test.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
reverseproxy_headers_replace_test.go feat: implement dynamic request variable replacement in replacer 2026-04-21 17:36:38 +08:00
reverseproxy_headers_test.go feat: add headers operations for reverse proxy 2026-04-21 16:34:25 +08:00
reverseproxy_lb.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
reverseproxy_test.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
route_match_benchmark_test.go fix: streamline route matcher backtracking 2026-04-07 08:27:00 +08:00
serve.go fix: preserve IPv6 brackets in redirects 2026-04-07 20:31:10 +08:00
serve_test.go perf: modernize io paths and reduce proxy allocations 2026-04-11 01:43:34 +08:00
sse.go fix(SSE): capture Writer before goroutine, use select for channel send 2026-03-29 16:50:37 +08:00
sse_test.go fix(SSE): capture Writer before goroutine, use select for channel send 2026-03-29 16:50:37 +08:00
testutil.go feat: add MPL 2.0 license headers to all go files 2025-07-24 08:07:38 +00:00
touka.go feat: add redirect host selection options 2026-04-07 19:49:13 +08:00
tree.go fix: avoid unsafe header buffer reuse 2026-04-07 09:32:14 +08:00
tree_test.go fix: streamline route matcher backtracking 2026-04-07 08:27:00 +08:00

Touka(灯花)框架

Touka(灯花) 是一个基于 Go 语言构建的多层次、高性能 Web 框架。其设计目标是为开发者提供更直接的控制、有效的扩展能力,以及针对特定场景的行为优化

文档

我们提供了详尽的文档来帮助您快速上手并深入了解 Touka

快速上手

package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/fenthope/reco"
	"github.com/infinite-iroha/touka"
)

func main() {
	r := touka.Default() // 使用带 Recovery 中间件的默认引擎

	// 配置日志记录器 (可选)
	logConfig := reco.Config{
		Level:      reco.LevelDebug,
		Mode:       reco.ModeText,
		Output:     os.Stdout,
		Async:      true,
	}
	r.SetLoggerCfg(logConfig)

	// 配置统一错误处理器
	r.SetErrorHandler(func(c *touka.Context, code int, err error) {
		c.JSON(code, touka.H{"error_code": code, "message": http.StatusText(code)})
		c.GetLogger().Errorf("发生HTTP错误: %d, 路径: %s, 错误: %v", code, c.Request.URL.Path, err)
	})

	// 注册路由
	r.GET("/hello/:name", func(c *touka.Context) {
		name := c.Param("name")
		query := c.DefaultQuery("mood", "happy")
		c.String(http.StatusOK, "Hello, %s! You seem %s.", name, query)
	})

	// 启动服务器(通过 WithGracefulShutdown 启用优雅关闭)
	log.Println("Touka Server starting on :8080...")
	if err := r.Run(touka.WithAddr(":8080"), touka.WithGracefulShutdown(10*time.Second)); err != nil {
		log.Fatalf("Touka server failed to start: %v", err)
	}
}

中间件支持

内置

  • Recovery: r.Use(touka.Recovery()) (已包含在 touka.Default() 中)

第三方 (fenthope)

贡献

我们欢迎任何形式的贡献,无论是错误报告、功能建议还是代码提交。请遵循项目的贡献指南。

相关项目

  • gin: Touka 在路由和 API 设计上参考了 Gin。
  • reco: Touka 框架的默认日志库。
  • httpc: 一个现代化且易用的 HTTP Client作为 Touka 框架 Context 携带的 HTTPC。

许可证

本项目基于 Mozilla Public License, v. 2.0 许可。

tree.go 部分代码源自 ginhttprouter,其原始许可为 BSD-style。