I am creating a module which will provide a http.Handler
that can be attached to any running server.
My module has a lot of bundled handlerFunc
s for handling internal requests:
func NewHandler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/one", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("one"))
})
mux.HandleFunc("/two", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("two"))
})
return mux
}
This handler can be attached to a custom path:
package main
import (
"net/http"
"github.com/someuser/someproject"
)
func main() {
http.Handle("/path", someproject.NewHandler())
http.ListenAndServe(":8080", nil)
}
On request invocation to http://localhost:8080/path/one
I get 404
. What am I doing wrong?