本文整理匯總了Golang中github.com/emicklei/go-restful.Request.ReadEntity方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.ReadEntity方法的具體用法?Golang Request.ReadEntity怎麽用?Golang Request.ReadEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/emicklei/go-restful.Request
的用法示例。
在下文中一共展示了Request.ReadEntity方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleDeployFromFile
// Handles deploy from file API call.
func (apiHandler *ApiHandler) handleDeployFromFile(request *restful.Request, response *restful.Response) {
deploymentSpec := new(AppDeploymentFromFileSpec)
if err := request.ReadEntity(deploymentSpec); err != nil {
handleInternalError(response, err)
return
}
isDeployed, err := DeployAppFromFile(
deploymentSpec, CreateObjectFromInfoFn, apiHandler.clientConfig)
if !isDeployed {
handleInternalError(response, err)
return
}
errorMessage := ""
if err != nil {
errorMessage = err.Error()
}
response.WriteHeaderAndEntity(http.StatusCreated, AppDeploymentFromFileResponse{
Name: deploymentSpec.Name,
Content: deploymentSpec.Content,
Error: errorMessage,
})
}
示例2: handleProtocolValidity
// Handles protocol validation API call.
func (apiHandler *ApiHandler) handleProtocolValidity(request *restful.Request, response *restful.Response) {
spec := new(ProtocolValiditySpec)
if err := request.ReadEntity(spec); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, ValidateProtocol(spec))
}
示例3: handleDeploy
// Handles deploy API call.
func (apiHandler *ApiHandler) handleDeploy(request *restful.Request, response *restful.Response) {
cfg := new(AppDeployment)
if err := request.ReadEntity(cfg); err != nil {
handleInternalError(response, err)
return
}
if err := DeployApp(cfg, apiHandler.client); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, cfg)
}
示例4: handleCreateImagePullSecret
// Handles image pull secret creation API call.
func (apiHandler *ApiHandler) handleCreateImagePullSecret(request *restful.Request, response *restful.Response) {
secretSpec := new(ImagePullSecretSpec)
if err := request.ReadEntity(secretSpec); err != nil {
handleInternalError(response, err)
return
}
secret, err := CreateSecret(apiHandler.client, secretSpec)
if err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, secret)
}
示例5: handleDeployFromFile
// Handles deploy from file API call.
func (apiHandler *ApiHandler) handleDeployFromFile(request *restful.Request, response *restful.Response) {
deploymentSpec := new(AppDeploymentFromFileSpec)
if err := request.ReadEntity(deploymentSpec); err != nil {
handleInternalError(response, err)
return
}
if err := DeployAppFromFile(deploymentSpec, CreateObjectFromInfoFn); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, deploymentSpec)
}
示例6: do
func do(request *restful.Request, response *restful.Response) {
u := &user{}
err := request.ReadEntity(u)
if err != nil {
log.Printf("should be no error, got:%v", err)
}
log.Printf("got:%v", u)
ur := &userResponse{Status: statusActive}
response.SetRequestAccepts(MIME_MSGPACK)
response.WriteEntity(ur)
}
示例7: handleCreateNamespace
// Handles namespace creation API call.
func (apiHandler *ApiHandler) handleCreateNamespace(request *restful.Request,
response *restful.Response) {
namespaceSpec := new(NamespaceSpec)
if err := request.ReadEntity(namespaceSpec); err != nil {
handleInternalError(response, err)
return
}
if err := CreateNamespace(namespaceSpec, apiHandler.client); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, namespaceSpec)
}
示例8: handleImageReferenceValidity
// Handles image reference validation API call.
func (ApiHandler *ApiHandler) handleImageReferenceValidity(request *restful.Request, response *restful.Response) {
spec := new(ImageReferenceValiditySpec)
if err := request.ReadEntity(spec); err != nil {
handleInternalError(response, err)
return
}
validity, err := ValidateImageReference(spec)
if err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, validity)
}
示例9: handleNameValidity
// Handles app name validation API call.
func (apiHandler *ApiHandler) handleNameValidity(request *restful.Request, response *restful.Response) {
spec := new(AppNameValiditySpec)
if err := request.ReadEntity(spec); err != nil {
handleInternalError(response, err)
return
}
validity, err := ValidateAppName(spec, apiHandler.client)
if err != nil {
handleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, validity)
}
示例10: setSinks
func (a *Api) setSinks(req *restful.Request, resp *restful.Response) {
sinkUris := new([]string)
if err := req.ReadEntity(sinkUris); err != nil {
resp.WriteError(http.StatusBadRequest, err)
return
}
var uris manager.Uris
for _, s := range *sinkUris {
if err := uris.Set(s); err != nil {
resp.WriteError(http.StatusBadRequest, err)
return
}
}
if err := a.manager.SetSinkUris(uris); err != nil {
resp.WriteError(http.StatusInternalServerError, err)
return
}
}
示例11: handlePutResource
func (apiHandler *ApiHandler) handlePutResource(
request *restful.Request, response *restful.Response) {
kind := request.PathParameter("kind")
namespace := request.PathParameter("namespace")
name := request.PathParameter("name")
putSpec := &runtime.Unknown{}
if err := request.ReadEntity(putSpec); err != nil {
handleInternalError(response, err)
return
}
if err := apiHandler.verber.Put(kind, namespace, name, putSpec); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeader(http.StatusOK)
}
示例12: handleUpdateReplicasCount
// Handles update of Replication Controller pods update API call.
func (apiHandler *ApiHandler) handleUpdateReplicasCount(
request *restful.Request, response *restful.Response) {
namespace := request.PathParameter("namespace")
replicationControllerName := request.PathParameter("replicationController")
replicationControllerSpec := new(ReplicationControllerSpec)
if err := request.ReadEntity(replicationControllerSpec); err != nil {
handleInternalError(response, err)
return
}
if err := UpdateReplicasCount(apiHandler.client, namespace, replicationControllerName,
replicationControllerSpec); err != nil {
handleInternalError(response, err)
return
}
response.WriteHeader(http.StatusAccepted)
}
示例13: patronize
// patronize handles a request to patronize an artist.
func patronize(req *restful.Request, resp *restful.Response) {
pr := PatronageRequest{}
err := req.ReadEntity(&pr)
if err != nil {
log.Println(err)
resp.WriteError(http.StatusBadRequest, err)
return
}
//
// Validate zip code
//
idx := validZip.FindStringIndex(pr.Zip)
if idx == nil {
log.Println("Invalid zip code:", pr.Zip)
resp.WriteError(http.StatusBadRequest, err)
return
}
//
// Save patron to database
//
artistId, err := strconv.Atoi(req.PathParameter("artist-id"))
if err != nil {
log.Println(err)
resp.WriteError(http.StatusBadRequest, err)
return
}
p := Patron{
ArtistId: int64(artistId),
Email: pr.Email,
Zip: pr.Zip,
Created: time.Now(),
Confirmed: false,
}
err = dbmap.Insert(&p)
if err != nil {
log.Println(err)
resp.WriteError(http.StatusInternalServerError, err)
return
}
resp.WriteEntity(p)
}
示例14: createArtist
// createArtist handles a request to create a new Artist.
func createArtist(req *restful.Request, resp *restful.Response) {
ar := ArtistRequest{}
err := req.ReadEntity(&ar)
if err != nil {
resp.WriteError(http.StatusBadRequest, err)
return
}
a := Artist{
Name: ar.Name,
Email: ar.Email,
Hometown: ar.Hometown,
Zip: ar.Zip,
Description: ar.Description,
}
err = dbmap.Insert(&a)
if err != nil {
resp.WriteError(http.StatusBadRequest, err)
return
}
resp.WriteEntity(a)
}