I am using gorilla/mux router
but it gives me error cannot use listContainers(docker) (type http.Handler) as type func(http.ResponseWriter, *http.Request) in argument to router.HandleFunc
func listContainers(client *client.Client) http.Handler {
docker := client
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
log.Println(“Listing containers”)
containers, err := docker.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
w.Header().Set(“Content-Type”, “application/json”)
json.NewEncoder(w).Encode(containers)
})
}
func ContainerHandler(router *mux.Router) {
DOCKER_HOST := “unix://var/run/docker.sock”
DOCKER_API_VERSION := “1.40”
docker, err := client.NewClient(DOCKER_HOST, DOCKER_API_VERSION, nil, nil)
if err != nil {
panic(err)
}
log.Println(“Successfully Connected to Docker Daemon”)
router.HandleFunc(“/containers/list”, listContainers(docker))
}