This commit is contained in:
Jeffrey Duroyon
2019-04-04 14:29:48 +02:00
committed by Jeffrey Duroyon
parent 0df6d64c35
commit 33db360b03
38 changed files with 1476 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
package utils
import "fmt"
type Injector struct {
content map[string]any
}
func (i *Injector) Get(key string) any {
val, ok := i.content[key]
if !ok {
panic(fmt.Sprintf("Can't get key %s from injector", key))
}
return val
}
func Get[T any](i *Injector, key string) T {
return i.Get(key).(T)
}
func (i *Injector) Set(key string, content any) {
if i.content == nil {
i.content = map[string]any{}
}
_, ok := i.content[key]
if ok {
panic(fmt.Sprintf("Key %s already have content", key))
}
i.content[key] = content
}