forked from golang-auth/go-gssapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
61 lines (45 loc) · 1.17 KB
/
registry.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2021 Jake Scott. All rights reserved.
// Use of this source code is governed by the Apache License
// version 2.0 that can be found in the LICENSE file.
package gssapi
import "strings"
type MechFactory func() Mech
var mechs map[string]MechFactory
func init() {
mechs = make(map[string]MechFactory)
}
// Register should be called by Mech implementations to enable
// a mechanism to be used by clients
func Register(name string, f MechFactory) {
name = strings.ToLower(name)
_, ok := mechs[name]
// can't register two mechs with the same name
if ok {
panic("Cannot have two mechs named " + name)
}
mechs[name] = f
}
// IsRegistered can be used to find out whether a named
// mechanism is registered or not
func IsRegistered(name string) bool {
name = strings.ToLower(name)
_, ok := mechs[name]
return ok
}
// NewMech returns a mechanism context by name
func NewMech(name string) Mech {
name = strings.ToLower(name)
f, ok := mechs[name]
if ok {
return f()
}
return nil
}
// Mechs returns the list of registered mechanism names
func Mechs() (l []string) {
l = make([]string, 0, len(mechs))
for name := range mechs {
l = append(l, name)
}
return
}