fix: protocol v1

This commit is contained in:
2024-08-02 12:57:07 +02:00
parent 8f89ed7e77
commit b976bde363
23 changed files with 392 additions and 85 deletions

View File

@ -2,6 +2,9 @@ package protocol
import (
"context"
"log/slog"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
)
type Identifier string
@ -11,3 +14,29 @@ type Protocol interface {
Available(ctx context.Context, addr string) (bool, error)
Operations(addr string) Operations
}
type ProtocolOptions struct {
Logger logger.Logger
}
type ProtocolFactory func(opts *ProtocolOptions) (Protocol, error)
type ProtocolOptionFunc func(opts *ProtocolOptions)
func NewProtocolOptions(funcs ...ProtocolOptionFunc) *ProtocolOptions {
opts := &ProtocolOptions{
Logger: slog.Default(),
}
for _, fn := range funcs {
fn(opts)
}
return opts
}
func WithProtocolLogger(logger logger.Logger) ProtocolOptionFunc {
return func(opts *ProtocolOptions) {
opts.Logger = logger
}
}