github.com/awesome-flow/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/corev1alpha1/actor/receiver_factory.go (about) 1 package actor 2 3 import ( 4 "fmt" 5 "strings" 6 7 core "github.com/awesome-flow/flow/pkg/corev1alpha1" 8 ) 9 10 func ReceiverFactory(name string, ctx *core.Context, params core.Params) (core.Actor, error) { 11 b, ok := params["bind"] 12 if !ok { 13 return nil, fmt.Errorf("receiver %q is missing `bind` config", name) 14 } 15 bind := b.(string) 16 var builder core.Builder 17 switch { 18 case strings.HasPrefix(bind, "tcp://"): 19 bind = bind[6:] 20 builder = NewReceiverTCP 21 case strings.HasPrefix(bind, "udp://"): 22 bind = bind[6:] 23 builder = NewReceiverUDP 24 case strings.HasPrefix(bind, "unix://"): 25 bind = bind[7:] 26 builder = NewReceiverUnix 27 case strings.HasPrefix(bind, "http://"): 28 bind = bind[7:] 29 builder = NewReceiverHTTP 30 default: 31 return nil, fmt.Errorf("receiver %q has unrecognised `bind` protocol: %q", name, bind) 32 } 33 34 params["bind"] = bind 35 36 return builder(name, ctx, params) 37 }