本文整理匯總了Golang中github.com/emicklei/go-restful.WebService.GET方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebService.GET方法的具體用法?Golang WebService.GET怎麽用?Golang WebService.GET使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/emicklei/go-restful.WebService
的用法示例。
在下文中一共展示了WebService.GET方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initAPIVersionRoute
// initAPIVersionRoute initializes the osapi endpoint to behave similar to the upstream api endpoint
func initAPIVersionRoute(root *restful.WebService, prefix string, versions ...string) {
versionHandler := apiserver.APIVersionHandler(versions...)
root.Route(root.GET(prefix).To(versionHandler).
Doc("list supported server API versions").
Produces(restful.MIME_JSON).
Consumes(restful.MIME_JSON))
}
示例2: 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
}
示例3: 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)
}
示例4: 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)
}
示例5: 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)
}
示例6: 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)
}
示例7: 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)
}
}
示例8: setupHandlers
func setupHandlers(metricSink *metricsink.MetricSink, podLister *cache.StoreToPodLister) http.Handler {
runningInKubernetes := true
// Make API handler.
wsContainer := restful.NewContainer()
wsContainer.EnableContentEncoding(true)
wsContainer.Router(restful.CurlyRouter{})
a := v1.NewApi(runningInKubernetes, metricSink)
a.Register(wsContainer)
// Metrics API
m := metricsApi.NewApi(metricSink, podLister)
m.Register(wsContainer)
handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
switch name {
case "profile":
pprof.Profile(resp, req.Request)
case "symbol":
pprof.Symbol(resp, req.Request)
case "cmdline":
pprof.Cmdline(resp, req.Request)
default:
pprof.Index(resp, req.Request)
}
}
// Setup pporf handlers.
ws := new(restful.WebService).Path(pprofBasePath)
ws.Route(ws.GET("/{subpath:*}").To(metrics.InstrumentRouteFunc("pprof", handlePprofEndpoint))).Doc("pprof endpoint")
wsContainer.Add(ws)
return wsContainer
}
示例9: initMetricsRoute
// initHealthCheckRoute initalizes an HTTP endpoint for health checking.
// OpenShift is deemed healthy if the API server can respond with an OK messages
func initMetricsRoute(root *restful.WebService, path string) {
h := prometheus.Handler()
root.Route(root.GET(path).To(func(req *restful.Request, resp *restful.Response) {
h.ServeHTTP(resp.ResponseWriter, req.Request)
}).Doc("return metrics for this process").
Returns(http.StatusOK, "if metrics are available", nil).
Produces("text/plain"))
}
示例10: initHealthCheckRoute
// initHealthCheckRoute initalizes an HTTP endpoint for health checking.
// OpenShift is deemed healthy if the API server can respond with an OK messages
func initHealthCheckRoute(root *restful.WebService, path string) {
root.Route(root.GET(path).To(func(req *restful.Request, resp *restful.Response) {
resp.ResponseWriter.WriteHeader(http.StatusOK)
resp.ResponseWriter.Write([]byte("ok"))
}).Doc("return the health state of the master").
Returns(http.StatusOK, "if master is healthy", nil).
Produces(restful.MIME_JSON))
}
示例11: initAPIVersionRoute
// initAPIVersionRoute initializes the osapi endpoint to behave similar to the upstream api endpoint
func initAPIVersionRoute(root *restful.WebService, prefix string, versions ...string) {
versionHandler := apiserver.APIVersionHandler(kapi.Codecs, func(req *restful.Request) *unversioned.APIVersions {
apiVersionsForDiscovery := unversioned.APIVersions{
// TODO: ServerAddressByClientCIDRs: s.getServerAddressByClientCIDRs(req.Request),
Versions: versions,
}
return &apiVersionsForDiscovery
})
root.Route(root.GET(prefix).To(versionHandler).
Doc("list supported server API versions").
Produces(restful.MIME_JSON).
Consumes(restful.MIME_JSON))
}
示例12: initMetricsRoute
// initMetricsRoute initializes an HTTP endpoint for metrics.
func initMetricsRoute(apiContainer *genericmux.APIContainer, path string) {
ws := new(restful.WebService).
Path(path).
Doc("return metrics for this process")
h := prometheus.Handler()
ws.Route(ws.GET("/").To(func(req *restful.Request, resp *restful.Response) {
h.ServeHTTP(resp.ResponseWriter, req.Request)
}).Doc("return metrics for this process").
Returns(http.StatusOK, "if metrics are available", nil).
Produces("text/plain"))
apiContainer.Add(ws)
}
示例13: 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)
}
示例14: 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)
}
示例15: initReadinessCheckRoute
// initReadinessCheckRoute initializes an HTTP endpoint for readiness checking
func initReadinessCheckRoute(root *restful.WebService, path string, readyFunc func() bool) {
root.Route(root.GET(path).To(func(req *restful.Request, resp *restful.Response) {
if readyFunc() {
resp.ResponseWriter.WriteHeader(http.StatusOK)
resp.ResponseWriter.Write([]byte("ok"))
} else {
resp.ResponseWriter.WriteHeader(http.StatusServiceUnavailable)
}
}).Doc("return the readiness state of the master").
Returns(http.StatusOK, "if the master is ready", nil).
Returns(http.StatusServiceUnavailable, "if the master is not ready", nil).
Produces(restful.MIME_JSON))
}