Move status HTTP handlers into prog/weaver/http.go
This commit is contained in:
1 parent
278807a199
commit
00ecff09f7
3 files changed
+46
-22
No files matched your search
@@ -67,7 +67,7 @@ $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go
|
|||||||
go build $(BUILD_FLAGS) -o $@ ./$(@D)
|
go build $(BUILD_FLAGS) -o $@ ./$(@D)
|
||||||
$(NETGO_CHECK)
|
$(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
|
$(WEAVEPROXY_EXE): proxy/*.go prog/weaveproxy/main.go
|
||||||
$(NETCHECK_EXE): prog/netcheck/netcheck.go
|
$(NETCHECK_EXE): prog/netcheck/netcheck.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())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
+1
-21
@@ -317,27 +317,7 @@ func handleHTTP(router *weave.Router, httpAddr string, allocator *ipam.Allocator
|
|||||||
|
|
||||||
router.HandleHTTP(muxRouter)
|
router.HandleHTTP(muxRouter)
|
||||||
|
|
||||||
muxRouter.Methods("GET").Path("/status").Headers("Accept", "application/json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
HandleHTTP(muxRouter, router, allocator, defaultSubnet, ns, dnsserver)
|
||||||
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())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
http.Handle("/", muxRouter)
|
http.Handle("/", muxRouter)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user