-
Notifications
You must be signed in to change notification settings - Fork 99
/
provider.go
47 lines (40 loc) · 996 Bytes
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package auth
import "fmt"
// Provider define Provider interface
type Provider interface {
GetName() string
ConfigAuth(*Auth)
Login(*Context)
Logout(*Context)
Register(*Context)
Callback(*Context)
ServeHTTP(*Context)
}
// RegisterProvider register auth provider
func (auth *Auth) RegisterProvider(provider Provider) {
name := provider.GetName()
for _, p := range auth.providers {
if p.GetName() == name {
fmt.Printf("warning: auth provider %v already registered", name)
return
}
}
provider.ConfigAuth(auth)
auth.providers = append(auth.providers, provider)
}
// GetProvider get provider with name
func (auth *Auth) GetProvider(name string) Provider {
for _, provider := range auth.providers {
if provider.GetName() == name {
return provider
}
}
return nil
}
// GetProviders return registered providers
func (auth *Auth) GetProviders() (providers []Provider) {
for _, provider := range auth.providers {
providers = append(providers, provider)
}
return
}