go-emlid/reach/client/options.go

48 lines
1.0 KiB
Go

package client
import (
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
v1 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v1"
v2 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2"
)
type Options struct {
Protocols *protocol.Registry
PreferredProtocol protocol.Identifier
FallbackProtocol protocol.Identifier
}
type OptionFunc func(opts *Options)
func NewOptions(funcs ...OptionFunc) *Options {
opts := &Options{
PreferredProtocol: v2.Identifier,
FallbackProtocol: v1.Identifier,
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
}
}