Skip to content

Commit b9abe9b

Browse files
committed
EntryDecorator 支持链式调用
1 parent 2c16993 commit b9abe9b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

http/router/entry.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,27 @@ func (e *Entry) AddLabel(labels ...*Label) EntryDecorator {
2121
}
2222

2323
// EnableAuth 启动身份验证
24-
func (e *Entry) EnableAuth() {
24+
func (e *Entry) EnableAuth() EntryDecorator {
2525
e.AuthEnable = true
26+
return e
2627
}
2728

2829
// DisableAuth 不启用身份验证
29-
func (e *Entry) DisableAuth() {
30+
func (e *Entry) DisableAuth() EntryDecorator {
3031
e.AuthEnable = false
32+
return e
3133
}
3234

3335
// EnablePermission 启用授权验证
34-
func (e *Entry) EnablePermission() {
36+
func (e *Entry) EnablePermission() EntryDecorator {
3537
e.PermissionEnable = true
38+
return e
3639
}
3740

3841
// DisablePermission 禁用授权验证
39-
func (e *Entry) DisablePermission() {
42+
func (e *Entry) DisablePermission() EntryDecorator {
4043
e.PermissionEnable = false
44+
return e
4145
}
4246

4347
// NewEntrySet 实例

http/router/router.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type SubRouter interface {
7070
type EntryDecorator interface {
7171
// SetLabel 设置子路由标签, 作用于Entry上
7272
AddLabel(...*Label) EntryDecorator
73-
EnableAuth()
74-
DisableAuth()
75-
EnablePermission()
76-
DisablePermission()
73+
EnableAuth() EntryDecorator
74+
DisableAuth() EntryDecorator
75+
EnablePermission() EntryDecorator
76+
DisablePermission() EntryDecorator
7777
}

0 commit comments

Comments
 (0)