// Receives a configuration struct and creates the relevant Handler func BuildHandlerFromConf(conf config.Handler, log logger.Logger) *Handler { var l Handler switch conf.GetType() { case "sqs": tl := &Sqs{Config: &appHandConfig.Sqs{}} tl.Log = log tl.Config.Init(conf.String()) l = tl case "lambda": tl := &Lambda{Config: &appHandConfig.Lambda{}} tl.Log = log tl.Config.Init(conf.String()) l = tl case "oauth2": tl := &OAuth2{Config: &appHandConfig.OAuth2{}} tl.Log = log tl.Config.Init(conf.String()) l = tl case "cli": tl := &Cli{Config: &appHandConfig.Cli{}} tl.Log = log tl.Config.Init(conf.String()) l = tl default: log.Warning("Could not create handler for type '%s'", conf.GetType()) return nil } return &l }
func BuildFromConf(conf appConfig.HandlerList, log logger.Logger) *HandlerList { hl := &HandlerList{ List: make(map[string]Handler), } for name, c := range conf { h := *BuildHandlerFromConf(&c, log) h.SetName(name) log.Debug("Created handler, %s, of type %s", h.GetName(), h.GetType()) hl.List[name] = h } return hl }
// Pass in the source configuration and this function both builds and starts listening to the source func StartSources(sourceConf *[]config.Source, rootList *listener.Listener, log logger.Logger, wg sync.WaitGroup) { log.Info("%d listeners to start", len(*sourceConf)) var wgLocal sync.WaitGroup var sources []Source for _, conf := range *sourceConf { tmp := BuildFromConfig(conf, rootList, log) sources = append(sources, tmp) wgLocal.Add(1) go tmp.Listen(wgLocal) } wgLocal.Wait() wg.Done() }
func BuildListener(conf config.ListenerList, hl *handler.HandlerList, log logger.Logger) *Listener { rootListener := Listener{} rootListener.Log = log rootListener.Name = "" for evtName, listners := range conf { log.Debug("Creating listeners for \"%s\": %q", evtName, listners) for _, l := range listners { h := hl.Get(l) if h == nil { log.Warning("Could not find handler with name '%s'", l) continue } rootListener.Add(evtName, h) } } return &rootListener }