42 lines
848 B
Go
42 lines
848 B
Go
|
package client
|
||
|
|
||
|
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||
|
|
||
|
type Options struct {
|
||
|
Protocols *protocol.Registry
|
||
|
PreferredProtocol protocol.Identifier
|
||
|
FallbackProtocol protocol.Identifier
|
||
|
}
|
||
|
|
||
|
type OptionFunc func(opts *Options)
|
||
|
|
||
|
func NewOptions(funcs ...OptionFunc) *Options {
|
||
|
opts := &Options{
|
||
|
Protocols: protocol.DefaultRegistry(),
|
||
|
}
|
||
|
|
||
|
for _, fn := range funcs {
|
||
|
fn(opts)
|
||
|
}
|
||
|
|
||
|
return opts
|
||
|
}
|
||
|
|
||
|
func WithPreferredProtocol(identifier protocol.Identifier) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.PreferredProtocol = identifier
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithFallbackProtocol(identifier protocol.Identifier) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.FallbackProtocol = identifier
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithProtocols(protocols *protocol.Registry) OptionFunc {
|
||
|
return func(opts *Options) {
|
||
|
opts.Protocols = protocols
|
||
|
}
|
||
|
}
|