diff --git a/Makefile b/Makefile index 1a056242..6d91237b 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go go build $(BUILD_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) -$(WEAVER_EXE): router/*.go ipam/*.go ipam/*/*.go nameserver/*.go prog/weaver/main.go +$(WEAVER_EXE): router/*.go ipam/*.go ipam/*/*.go nameserver/*.go prog/weaver/*.go $(WEAVEPROXY_EXE): proxy/*.go prog/weaveproxy/main.go $(NETCHECK_EXE): prog/netcheck/netcheck.go diff --git a/prog/weaver/http.go b/prog/weaver/http.go new file mode 100644 index 00000000..e26a27c9 --- /dev/null +++ b/prog/weaver/http.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "github.com/gorilla/mux" + "github.com/weaveworks/weave/ipam" + "github.com/weaveworks/weave/nameserver" + "github.com/weaveworks/weave/net/address" + weave "github.com/weaveworks/weave/router" + "net/http" +) + +func HandleHTTP(muxRouter *mux.Router, + router *weave.Router, + allocator *ipam.Allocator, + defaultSubnet address.CIDR, + ns *nameserver.Nameserver, + dnsserver *nameserver.DNSServer) { + + muxRouter.Methods("GET").Path("/status").Headers("Accept", "application/json").HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + json, _ := router.StatusJSON(version) + w.Header().Set("Content-Type", "application/json") + w.Write(json) + }) + + muxRouter.Methods("GET").Path("/status").HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "weave router", version) + fmt.Fprintln(w, router.Status()) + if allocator != nil { + fmt.Fprintln(w, allocator.String()) + fmt.Fprintln(w, "Allocator default subnet:", defaultSubnet) + } + fmt.Fprintln(w, "") + if dnsserver == nil { + fmt.Fprintln(w, "WeaveDNS is disabled") + } else { + fmt.Fprintln(w, dnsserver.String()) + fmt.Fprintln(w, ns.String()) + } + }) + +} diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 1ddf7b2c..d04cb017 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -317,27 +317,7 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator router.HandleHTTP(muxRouter) - muxRouter.Methods("GET").Path("/status").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - json, _ := router.StatusJSON(version) - w.Header().Set("Content-Type", "application/json") - w.Write(json) - }) - - muxRouter.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "weave router", version) - fmt.Fprintln(w, router.Status()) - if allocator != nil { - fmt.Fprintln(w, allocator.String()) - fmt.Fprintln(w, "Allocator default subnet:", defaultSubnet) - } - fmt.Fprintln(w, "") - if dnsserver == nil { - fmt.Fprintln(w, "WeaveDNS is disabled") - } else { - fmt.Fprintln(w, dnsserver.String()) - fmt.Fprintln(w, ns.String()) - } - }) + HandleHTTP(muxRouter, router, allocator, defaultSubnet, ns, dnsserver) http.Handle("/", muxRouter)