move init to options
This commit is contained in:
parent
c60b5a45bb
commit
64459c54a1
21
init/init.go
21
init/init.go
@ -1,21 +0,0 @@
|
||||
// Package init is an interface for initialising options
|
||||
package init
|
||||
|
||||
// Options is used for initialisation
|
||||
type Options interface {
|
||||
// Initialise options
|
||||
Init(...Option) error
|
||||
// Options returns the current options
|
||||
Options() Options
|
||||
// Value returns an option value
|
||||
Value(k interface{}) (interface{}, bool)
|
||||
// The name for who these options exist
|
||||
String() string
|
||||
}
|
||||
|
||||
// NewOptions returns a new initialiser
|
||||
func NewOptions(opts ...Option) Options {
|
||||
o := new(defaultOptions)
|
||||
o.Init(opts...)
|
||||
return o
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package init
|
||||
package options
|
||||
|
||||
type defaultOptions struct {
|
||||
opts *Values
|
@ -1,9 +1,21 @@
|
||||
package init
|
||||
package options
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Options is used for initialisation
|
||||
type Options interface {
|
||||
// Initialise options
|
||||
Init(...Option) error
|
||||
// Options returns the current options
|
||||
Options() Options
|
||||
// Value returns an option value
|
||||
Value(k interface{}) (interface{}, bool)
|
||||
// The name for who these options exist
|
||||
String() string
|
||||
}
|
||||
|
||||
// Values holds the set of option values and protects them
|
||||
type Values struct {
|
||||
sync.RWMutex
|
||||
@ -53,3 +65,10 @@ func WithOption(o Option) Option {
|
||||
func String(s string) Option {
|
||||
return WithValue(stringKey{}, s)
|
||||
}
|
||||
|
||||
// NewOptions returns a new initialiser
|
||||
func NewOptions(opts ...Option) Options {
|
||||
o := new(defaultOptions)
|
||||
o.Init(opts...)
|
||||
return o
|
||||
}
|
Loading…
Reference in New Issue
Block a user