Skip to content

Commit

Permalink
Have server endpoint ready for sns confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
joe94 committed Nov 13, 2017
1 parent 5bda297 commit b4f8799
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/tr1d1um/tr1d1um.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ func tr1d1um(arguments []string) (exitCode int) {

AddRoutes(baseRouter, preHandler, conversionHandler)

if exitCode = ConfigureWebHooks(baseRouter, r, preHandler, v, logger); exitCode != 0 {
var snsFactory *webhook.Factory

if snsFactory, exitCode = ConfigureWebHooks(baseRouter, r, preHandler, v, logger); exitCode != 0 {
return
}

Expand All @@ -116,6 +118,8 @@ func tr1d1um(arguments []string) (exitCode int) {
signals = make(chan os.Signal, 1)
)

go snsFactory.PrepareAndStart()

if err := concurrent.Await(tr1d1umServer, signals); err != nil {
fmt.Fprintf(os.Stderr, "Error when starting %s: %s", applicationName, err)
return 4
Expand All @@ -127,12 +131,12 @@ func tr1d1um(arguments []string) (exitCode int) {
//ConfigureWebHooks sets route paths, initializes and synchronizes hook registries for this tr1d1um instance
//baseRouter is pre-configured with the api/v2 prefix path
//root is the original router used by webHookFactory.Initialize()
func ConfigureWebHooks(baseRouter *mux.Router, root *mux.Router, preHandler *alice.Chain, v *viper.Viper, logger log.Logger) int {
func ConfigureWebHooks(baseRouter *mux.Router, root *mux.Router, preHandler *alice.Chain, v *viper.Viper, logger log.Logger) (*webhook.Factory, int) {
webHookFactory, err := webhook.NewFactory(v)

if err != nil {
fmt.Fprintf(os.Stderr, "Error creating new webHook factory: %s\n", err)
return 1
return nil, 1
}

webHookRegistry, webHookHandler := webHookFactory.NewRegistryAndHandler()
Expand All @@ -147,9 +151,7 @@ func ConfigureWebHooks(baseRouter *mux.Router, root *mux.Router, preHandler *ali
}

webHookFactory.Initialize(root, selfURL, webHookHandler, logger, nil)
webHookFactory.PrepareAndStart()

return 0
return webHookFactory, 0
}

//AddRoutes configures the paths and connection rules to TR1D1UM
Expand Down

0 comments on commit b4f8799

Please sign in to comment.