Skip to content

Commit

Permalink
feat(middlewares): 添加 empty 中间件
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed May 31, 2024
1 parent 1786836 commit 85304cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
- access 客户端访问记录;
- health 接口状态的监测;
- compress 根据 CPU 使用率决定是否启用压缩功能;
- locales 加载本地化的文件资源;

## 中间件

Expand All @@ -37,6 +36,7 @@
- auth/jwt JSON Web Tokens 中间件;
- auth/session session 管理;
- auth/token 传统方式的令牌管理;
- empty 提供了一个不作任何操作的中间件;
- skip 根据条件跳过路由的执行;

## 安装
Expand Down
15 changes: 15 additions & 0 deletions middlewares/empty/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2024 caixw
//
// SPDX-License-Identifier: MIT

// Package empty 提供了一个不做任务附加操作的中间件
package empty

import "github.com/issue9/web"

// Empty 一个不做任何操作的中间件
//
// 在某些情况下需要保持中间件的变量是非空的值,可以采用此对象。
type Empty struct{}

func (m Empty) Middleware(next web.HandlerFunc, _, _, _ string) web.HandlerFunc { return next }
9 changes: 9 additions & 0 deletions middlewares/empty/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2024 caixw
//
// SPDX-License-Identifier: MIT

package empty

import "github.com/issue9/web"

var _ web.Middleware = &Empty{}

0 comments on commit 85304cb

Please sign in to comment.