Repository navigation
Expand file tree
/
Copy pathmodule.go
More file actions
86 lines (72 loc) · 2.31 KB
/
Copy pathmodule.go
File metadata and controls
86 lines (72 loc) · 2.31 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package auth
import (
"github.com/gin-gonic/gin"
)
var registeredModules = make(map[string]Module)
// Moduler should be implemented by all the authboss modules.
type Module func(auth *Engine) gin.HandlerFunc
// RegisterModule with the core providing all the necessary information to
// integrate into authboss.
func RegisterModule(name string, m Module) {
registeredModules[name] = m
}
// RegisteredModules returns a list of modules that are currently registered.
func RegisteredModules() []string {
mods := make([]string, len(registeredModules))
i := 0
for k := range registeredModules {
mods[i] = k
i++
}
return mods
}
// LoadedModules returns a list of modules that are currently loaded.
func (a *Engine) LoadedModules() []string {
mods := make([]string, len(registeredModules))
i := 0
for k := range registeredModules {
mods[i] = k
i++
}
return mods
}
// IsLoaded checks if a specific module is loaded.
func (a *Engine) IsLoaded(mod string) bool {
_, ok := registeredModules[mod]
return ok
}
// ModuleListMiddleware puts a map in the data that can be used
// to provide the renderer with information about which pieces of the
// views to show. The bool is extraneous, as presence in the map is
// the indication of wether or not the module is loaded.
// Data looks like:
// map[modulename] = true
//
// oauth2 providers are also listed here using the syntax:
// oauth2.google for an example. Be careful since this doesn't actually mean
// that the oauth2 module has been loaded so you should do a conditional
// that checks for both.
// func ModuleListMiddleware(ab *Engine) func(http.Handler) http.Handler {
// return func(next http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// var data HTMLData
// ctx := r.Context()
// dataIntf := ctx.Value(CTXKeyData)
// if dataIntf != nil {
// data = dataIntf.(HTMLData)
// } else {
// data = HTMLData{}
// }
// loaded := make(map[string]bool, len(ab.loadedModules))
// for k := range ab.loadedModules {
// loaded[k] = true
// }
// for provider := range ab.Config.Modules.OAuth2Providers {
// loaded["oauth2."+provider] = true
// }
// data[DataModules] = loaded
// r = r.WithContext(context.WithValue(ctx, CTXKeyData, data))
// next.ServeHTTP(w, r)
// })
// }
// }