go-emlid/reach/client/options.go

42 lines
848 B
Go
Raw Normal View History

2024-07-30 14:28:39 +02:00
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
}
}