Example #1
0
// 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
}
Example #2
0
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
}