mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-10 00:08:14 +01:00
31 lines
758 B
Go
31 lines
758 B
Go
package connecter
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zrepl/zrepl/config"
|
|
"github.com/zrepl/zrepl/daemon/transport/serve"
|
|
"net"
|
|
)
|
|
|
|
type LocalConnecter struct {
|
|
listenerName string
|
|
clientIdentity string
|
|
}
|
|
|
|
func LocalConnecterFromConfig(in *config.LocalConnect) (*LocalConnecter, error) {
|
|
if in.ClientIdentity == "" {
|
|
return nil, fmt.Errorf("ClientIdentity must not be empty")
|
|
}
|
|
if in.ListenerName == "" {
|
|
return nil, fmt.Errorf("ListenerName must not be empty")
|
|
}
|
|
return &LocalConnecter{listenerName: in.ListenerName, clientIdentity: in.ClientIdentity}, nil
|
|
}
|
|
|
|
func (c *LocalConnecter) Connect(dialCtx context.Context) (conn net.Conn, err error) {
|
|
l := serve.GetLocalListener(c.listenerName)
|
|
return l.Connect(dialCtx, c.clientIdentity)
|
|
}
|
|
|