post image January 6, 2022 | 1 min Read

Go using DefaultMux with nil

package main

import (
	"io"
	"net/http"
)

type pageDog int

func (pd pageDog) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "This is the web about dogs!\n")
}

type pageCat []string

func (pc pageCat) ServeHTTP(w http.ResponseWriter, r *http.Request)  {
	io.WriteString(w, "This is the web about cats!\n")
}

func main() {

	var dogs pageDog
	var cats pageCat

	http.Handle("/dogs/", dogs)
	http.Handle("/cats", cats)

	http.ListenAndServe(":8080", nil)

}

author image

Jan Toth

I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …

comments powered by Disqus