Steps

1- import or make sure net/http package is listed in the imports section.

2- Define your function handler and the logic inside it.

3- Register your handler with the http.HandleFunc function by specifying also the path.

4- Start your server by using http.ListenAndServe function. Define your port and the Multiplexer (DefaultServeMux)

http.HandleFunc

DefaultServeMux initialization

ServeMux is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL.

ListenAndServe Definition

Handler Interface

ServeMux implementing Handler Interface

http Package Main Components Diagram

Gorilla Mux General Conception

Negroni

Negroni Handler Function Example

Questions

Are you ready?

1- Crea un multiplexer que pueda atender tres solicitudes:

/fibonacci?n=<<number>> 

/factorial?n=<<number>>
/palindrome?word=<<word>>

2- Crea los respectivos handlers para atender cada solicitud.

3- Retorna  404 para aquellas solicitudes que no cumplan con el formato de las tres operaciones.

Thanks

MicroServerOnGo

By Larry Morales

MicroServerOnGo

An introduction to develop a simple and small server using Go.

  • 742