O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Activating the chat server

In the igweb.go source file, we have included a function called startChatHub, which is responsible for starting the Hub:

func startChatHub(hub *chat.Hub) {  go hub.Run()}

We add the following code in the main function to create a new chatbot, associate it with the Hub, and start the Hub:

  chatbot := bot.NewAgentCase()  hub := chat.NewHub(chatbot)  startChatHub(hub)

When we call the registerRoutes function to register all the routes for the server-side web application, note that we also pass in the hub value to the function:

  r := mux.NewRouter()  registerRoutes(&env, r, hub)

In the registerRoutes function, we need the hub to register the route handler for the Rest API endpoint that returns the agent's information:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required