github.com/whiteboxio/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/corev1alpha1/actor/sink_head_factory.go (about)

     1  package actor
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"strings"
     7  
     8  	core "github.com/awesome-flow/flow/pkg/corev1alpha1"
     9  )
    10  
    11  type SinkHead interface {
    12  	core.Runner
    13  	Write([]byte) (int, error, bool)
    14  	Connect() error
    15  }
    16  
    17  func SinkHeadFactory(params core.Params) (SinkHead, error) {
    18  	b, ok := params["bind"]
    19  	if !ok {
    20  		return nil, fmt.Errorf("missing `bind` config")
    21  	}
    22  	bind := b.(string)
    23  	if strings.HasPrefix(bind, "tcp://") {
    24  		tcpaddr, err := net.ResolveTCPAddr("tcp", bind[6:])
    25  		if err != nil {
    26  			return nil, err
    27  		}
    28  		return NewSinkHeadTCP(tcpaddr)
    29  	} else if strings.HasPrefix(bind, "udp://") {
    30  		udpaddr, err := net.ResolveUDPAddr("udp", bind[6:])
    31  		if err != nil {
    32  			return nil, err
    33  		}
    34  		return NewSinkHeadUDP(udpaddr)
    35  	} else if strings.HasPrefix(bind, "unix://") {
    36  		unixaddr, err := net.ResolveUnixAddr("unix", bind[7:])
    37  		if err != nil {
    38  			return nil, err
    39  		}
    40  		return NewSinkHeadUnix(unixaddr)
    41  	} else if strings.HasPrefix(bind, "file://") {
    42  		return NewSinkHeadFile(bind[7:])
    43  	}
    44  
    45  	return nil, fmt.Errorf("unrecognised address format: %q", bind)
    46  }