- Install the github.com/gorilla/mux package using the go get command, as follows:
$ go get github.com/gorilla/mux
- Create http-rest-get.go where we will define two routes—/employees and /employee/{id} along with their handlers. The former writes the static array of employees and the latter writes employee details for the provided ID to an HTTP response stream, as follows:
package mainimport ( "encoding/json" "log" "net/http" "github.com/gorilla/mux")const ( CONN_HOST = "localhost" CONN_PORT = "8080")type Route struct { Name string Method string Pattern string HandlerFunc http.HandlerFunc}type Routes []Routevar routes = Routes{ Route { "getEmployees", "GET", "/employees", getEmployees, }, Route { "getEmployee", "GET", "/employee/{id}", ...