mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user