From 64459c54a1faf223efec573a6f98c32dca6b2b61 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Jun 2019 17:54:30 +0100 Subject: [PATCH] move init to options --- init/init.go | 21 --------------------- {init => options}/default.go | 2 +- {init => options}/options.go | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 init/init.go rename {init => options}/default.go (97%) rename {init => options}/options.go (69%) diff --git a/init/init.go b/init/init.go deleted file mode 100644 index a9db1ebc..00000000 --- a/init/init.go +++ /dev/null @@ -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 -} diff --git a/init/default.go b/options/default.go similarity index 97% rename from init/default.go rename to options/default.go index 97d26e35..7b236db2 100644 --- a/init/default.go +++ b/options/default.go @@ -1,4 +1,4 @@ -package init +package options type defaultOptions struct { opts *Values diff --git a/init/options.go b/options/options.go similarity index 69% rename from init/options.go rename to options/options.go index ad99a056..830adea8 100644 --- a/init/options.go +++ b/options/options.go @@ -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 +}