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
|
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package options
import (
"fmt"
"strings"
)
type (
Factory func() Interface
Factories map[string]Factory
)
var factories = make(Factories, 10)
func GetFactories() Factories {
return factories
}
func RegisterFactory(name string, factory Factory) {
name = strings.ToLower(name)
factories[name] = factory
}
func GetFactory(name string) Factory {
name = strings.ToLower(name)
factory, ok := factories[name]
if !ok {
panic(fmt.Errorf("no options factory registered for %s", name))
}
return factory
}
|