當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Request.ReadEntity方法代碼示例

本文整理匯總了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,
	})
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:26,代碼來源:apihandler.go

示例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))
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:10,代碼來源:apihandler.go

示例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)
}
開發者ID:sutrisnotay,項目名稱:dashboard,代碼行數:14,代碼來源:apihandler.go

示例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)
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:14,代碼來源:apihandler.go

示例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)
}
開發者ID:fwalker,項目名稱:dashboard,代碼行數:14,代碼來源:apihandler.go

示例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)
}
開發者ID:luxas,項目名稱:flannel,代碼行數:13,代碼來源:msgpack_entity_test.go

示例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)
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:15,代碼來源:apihandler.go

示例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)
}
開發者ID:FujitsuEnablingSoftwareTechnologyGmbH,項目名稱:dashboard,代碼行數:15,代碼來源:apihandler.go

示例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)
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:16,代碼來源:apihandler.go

示例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
	}
}
開發者ID:kmala,項目名稱:heapster,代碼行數:18,代碼來源:api.go

示例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)
}
開發者ID:FujitsuEnablingSoftwareTechnologyGmbH,項目名稱:dashboard,代碼行數:18,代碼來源:apihandler.go

示例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)
}
開發者ID:lohmander,項目名稱:dashboard,代碼行數:21,代碼來源:apihandler.go

示例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)
}
開發者ID:jmcvetta,項目名稱:lgtts,代碼行數:42,代碼來源:patron.go

示例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)
}
開發者ID:jmcvetta,項目名稱:lgtts,代碼行數:22,代碼來源:artist.go


注:本文中的github.com/emicklei/go-restful.Request.ReadEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。