so go-restful require different prefixes now

This commit is contained in:
Mikaël Cluseau 2019-04-18 18:47:31 +01:00
parent 9b62d598bb
commit a1fcd4093c
2 changed files with 11 additions and 13 deletions

View File

@ -1,5 +1,5 @@
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from golang:1.12.3-alpine as build from golang:1.12.4-alpine as build
run apk add --update git run apk add --update git
env CGO_ENABLED 0 env CGO_ENABLED 0

View File

@ -13,8 +13,7 @@ import (
func registerWS(rest *restful.Container) { func registerWS(rest *restful.Container) {
// Admin API // Admin API
adminWS := &restful.WebService{} ws := &restful.WebService{}
ws := adminWS
ws.Filter(adminAuth). ws.Filter(adminAuth).
HeaderParameter("Authorization", "Admin bearer token") HeaderParameter("Authorization", "Admin bearer token")
@ -42,35 +41,34 @@ func registerWS(rest *restful.Container) {
ws.Route(ws.PUT("/clusters/{cluster-name}/passwords/{password-name}").To(wsClusterSetPassword). ws.Route(ws.PUT("/clusters/{cluster-name}/passwords/{password-name}").To(wsClusterSetPassword).
Doc("Set cluster's password")) Doc("Set cluster's password"))
ws.Route(ws.GET("/hosts").To(wsListHosts).
Doc("List hosts"))
(&wsHost{ (&wsHost{
prefix: "/hosts/{host-name}", prefix: "/hosts/{host-name}",
hostDoc: "given host", hostDoc: "given host",
getHost: func(req *restful.Request) string { getHost: func(req *restful.Request) string {
return req.PathParameter("host-name") return req.PathParameter("host-name")
}, },
}).register(adminWS, func(rb *restful.RouteBuilder) { }).register(ws, func(rb *restful.RouteBuilder) {
}) })
rest.Add(ws)
// Hosts API // Hosts API
hostsWS := &restful.WebService{} ws = &restful.WebService{}
ws = adminWS ws.Path("/me")
ws.Filter(hostsAuth). ws.Filter(hostsAuth).
HeaderParameter("Authorization", "Host or admin bearer token") HeaderParameter("Authorization", "Host or admin bearer token")
ws.Route(ws.GET("/hosts").To(wsListHosts).
Doc("List hosts"))
(&wsHost{ (&wsHost{
prefix: "/me",
hostDoc: "detected host", hostDoc: "detected host",
getHost: detectHost, getHost: detectHost,
}).register(ws, func(rb *restful.RouteBuilder) { }).register(ws, func(rb *restful.RouteBuilder) {
rb.Notes("In this case, the host is detected from the remote IP") rb.Notes("In this case, the host is detected from the remote IP")
}) })
// register the web services rest.Add(ws)
rest.Add(adminWS)
rest.Add(hostsWS)
} }
func detectHost(req *restful.Request) string { func detectHost(req *restful.Request) string {