-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
51 lines (43 loc) · 1.11 KB
/
utils.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
package ore
import (
"fmt"
"strings"
)
type specialContextKey string
type specialOreKey int
type contextKey struct {
typeID
containerID int32
resolverID int
}
type typeID struct {
pointerTypeName pointerTypeName
oreKey any //comparable
}
type pointerTypeName string
func (this *Container) clearAll() {
this.resolvers = make(map[typeID][]serviceResolver)
this.aliases = make(map[pointerTypeName][]pointerTypeName)
this.isSealed = false
this.DisableValidation = false
}
func clearAll() {
DefaultContainer.clearAll()
}
// Get type name of *T.
// it allocates less memory and is faster than `reflect.TypeFor[*T]().String()`
func getPointerTypeName[T any]() pointerTypeName {
var mockValue *T
return pointerTypeName(fmt.Sprintf("%T", mockValue))
}
func getUnderlyingTypeName(ptn pointerTypeName) string {
s := string(ptn)
index := strings.Index(s, "*")
if index == -1 {
return s // no '*' found, return the original string
}
return s[:index] + s[index+1:]
}
func (this typeID) String() string {
return fmt.Sprintf("(name={%s}, key='%s')", getUnderlyingTypeName(this.pointerTypeName), this.oreKey)
}