MCPcopy Index your code
hub / github.com/dxvgef/tsing

github.com/dxvgef/tsing @v2.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.2.1 ↗ · + Follow
119 symbols 291 edges 6 files 82 documented · 69%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Tsing

Tsing是一个Go语言的HTTP API框架,具有以下功能特性: - 高性能,零内存分配 - 微核心,仅包含路由和会话管理两大模块 - 轻量,无第三方包依赖,兼容net/http标准包 - 可自动处理路由处理器中的Panic错误,防止进程退出 - 使用回调函数代替传统的内置Logger机掉,异常处理更灵活 - 支持后置回调处理器AfterHandler(仅在路由命中时有效)

Tsing是汉字【青】以及同音字做为名词时的英文,例如:清华大学(Tsinghua University)、青岛(Tsing Tao)。

已经在多个项目中稳定运行。

执行流程

  1. 根据URI查找路由
  2. 执行Use()方法注册的中间件
  3. 执行GET()等方法注册的路由处理器
  4. 执行AfterHandler后置处理器,无视之前处理器的执行结果

  5. 如果任意环节的处理器出现了以下情况,会中止执行后面的处理器

    • 处理器返回了error
    • 处理器中执行了Context.Break()
    • 处理器执行时触发了panic
  6. 如果路由未命中,只会执行ErrorHandler错误回调处理器,不会触发中间件和后置处理器

安装

要求:Go 1.18+

github.com/dxvgef/tsing/v2

示例

请参考/example_test.go文件

基准测试

测试代码:github.com/dxvgef/tsing-benchmark

Benchmark_TsingV2-8                        50865             23725 ns/op               0 B/op          0 allocs/op
Benchmark_TsingV2_Recover-8                48708             24582 ns/op               0 B/op          0 allocs/op
Benchmark_TsingV1-8                        48664             24875 ns/op               0 B/op          0 allocs/op
Benchmark_TsingV1_Recover-8                45986             26267 ns/op               0 B/op          0 allocs/op
Benchmark_Gin-8                            47978             24542 ns/op               0 B/op          0 allocs/op
Benchmark_Gin_Recover-8                    43753             27390 ns/op               0 B/op          0 allocs/op
Benchmark_Httprouter-8                     46738             25555 ns/op           13792 B/op        167 allocs/op
Benchmark_Httprouter_Recover-8             44786             26703 ns/op           13792 B/op        167 allocs/op
Benchmark_Echo-8                           38401             31216 ns/op               0 B/op          0 allocs/op
Benchmark_Echo_Recover-8                   28674             41750 ns/op            9748 B/op        203 allocs/op
Benchmark_HTTPTreemux-8                    15448             77755 ns/op           65857 B/op        671 allocs/op

相关资源

  • dxvgef/tsing-demo Tsing整合常见功能的示例项目,可以做为新项目初始化使用
  • dxvgef/filter 参数值过滤包,由数据输入、格式化、校验、输出几个部份组成
  • Tsing Gateway 跨平台、去中心化集群、动态配置的API网关
  • Tsing Center 跨平台、去中心化集群、动态配置的服务中心

用户案例

如果你在使用本项目,请通过Issues告知我们项目的简介

帮助反馈

本项目已在多个项目的生产环境中稳定运行。如有问题可在Issues里提出。

诚邀更多的开发者参与到本项目维护中,帮助这个开源项目更好的发展。

Extension points exported contracts — how you extend this code

Router (Interface)
Router 路由器接口,包括单路由和路由组 [1 implementers]
router.go
Handler (FuncType)
Handler 路由处理器
engine.go
Routes (Interface)
Routes 定义所有路由器接口
router.go
CallbackHandler (FuncType)
CallbackHandler 回调处理器
engine.go

Core symbols most depended-on inside this repo

ServeHTTP
called by 13
engine.go
New
called by 12
engine.go
GET
called by 9
router.go
handle
called by 9
router.go
strToBytes
called by 7
utils.go
Get
called by 5
tree.go
initQueryCache
called by 5
context.go
InitFormCache
called by 5
context.go

Shape

Method 76
Function 26
Struct 9
TypeAlias 4
FuncType 2
Interface 2

Languages

Go100%

Modules by API surface

context.go34 symbols
router.go33 symbols
tree.go19 symbols
example_test.go14 symbols
engine.go11 symbols
utils.go8 symbols

For agents

$ claude mcp add tsing \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page