diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-03-28 12:46:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 12:46:28 +0800 |
commit | 6526733a58632086d51ce7211b3a4dc75dbbef90 (patch) | |
tree | d4d00230c18e0b4bbae1a767ef3f52800d284a14 /services/auth/group.go | |
parent | d6fa138e7ce7c36ce253a3c847e3218fd31452c4 (diff) | |
download | gitea-6526733a58632086d51ce7211b3a4dc75dbbef90.tar.gz gitea-6526733a58632086d51ce7211b3a4dc75dbbef90.zip |
Let web and API routes have different auth methods group (#19168)
* remove the global methods but create dynamiclly
* Fix lint
* Fix windows lint
* Fix windows lint
* some improvements
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'services/auth/group.go')
-rw-r--r-- | services/auth/group.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/services/auth/group.go b/services/auth/group.go index bf047338bb..0f40e1a76c 100644 --- a/services/auth/group.go +++ b/services/auth/group.go @@ -6,6 +6,8 @@ package auth import ( "net/http" + "reflect" + "strings" "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" @@ -30,6 +32,24 @@ func NewGroup(methods ...Method) *Group { } } +// Add adds a new method to group +func (b *Group) Add(method Method) { + b.methods = append(b.methods, method) +} + +// Name returns group's methods name +func (b *Group) Name() string { + names := make([]string, 0, len(b.methods)) + for _, m := range b.methods { + if n, ok := m.(Named); ok { + names = append(names, n.Name()) + } else { + names = append(names, reflect.TypeOf(m).Elem().Name()) + } + } + return strings.Join(names, ",") +} + // Init does nothing as the Basic implementation does not need to allocate any resources func (b *Group) Init() error { for _, method := range b.methods { |