forked from forgejo/forgejo
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>
This commit is contained in:
parent
d6fa138e7c
commit
6526733a58
10 changed files with 140 additions and 80 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue