Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0bbfd6d02 | |||
2cb6843773 | |||
87e1480077 | |||
bcd7f6a551 | |||
925b3af46b | |||
ef4efa6a6b | |||
125646d89b | |||
7af7649448 |
@@ -25,6 +25,7 @@ func NewOptions(opts ...Option) Options {
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Name string
|
||||
// Issuer of the service's account
|
||||
Issuer string
|
||||
// ID is the services auth ID
|
||||
@@ -63,6 +64,13 @@ func Addrs(addrs ...string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
||||
// Issuer of the services account
|
||||
func Issuer(i string) Option {
|
||||
return func(o *Options) {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package codec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
@@ -40,7 +41,7 @@ func (c *noopCodec) ReadBody(conn io.Reader, b interface{}) error {
|
||||
case *Frame:
|
||||
v.Data = buf
|
||||
default:
|
||||
return ErrInvalidMessage
|
||||
return json.Unmarshal(buf, v)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -64,7 +65,11 @@ func (c *noopCodec) Write(conn io.Writer, m *Message, b interface{}) error {
|
||||
case []byte:
|
||||
v = vb
|
||||
default:
|
||||
return ErrInvalidMessage
|
||||
var err error
|
||||
v, err = json.Marshal(vb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err := conn.Write(v)
|
||||
return err
|
||||
@@ -98,30 +103,34 @@ func (c *noopCodec) Marshal(v interface{}) ([]byte, error) {
|
||||
case *Message:
|
||||
return ve.Body, nil
|
||||
}
|
||||
return nil, ErrInvalidMessage
|
||||
|
||||
return json.Marshal(v)
|
||||
}
|
||||
|
||||
func (c *noopCodec) Unmarshal(d []byte, v interface{}) error {
|
||||
var err error
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
switch ve := v.(type) {
|
||||
case string:
|
||||
ve = string(d)
|
||||
return nil
|
||||
case *string:
|
||||
*ve = string(d)
|
||||
return nil
|
||||
case []byte:
|
||||
ve = d
|
||||
return nil
|
||||
case *[]byte:
|
||||
*ve = d
|
||||
return nil
|
||||
case *Frame:
|
||||
ve.Data = d
|
||||
return nil
|
||||
case *Message:
|
||||
ve.Body = d
|
||||
default:
|
||||
err = ErrInvalidMessage
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
return json.Unmarshal(d, v)
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ var (
|
||||
|
||||
// Config is an interface abstraction for dynamic configuration
|
||||
type Config interface {
|
||||
Name() string
|
||||
// Init the config
|
||||
Init(opts ...Option) error
|
||||
// Options in the config
|
||||
|
@@ -251,6 +251,10 @@ func (c *defaultConfig) String() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func (c *defaultConfig) Name() string {
|
||||
return c.opts.Name
|
||||
}
|
||||
|
||||
func NewConfig(opts ...Option) Config {
|
||||
options := NewOptions(opts...)
|
||||
if len(options.StructTag) == 0 {
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Name string
|
||||
AllowFail bool
|
||||
BeforeLoad []func(context.Context, Config) error
|
||||
AfterLoad []func(context.Context, Config) error
|
||||
@@ -116,3 +117,10 @@ func StructTag(name string) Option {
|
||||
o.StructTag = name
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ type Option func(*Options)
|
||||
|
||||
// Options holds logger options
|
||||
type Options struct {
|
||||
Name string
|
||||
// The logging level the logger should log at. default is `InfoLevel`
|
||||
Level Level
|
||||
// fields to always be logged
|
||||
@@ -72,3 +73,10 @@ func WithContext(ctx context.Context) Option {
|
||||
o.Context = ctx
|
||||
}
|
||||
}
|
||||
|
||||
// WithName sets the name
|
||||
func withName(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
@@ -93,3 +93,10 @@ func Label(key, val string) Option {
|
||||
o.Labels.vals = append(o.Labels.vals, val)
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Name string
|
||||
// Addrs is the list of intermediary addresses to connect to
|
||||
Addrs []string
|
||||
// Codec is the codec interface to use where headers are not supported
|
||||
@@ -176,3 +177,10 @@ func Tracer(t tracer.Tracer) Option {
|
||||
o.Tracer = t
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ type Option func(*Options)
|
||||
|
||||
// Options provides network configuration options
|
||||
type Options struct {
|
||||
Name string
|
||||
// Id is tunnel id
|
||||
Id string
|
||||
// Address is tunnel address
|
||||
@@ -181,3 +182,10 @@ func Tracer(t tracer.Tracer) Option {
|
||||
o.Tracer = t
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
40
options.go
40
options.go
@@ -134,6 +134,14 @@ func BrokerServer(n string) BrokerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// Client to be used for service
|
||||
func Client(c ...client.Client) Option {
|
||||
return func(o *Options) error {
|
||||
o.Clients = c
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Clients to be used for service
|
||||
func Clients(c ...client.Client) Option {
|
||||
return func(o *Options) error {
|
||||
@@ -161,6 +169,14 @@ func Profile(p profile.Profile) Option {
|
||||
}
|
||||
*/
|
||||
|
||||
// Server to be used for service
|
||||
func Server(s ...server.Server) Option {
|
||||
return func(o *Options) error {
|
||||
o.Servers = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Servers to be used for service
|
||||
func Servers(s ...server.Server) Option {
|
||||
return func(o *Options) error {
|
||||
@@ -169,6 +185,14 @@ func Servers(s ...server.Server) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Store sets the store to use
|
||||
func Store(s ...store.Store) Option {
|
||||
return func(o *Options) error {
|
||||
o.Stores = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Stores sets the store to use
|
||||
func Stores(s ...store.Store) Option {
|
||||
return func(o *Options) error {
|
||||
@@ -275,6 +299,14 @@ func LoggerServer(n string) LoggerOption {
|
||||
}
|
||||
*/
|
||||
|
||||
// Meter set the meter to use
|
||||
func Meter(m ...meter.Meter) Option {
|
||||
return func(o *Options) error {
|
||||
o.Meters = m
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Meters set the meter to use
|
||||
func Meters(m ...meter.Meter) Option {
|
||||
return func(o *Options) error {
|
||||
@@ -450,6 +482,14 @@ func Auth(a auth.Auth) Option {
|
||||
}
|
||||
*/
|
||||
|
||||
// Config sets the config for the service
|
||||
func Config(c ...config.Config) Option {
|
||||
return func(o *Options) error {
|
||||
o.Configs = c
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Configs sets the configs for the service
|
||||
func Configs(c ...config.Config) Option {
|
||||
return func(o *Options) error {
|
||||
|
@@ -246,13 +246,13 @@ func DeregisterDomain(d string) DeregisterOption {
|
||||
}
|
||||
}
|
||||
|
||||
func GetContext(ctx context.Context) LookupOption {
|
||||
func LookupContext(ctx context.Context) LookupOption {
|
||||
return func(o *LookupOptions) {
|
||||
o.Context = ctx
|
||||
}
|
||||
}
|
||||
|
||||
func GetDomain(d string) LookupOption {
|
||||
func LookupDomain(d string) LookupOption {
|
||||
return func(o *LookupOptions) {
|
||||
o.Domain = d
|
||||
}
|
||||
@@ -269,3 +269,10 @@ func ListDomain(d string) ListOption {
|
||||
o.Domain = d
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
@@ -91,6 +91,13 @@ func Meter(m meter.Meter) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Name the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
||||
// Tracer sets the tracer
|
||||
func Tracer(t tracer.Tracer) Option {
|
||||
return func(o *Options) {
|
||||
|
@@ -53,3 +53,10 @@ func NewOptions(opts ...Option) Options {
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// Name sets the name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user