本文整理匯總了Golang中github.com/emicklei/go-restful.WebService.POST方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebService.POST方法的具體用法?Golang WebService.POST怎麽用?Golang WebService.POST使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/emicklei/go-restful.WebService
的用法示例。
在下文中一共展示了WebService.POST方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例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: 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}
}
示例4: 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
}
示例5: 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)
}
示例6: 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,
}
}
示例7: 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)
}
示例8: 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/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeployment{}).
Writes(AppDeployment{}))
wsContainer.Add(deployWs)
replicaSetWs := new(restful.WebService)
replicaSetWs.Path("/api/replicasets").
Produces(restful.MIME_JSON)
replicaSetWs.Route(
replicaSetWs.GET("").
To(apiHandler.handleGetReplicaSetList).
Writes(ReplicaSetList{}))
replicaSetWs.Route(
replicaSetWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(ReplicaSetDetail{}))
wsContainer.Add(replicaSetWs)
namespaceListWs := new(restful.WebService)
namespaceListWs.Path("/api/namespaces").
Produces(restful.MIME_JSON)
namespaceListWs.Route(
namespaceListWs.GET("").
To(apiHandler.handleGetNamespaceList).
Writes(NamespacesList{}))
wsContainer.Add(namespaceListWs)
return wsContainer
}
示例9: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
clientConfig clientcmd.ClientConfig) http.Handler {
apiHandler := ApiHandler{client, heapsterClient, clientConfig}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Filter(wsLogger)
deployWs.Path("/api/v1/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
deployWs.Route(
deployWs.POST("/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
deployWs.Route(
deployWs.POST("/validate/protocol").
To(apiHandler.handleProtocolValidity).
Reads(ProtocolValiditySpec{}).
Writes(ProtocolValidity{}))
deployWs.Route(
deployWs.GET("/protocols").
To(apiHandler.handleGetAvailableProcotols).
Writes(Protocols{}))
wsContainer.Add(deployWs)
deployFromFileWs := new(restful.WebService)
deployFromFileWs.Path("/api/v1/appdeploymentfromfile").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployFromFileWs.Route(
deployFromFileWs.POST("").
To(apiHandler.handleDeployFromFile).
Reads(AppDeploymentFromFileSpec{}).
Writes(AppDeploymentFromFileResponse{}))
wsContainer.Add(deployFromFileWs)
replicationControllerWs := new(restful.WebService)
replicationControllerWs.Filter(wsLogger)
replicationControllerWs.Path("/api/v1/replicationcontrollers").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
replicationControllerWs.Route(
replicationControllerWs.GET("").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
replicationControllerWs.Route(
replicationControllerWs.GET("/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerDetail).
Writes(ReplicationControllerDetail{}))
replicationControllerWs.Route(
replicationControllerWs.POST("/{namespace}/{replicationController}/update/pods").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicationControllerSpec{}))
replicationControllerWs.Route(
replicationControllerWs.DELETE("/{namespace}/{replicationController}").
To(apiHandler.handleDeleteReplicationController))
replicationControllerWs.Route(
replicationControllerWs.GET("/pods/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerPods).
Writes(ReplicationControllerPods{}))
wsContainer.Add(replicationControllerWs)
namespacesWs := new(restful.WebService)
namespacesWs.Filter(wsLogger)
namespacesWs.Path("/api/v1/namespaces").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
namespacesWs.Route(
namespacesWs.POST("").
To(apiHandler.handleCreateNamespace).
Reads(NamespaceSpec{}).
Writes(NamespaceSpec{}))
namespacesWs.Route(
namespacesWs.GET("").
To(apiHandler.handleGetNamespaces).
Writes(NamespaceList{}))
wsContainer.Add(namespacesWs)
logsWs := new(restful.WebService)
logsWs.Filter(wsLogger)
logsWs.Path("/api/v1/logs").
Produces(restful.MIME_JSON)
logsWs.Route(
logsWs.GET("/{namespace}/{podId}").
To(apiHandler.handleLogs).
Writes(Logs{}))
logsWs.Route(
logsWs.GET("/{namespace}/{podId}/{container}").
To(apiHandler.handleLogs).
Writes(Logs{}))
wsContainer.Add(logsWs)
//.........這裏部分代碼省略.........
示例10: InstallDebuggingHandlers
// InstallDeguggingHandlers registers the HTTP request patterns that serve logs or run commands/containers
func (s *Server) InstallDebuggingHandlers() {
var ws *restful.WebService
ws = new(restful.WebService)
ws.
Path("/run")
ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}").
To(s.getRun).
Operation("getRun"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}").
To(s.getRun).
Operation("getRun"))
s.restfulCont.Add(ws)
ws = new(restful.WebService)
ws.
Path("/exec")
ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}").
To(s.getExec).
Operation("getExec"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}").
To(s.getExec).
Operation("getExec"))
ws.Route(ws.GET("/{podNamespace}/{podID}/{uid}/{containerName}").
To(s.getExec).
Operation("getExec"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}").
To(s.getExec).
Operation("getExec"))
s.restfulCont.Add(ws)
ws = new(restful.WebService)
ws.
Path("/attach")
ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}").
To(s.getAttach).
Operation("getAttach"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}").
To(s.getAttach).
Operation("getAttach"))
ws.Route(ws.GET("/{podNamespace}/{podID}/{uid}/{containerName}").
To(s.getAttach).
Operation("getAttach"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}").
To(s.getAttach).
Operation("getAttach"))
s.restfulCont.Add(ws)
ws = new(restful.WebService)
ws.
Path("/portForward")
ws.Route(ws.POST("/{podNamespace}/{podID}").
To(s.getPortForward).
Operation("getPortForward"))
ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}").
To(s.getPortForward).
Operation("getPortForward"))
s.restfulCont.Add(ws)
ws = new(restful.WebService)
ws.
Path("/logs/")
ws.Route(ws.GET("").
To(s.getLogs).
Operation("getLogs"))
ws.Route(ws.GET("/{logpath:*}").
To(s.getLogs).
Operation("getLogs"))
s.restfulCont.Add(ws)
ws = new(restful.WebService)
ws.
Path("/containerLogs")
ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}").
To(s.getContainerLogs).
Operation("getContainerLogs"))
s.restfulCont.Add(ws)
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(func(req *restful.Request, resp *restful.Response) {
handlePprofEndpoint(req, resp)
})).Doc("pprof endpoint")
s.restfulCont.Add(ws)
//.........這裏部分代碼省略.........
示例11: CreateHttpApiHandler
// CreateHttpApiHandler creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
clientConfig clientcmd.ClientConfig) http.Handler {
verber := common.NewResourceVerber(client.RESTClient, client.ExtensionsClient.RESTClient,
client.AppsClient.RESTClient, client.BatchClient.RESTClient)
apiHandler := ApiHandler{client, heapsterClient, clientConfig, verber}
wsContainer := restful.NewContainer()
apiV1Ws := new(restful.WebService)
apiV1Ws.Filter(wsLogger)
apiV1Ws.Path("/api/v1").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
wsContainer.Add(apiV1Ws)
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/imagereference").
To(apiHandler.handleImageReferenceValidity).
Reads(ImageReferenceValiditySpec{}).
Writes(ImageReferenceValidity{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/protocol").
To(apiHandler.handleProtocolValidity).
Reads(ProtocolValiditySpec{}).
Writes(ProtocolValidity{}))
apiV1Ws.Route(
apiV1Ws.GET("/appdeployment/protocols").
To(apiHandler.handleGetAvailableProcotols).
Writes(Protocols{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeploymentfromfile").
To(apiHandler.handleDeployFromFile).
Reads(AppDeploymentFromFileSpec{}).
Writes(AppDeploymentFromFileResponse{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/{namespace}").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerDetail).
Writes(ReplicationControllerDetail{}))
apiV1Ws.Route(
apiV1Ws.POST("/replicationcontroller/{namespace}/{replicationController}/update/pod").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicationControllerSpec{}))
apiV1Ws.Route(
apiV1Ws.DELETE("/replicationcontroller/{namespace}/{replicationController}").
To(apiHandler.handleDeleteReplicationController))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/pod/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerPods).
Writes(ReplicationControllerPods{}))
apiV1Ws.Route(
apiV1Ws.GET("/workload").
To(apiHandler.handleGetWorkloads).
Writes(workload.Workloads{}))
apiV1Ws.Route(
apiV1Ws.GET("/workload/{namespace}").
To(apiHandler.handleGetWorkloads).
Writes(workload.Workloads{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset").
To(apiHandler.handleGetReplicaSets).
Writes(replicaset.ReplicaSetList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset/{namespace}").
To(apiHandler.handleGetReplicaSets).
Writes(replicaset.ReplicaSetList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(replicaset.ReplicaSetDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/pod").
To(apiHandler.handleGetPods).
Writes(pod.PodList{}))
apiV1Ws.Route(
apiV1Ws.GET("/pod/{namespace}").
To(apiHandler.handleGetPods).
//.........這裏部分代碼省略.........
示例12: 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/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
deployWs.Route(
deployWs.POST("/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
wsContainer.Add(deployWs)
replicaSetWs := new(restful.WebService)
replicaSetWs.Path("/api/replicasets").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
replicaSetWs.Route(
replicaSetWs.GET("").
To(apiHandler.handleGetReplicaSetList).
Writes(ReplicaSetList{}))
replicaSetWs.Route(
replicaSetWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(ReplicaSetDetail{}))
replicaSetWs.Route(
replicaSetWs.POST("/{namespace}/{replicaSet}/update/pods").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicaSetSpec{}))
replicaSetWs.Route(
replicaSetWs.DELETE("/{namespace}/{replicaSet}").
To(apiHandler.handleDeleteReplicaSet))
replicaSetWs.Route(
replicaSetWs.GET("/pods/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetPods).
Writes(ReplicaSetPods{}))
wsContainer.Add(replicaSetWs)
namespacesWs := new(restful.WebService)
namespacesWs.Path("/api/namespaces").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
namespacesWs.Route(
namespacesWs.POST("").
To(apiHandler.handleCreateNamespace).
Reads(NamespaceSpec{}).
Writes(NamespaceSpec{}))
namespacesWs.Route(
namespacesWs.GET("").
To(apiHandler.handleGetNamespaces).
Writes(NamespaceList{}))
wsContainer.Add(namespacesWs)
logsWs := new(restful.WebService)
logsWs.Path("/api/logs").
Produces(restful.MIME_JSON)
logsWs.Route(
logsWs.GET("/{namespace}/{podId}/{container}").
To(apiHandler.handleLogs).
Writes(Logs{}))
wsContainer.Add(logsWs)
eventsWs := new(restful.WebService)
eventsWs.Path("/api/events").
Produces(restful.MIME_JSON)
eventsWs.Route(
eventsWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleEvents).
Writes(Events{}))
wsContainer.Add(eventsWs)
return wsContainer
}