本文整理匯總了Golang中github.com/emicklei/go-restful.WebService.Path方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebService.Path方法的具體用法?Golang WebService.Path怎麽用?Golang WebService.Path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/emicklei/go-restful.WebService
的用法示例。
在下文中一共展示了WebService.Path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InstallDefaultHandlers
// InstallDefaultHandlers registers the default set of supported HTTP request
// patterns with the restful Container.
func (s *Server) InstallDefaultHandlers() {
healthz.InstallHandler(s.restfulCont,
healthz.PingHealthz,
healthz.NamedCheck("syncloop", s.syncLoopHealthCheck),
healthz.NamedCheck("pleg", s.plegHealthCheck),
)
var ws *restful.WebService
ws = new(restful.WebService)
ws.
Path("/pods").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(s.getPods).
Operation("getPods"))
s.restfulCont.Add(ws)
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer))
s.restfulCont.Handle(metricsPath, prometheus.Handler())
ws = new(restful.WebService)
ws.
Path(specPath).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(s.getSpec).
Operation("getSpec").
Writes(cadvisorapi.MachineInfo{}))
s.restfulCont.Add(ws)
}
示例2: CreateApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateApiHandler(client *client.Client) http.Handler {
wsContainer := restful.NewContainer()
// TODO(bryk): This is for tests only. Replace with real implementation once ready.
ws := new(restful.WebService)
ws.Path("/api/deploy").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
cfg := new(DeployAppConfig)
if err := request.ReadEntity(cfg); err != nil {
HandleInternalError(response, err)
return
}
if err := DeployApp(cfg, client); err != nil {
HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, cfg)
}).Reads(DeployAppConfig{}).Writes(DeployAppConfig{}))
wsContainer.Add(ws)
return wsContainer
}
示例3: Register
func (a *Api) Register(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/apis/metrics/v1alpha1").
Doc("Root endpoint of metrics API").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/nodes/").
To(a.nodeMetricsList).
Doc("Get a list of metrics for all available nodes.").
Operation("nodeMetricsList"))
ws.Route(ws.GET("/nodes/{node-name}/").
To(a.nodeMetrics).
Doc("Get a list of all available metrics for the specified node.").
Operation("nodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/").
To(a.podMetricsList).
Doc("Get a list of metrics for all available pods in the specified namespace.").
Operation("podMetricsList").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))).
Param(ws.QueryParameter("labelSelector", "A selector to restrict the list of returned objects by their labels. Defaults to everything.").DataType("string"))
ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/").
To(a.podMetrics).
Doc("Get metrics for the specified pod in the specified namespace.").
Operation("podMetrics").
Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")).
Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")))
container.Add(ws)
}
示例4: InstallDefaultHandlers
// InstallDefaultHandlers registers the default set of supported HTTP request
// patterns with the restful Container.
func (s *Server) InstallDefaultHandlers() {
healthz.InstallHandler(s.restfulCont,
healthz.PingHealthz,
healthz.NamedCheck("syncloop", s.syncLoopHealthCheck),
)
var ws *restful.WebService
ws = new(restful.WebService)
ws.
Path("/pods").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(s.getPods).
Operation("getPods"))
s.restfulCont.Add(ws)
s.restfulCont.Handle("/stats/", &httpHandler{f: s.handleStats})
s.restfulCont.Handle("/metrics", prometheus.Handler())
ws = new(restful.WebService)
ws.
Path("/spec/").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(s.getSpec).
Operation("getSpec").
Writes(cadvisorapi.MachineInfo{}))
s.restfulCont.Add(ws)
}
示例5: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client) http.Handler {
apiHandler := ApiHandler{client}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Path("/api/deploy").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeployment{}).
Writes(AppDeployment{}))
wsContainer.Add(deployWs)
microserviceListWs := new(restful.WebService)
microserviceListWs.Path("/api/microservice").
Produces(restful.MIME_JSON)
microserviceListWs.Route(
microserviceListWs.GET("").
To(apiHandler.handleGetMicroserviceList).
Writes(MicroserviceList{}))
wsContainer.Add(microserviceListWs)
return wsContainer
}
示例6: Register
// Register the mainApi on the specified endpoint.
func (a *Api) Register(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/api/v1/metric-export").
Doc("Exports the latest point for all Heapster metrics").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(a.exportMetrics).
Doc("export the latest data point for all metrics").
Operation("exportMetrics").
Writes([]*types.Timeseries{}))
container.Add(ws)
ws = new(restful.WebService)
ws.Path("/api/v1/metric-export-schema").
Doc("Schema for metrics exported by heapster").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(a.exportMetricsSchema).
Doc("export the schema for all metrics").
Operation("exportmetricsSchema").
Writes(types.TimeseriesSchema{}))
container.Add(ws)
if a.metricSink != nil {
a.RegisterModel(container)
}
if a.historicalSource != nil {
a.RegisterHistorical(container)
}
}
示例7: initOAuthAuthorizationServerMetadataRoute
// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery
// https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2
// masterPublicURL should be internally and externally routable to allow all users to discover this information
func initOAuthAuthorizationServerMetadataRoute(apiContainer *genericmux.APIContainer, path, masterPublicURL string) {
// Build OAuth metadata once
metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", " ")
if err != nil {
glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err)
return
}
secretContainer := restful.Container{
ServeMux: apiContainer.SecretRoutes.(*http.ServeMux), // we know it's a *http.ServeMux. In kube 1.6, the type will actually be correct.
}
// Set up a service to return the OAuth metadata.
ws := new(restful.WebService)
ws.Path(path)
ws.Doc("OAuth 2.0 Authorization Server Metadata")
ws.Route(
ws.GET("/").To(func(_ *restful.Request, resp *restful.Response) {
writeJSON(resp, metadata)
}).
Doc("get the server's OAuth 2.0 Authorization Server Metadata").
Operation("getOAuthAuthorizationServerMetadata").
Produces(restful.MIME_JSON))
secretContainer.Add(ws)
}
示例8: RegisterHistorical
// RegisterHistorical registers the Historical API endpoints. It will register the same endpoints
// as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod
// metrics by using the pod id.
func (normalApi *Api) RegisterHistorical(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/api/v1/historical").
Doc("Root endpoint of the historical access API").
Consumes("*/*").
Produces(restful.MIME_JSON)
a := &HistoricalApi{normalApi}
addClusterMetricsRoutes(a, ws)
addAggregationRoutes(a, ws)
// register the endpoint for fetching raw metrics based on pod id
if a.isRunningInKubernetes() {
// The /pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Pod entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)).
Doc("Export some pod-level metric aggregations").
Operation("podAggregations").
Param(ws.PathParameter("pod-id", "The UID of the pod to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// some aggregations for a Container entity of the historical API.
ws.Route(ws.GET("/pod-id/{pod-id}/containers/{container-name}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerMetrics)).
Doc("Export some aggregations for a Pod Container").
Operation("podContainerAggregations").
Param(ws.PathParameter("pod-id", "The uid of the pod to use").DataType("string")).
Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResult{}))
// The /pod-id-list/{pod-id-list}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes
// metrics for a list of pod ids of the historical API.
ws.Route(ws.GET("/pod-id-list/{pod-id-list}/metrics/{metric-name:*}").
To(metrics.InstrumentRouteFunc("podListAggregations", a.podListMetrics)).
Doc("Export an aggregation for all pods from the given list").
Operation("podListAggregations").
Param(ws.PathParameter("pod-id-list", "Comma separated list of pod UIDs to lookup").DataType("string")).
Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")).
Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")).
Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")).
Writes(types.MetricResultList{}))
}
container.Add(ws)
}
示例9: NewWebService
func NewWebService() *restful.WebService {
ws := restful.WebService{}
ws.Path("/api/v1").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON, restful.MIME_XML)
ws.Route(ws.POST("/artists").To(createArtist).
Doc("Create a new Arist").
Reads(ArtistRequest{}))
ws.Route(ws.POST("/artists/{artist-id}/patrons").To(patronize).
Doc("Patronize an artist").
Param(ws.BodyParameter("artist-id", "artist identifier").DataType("int")).
Reads(PatronageRequest{}))
return &ws
}
示例10: initVersionRoute
// initReadinessCheckRoute initializes an HTTP endpoint for readiness checking
func initVersionRoute(container *restful.Container, path string) {
// Set up a service to return the git code version.
versionWS := new(restful.WebService)
versionWS.Path(path)
versionWS.Doc("git code version from which this is built")
versionWS.Route(
versionWS.GET("/").To(handleVersion).
Doc("get the code version").
Operation("getCodeVersion").
Produces(restful.MIME_JSON).
Consumes(restful.MIME_JSON))
container.Add(versionWS)
}
示例11: main
func main() {
port := env.StringDefault("PORT", "8080")
baseUrl := ":" + port
var ws restful.WebService
ws.Path("/api").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/bar").To(getBar).
Writes(Bar{}))
ws.Route(ws.GET("/foo").To(getFoo).
Writes(Foo{}))
restful.Add(&ws)
log.Printf("Starting webserver on %v...", baseUrl)
log.Fatal(http.ListenAndServe(baseUrl, nil))
}
示例12: RegisterModel
// RegisterModel registers the Model API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
func (a *Api) RegisterModel(container *restful.Container) {
ws := new(restful.WebService)
ws.Path("/api/v1/model").
Doc("Root endpoint of the stats model").
Consumes("*/*").
Produces(restful.MIME_JSON)
addClusterMetricsRoutes(a, ws)
ws.Route(ws.GET("/debug/allkeys").
To(metrics.InstrumentRouteFunc("debugAllKeys", a.allKeys)).
Doc("Get keys of all metric sets available").
Operation("debugAllKeys"))
container.Add(ws)
}
示例13: RegisterMetrics
// RegisterMetrics registers the Metrics API endpoints.
// All endpoints that end with a {metric-name} also receive a start time query parameter.
// The start and end times should be specified as a string, formatted according to RFC 3339.
// These apis are experimental, so they may change or disappear in the future.
func (a *Api) RegisterMetrics(container *restful.Container) {
ws := new(restful.WebService)
ws.
Path("/experimental/v2").
Doc("Root endpoint of the stats model").
Consumes("*/*").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/nodeMetrics/derived/").
To(a.derivedNodeMetricsList).
Filter(compressionFilter).
Doc("Get a list of all available metrics for all nodes").
Writes([]types.DerivedNodeMetrics{}).
Operation("derivedNodeMetricsList"))
ws.Route(ws.GET("/nodeMetrics/derived/{node-name}").
To(a.derivedNodeMetrics).
Filter(compressionFilter).
Doc("Get a list of all raw metrics for a Node entity").
Writes(types.DerivedNodeMetrics{}).
Operation("derivedNodeMetrics").
Param(ws.PathParameter("node-name", "The name of the node to look up").DataType("string")))
container.Add(ws)
}
示例14: Register
// Register the Api on the specified endpoint.
func (a *Api) Register(container *restful.Container) {
ws := new(restful.WebService)
ws.
Path("/api/v1/metric-export").
Doc("Exports the latest point for all Heapster metrics").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
Filter(compressionFilter).
To(a.exportMetrics).
Doc("export the latest data point for all metrics").
Operation("exportMetrics").
Writes([]*Timeseries{}))
container.Add(ws)
ws = new(restful.WebService)
ws.Path("/api/v1/metric-export-schema").
Doc("Schema for metrics exported by heapster").
Produces(restful.MIME_JSON)
ws.Route(ws.GET("").
To(a.exportMetricsSchema).
Doc("export the schema for all metrics").
Operation("exportmetricsSchema").
Writes(TimeseriesSchema{}))
container.Add(ws)
ws = new(restful.WebService)
ws.Path("/api/v1/sinks").
Doc("Configuration for Heapster sinks for exporting data").
Produces(restful.MIME_JSON)
ws.Route(ws.POST("").
To(a.setSinks).
Doc("set the current sinks").
Operation("setSinks").
Reads([]string{}))
ws.Route(ws.GET("").
To(a.getSinks).
Doc("get the current sinks").
Operation("getSinks").
Writes([]string{}))
container.Add(ws)
// Register the endpoints of the model
a.RegisterModel(container)
}
示例15: initOAuthAuthorizationServerMetadataRoute
// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery
// https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2
// masterPublicURL should be internally and externally routable to allow all users to discover this information
func initOAuthAuthorizationServerMetadataRoute(container *restful.Container, path, masterPublicURL string) {
// Build OAuth metadata once
metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", " ")
if err != nil {
glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err)
return
}
// Set up a service to return the OAuth metadata.
oauthWS := new(restful.WebService)
oauthWS.Path(path)
oauthWS.Doc("OAuth 2.0 Authorization Server Metadata")
oauthWS.Route(
oauthWS.GET("/").To(func(_ *restful.Request, resp *restful.Response) {
writeJSON(resp, metadata)
}).
Doc("get the server's OAuth 2.0 Authorization Server Metadata").
Operation("getOAuthAuthorizationServerMetadata").
Produces(restful.MIME_JSON))
container.Add(oauthWS)
}