2018-12-11 22:01:50 +01:00
|
|
|
package local
|
2018-09-24 14:43:53 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-09-24 14:43:53 +02:00
|
|
|
"github.com/zrepl/zrepl/config"
|
2018-12-11 22:01:50 +01:00
|
|
|
"github.com/zrepl/zrepl/transport"
|
2018-09-24 14:43:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type LocalConnecter struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
listenerName string
|
2018-09-24 14:43:53 +02:00
|
|
|
clientIdentity string
|
|
|
|
}
|
|
|
|
|
|
|
|
func LocalConnecterFromConfig(in *config.LocalConnect) (*LocalConnecter, error) {
|
|
|
|
if in.ClientIdentity == "" {
|
|
|
|
return nil, fmt.Errorf("ClientIdentity must not be empty")
|
|
|
|
}
|
2018-10-11 13:06:47 +02:00
|
|
|
if in.ListenerName == "" {
|
|
|
|
return nil, fmt.Errorf("ListenerName must not be empty")
|
|
|
|
}
|
|
|
|
return &LocalConnecter{listenerName: in.ListenerName, clientIdentity: in.ClientIdentity}, nil
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-12-11 22:01:50 +01:00
|
|
|
func (c *LocalConnecter) Connect(dialCtx context.Context) (transport.Wire, error) {
|
|
|
|
l := GetLocalListener(c.listenerName)
|
2018-10-11 13:06:47 +02:00
|
|
|
return l.Connect(dialCtx, c.clientIdentity)
|
2018-09-24 14:43:53 +02:00
|
|
|
}
|