本文整理汇总了Golang中github.com/emicklei/go-restful.WebService类的典型用法代码示例。如果您正苦于以下问题:Golang WebService类的具体用法?Golang WebService怎么用?Golang WebService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
}
开发者ID:titilambert,项目名称:heapster,代码行数:35,代码来源:handlers.go
示例2: 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))
}
开发者ID:kcbabo,项目名称:origin,代码行数:8,代码来源:master.go
示例3: 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"))
}
开发者ID:ncantor,项目名称:origin,代码行数:10,代码来源:master.go
示例4: 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))
}
开发者ID:ncantor,项目名称:origin,代码行数:10,代码来源:master.go
示例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)
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:29,代码来源:master.go
示例6: 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))
}
开发者ID:pecameron,项目名称:origin,代码行数:14,代码来源:master.go
示例7: 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)
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:14,代码来源:master.go
示例8: NewService
// NewService creates and returns a new Service, initalized with a new
// restful.WebService configured with a route that dispatches to the supplied
// handler. The new Service must be registered before accepting traffic by
// calling Register.
func NewService(handler restful.RouteFunction) *Service {
restful.EnableTracing(true)
webService := new(restful.WebService)
webService.Consumes(restful.MIME_JSON, restful.MIME_XML)
webService.Produces(restful.MIME_JSON, restful.MIME_XML)
webService.Route(webService.POST("/expand").To(handler).
Doc("Expand a template.").
Reads(&expander.Template{}))
return &Service{webService}
}
开发者ID:RamessesYin,项目名称:deployment-manager,代码行数:14,代码来源:service.go
示例9: 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))
}
开发者ID:ncantor,项目名称:origin,代码行数:15,代码来源:master.go
示例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)
}
开发者ID:pecameron,项目名称:origin,代码行数:15,代码来源:master.go
示例11: 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
}
开发者ID:codeat,项目名称:dashboard,代码行数:27,代码来源:apihandler.go
示例12: initAPIVersionRoute
// initAPIVersionRoute initializes the osapi endpoint to behave similar to the upstream api endpoint
func initAPIVersionRoute(apiContainer *genericmux.APIContainer, 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
})
ws := new(restful.WebService).
Path(prefix).
Doc("list supported server API versions")
ws.Route(ws.GET("/").To(versionHandler).
Doc("list supported server API versions").
Produces(restful.MIME_JSON).
Consumes(restful.MIME_JSON).
Operation("get" + strings.Title(prefix[1:]) + "Version"))
apiContainer.Add(ws)
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:19,代码来源:master.go
示例13: initReadinessCheckRoute
// initReadinessCheckRoute initializes an HTTP endpoint for readiness checking
func initReadinessCheckRoute(apiContainer *genericmux.APIContainer, path string, readyFunc func() bool) {
ws := new(restful.WebService).
Path(path).
Doc("return the readiness state of the master")
ws.Route(ws.GET("/").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))
apiContainer.Add(ws)
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:20,代码来源:master.go
示例14: NewService
// NewService encapsulates code to open an HTTP server on the given address:port that serves the
// expansion API using the given Expander backend to do the actual expansion. After calling
// NewService, call ListenAndServe to start the returned service.
func NewService(address string, port int, backend Expander) *Service {
restful.EnableTracing(true)
webService := new(restful.WebService)
webService.Consumes(restful.MIME_JSON)
webService.Produces(restful.MIME_JSON)
handler := func(req *restful.Request, resp *restful.Response) {
util.LogHandlerEntry("expansion service", req.Request)
request := &ServiceRequest{}
if err := req.ReadEntity(&request); err != nil {
badRequest(resp, err.Error())
return
}
reqMsg := fmt.Sprintf("\nhandling request:\n%s\n", util.ToYAMLOrError(request))
util.LogHandlerText("expansion service", reqMsg)
response, err := backend.ExpandChart(request)
if err != nil {
badRequest(resp, fmt.Sprintf("error expanding chart: %s", err))
return
}
util.LogHandlerExit("expansion service", http.StatusOK, "OK", resp.ResponseWriter)
respMsg := fmt.Sprintf("\nreturning response:\n%s\n", util.ToYAMLOrError(response.Resources))
util.LogHandlerText("expansion service", respMsg)
resp.WriteEntity(response)
}
webService.Route(
webService.POST("/expand").
To(handler).
Doc("Expand a chart.").
Reads(&ServiceRequest{}).
Writes(&ServiceResponse{}))
container := restful.DefaultContainer
container.Add(webService)
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", address, port),
Handler: container,
}
return &Service{
webService: webService,
server: server,
container: container,
}
}
开发者ID:jackgr,项目名称:helm,代码行数:50,代码来源:service.go
示例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)
}
开发者ID:jayunit100,项目名称:origin,代码行数:25,代码来源:master.go
示例16: initVersionRoute
// initVersionRoute initializes an HTTP endpoint for the server's version information.
func initVersionRoute(container *restful.Container, path string) {
// Build version info once
versionInfo, err := json.MarshalIndent(version.Get(), "", " ")
if err != nil {
glog.Errorf("Unable to initialize version route: %v", err)
return
}
// 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(func(_ *restful.Request, resp *restful.Response) {
writeJSON(resp, versionInfo)
}).
Doc("get the code version").
Operation("getCodeVersion").
Produces(restful.MIME_JSON))
container.Add(versionWS)
}
开发者ID:jayunit100,项目名称:origin,代码行数:23,代码来源:master.go
示例17: 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)
}
开发者ID:kubernetes,项目名称:heapster,代码行数:18,代码来源:model_handlers.go
示例18: register
func register(container *restful.Container) {
restful.RegisterEntityAccessor(MIME_MSGPACK, NewEntityAccessorMsgPack())
ws := new(restful.WebService)
ws.
Path("/test").
Consumes(restful.MIME_JSON, MIME_MSGPACK).
Produces(restful.MIME_JSON, MIME_MSGPACK)
// route user api
ws.Route(ws.POST("/msgpack").
To(do).
Reads(user{}).
Writes(userResponse{}))
container.Add(ws)
}
开发者ID:luxas,项目名称:flannel,代码行数:14,代码来源:msgpack_entity_test.go
示例19: 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)
}
开发者ID:kmala,项目名称:heapster,代码行数:43,代码来源:api.go
示例20: main
func main() {
ws := new(restful.WebService)
ws.Path("/itrain").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
ws.Route(ws.GET("/version").
To(report_version).
Doc("get itrain version number").
Operation("version"))
ws.Route(ws.GET("/report_inverter").
To(report_inverter).
Doc("get inverter report data").
Operation("report_inverter").
Param(ws.QueryParameter("sd", "startdate")))
restful.Add(ws)
config := swagger.Config{
WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible
WebServicesUrl: "/",
ApiPath: "/apidocs.json",
// specifiy where the UI is located
SwaggerPath: "/apidocs/",
SwaggerFilePath: "./swaggerui"}
swagger.RegisterSwaggerService(config, restful.DefaultContainer)
var (
hostname string = "127.0.0.1"
port int = 8080
)
// Listen on hostname:port
fmt.Printf("Listening on %s:%d...\n", hostname, port)
err := http.ListenAndServe(fmt.Sprintf("%s:%d", hostname, port), nil)
if err != nil {
log.Fatal("Error: ", err)
}
}
开发者ID:iplon,项目名称:gotrain,代码行数:37,代码来源:main.go
注:本文中的github.com/emicklei/go-restful.WebService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论