本文整理汇总了Golang中techtraits/com/klaxon/router.Request.GetContent方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.GetContent方法的具体用法?Golang Request.GetContent怎么用?Golang Request.GetContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类techtraits/com/klaxon/router.Request
的用法示例。
在下文中一共展示了Request.GetContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: registerUser
func registerUser(request router.Request) (int, []byte) {
var registration UserResgistration
err := json.Unmarshal(request.GetContent(), ®istration)
//Check for correct desrialization
if err != nil {
log.Errorf(request.GetContext(), "error: %v", err)
return http.StatusBadRequest, []byte(err.Error())
}
//check if username already exists
if IsUsernameAvailable(registration.UserName, request.GetContext()) {
// generate a random salt with default rounds of complexity
salt, _ := bcrypt.Salt()
// hash and verify a password with random salt
hash, _ := bcrypt.Hash(registration.Password)
var user = UserData{registration.UserName, nil, salt, hash}
err = SaveUserToGAE(user, request.GetContext())
if err != nil {
log.Errorf(request.GetContext(), "error: %v", err)
return http.StatusInternalServerError, []byte(err.Error())
} else {
return http.StatusOK, nil
}
} else {
return http.StatusConflict, []byte("Username not avaiable")
}
}
示例2: postSubscription
//Create/Update an subscription for the given project
func postSubscription(request router.Request) (int, []byte) {
var subscription Subscription
err := json.Unmarshal(request.GetContent(), &subscription)
if err != nil {
log.Errorf(request.GetContext(), "error: %v", err)
return http.StatusBadRequest, []byte(err.Error())
}
subscription.Project = request.GetPathParams()["project_id"]
err = SaveSubscriptionToGAE(subscription, request.GetContext())
if err != nil {
log.Errorf(request.GetContext(), "error: %v", err)
return http.StatusInternalServerError, []byte(err.Error())
}
return http.StatusOK, nil
}
示例3: postAlert
//Create/Update an alert for the given project
func postAlert(request router.Request) (int, []byte) {
var alert Alert
err := json.Unmarshal(request.GetContent(), &alert)
if err != nil {
log.Infof(request.GetContext(), "error: %v", err)
return http.StatusBadRequest, []byte(err.Error())
}
//TODO Check Project Exists
alert.Project = request.GetPathParams()["project_id"]
err = SaveAlertToGAE(alert, request.GetContext())
if err != nil {
log.Infof(request.GetContext(), "error: %v", err)
return http.StatusInternalServerError, []byte(err.Error())
}
return http.StatusOK, nil
}
示例4: updateProject
//Create/Update a project
//TODO: Check Admin/User Permissions
//TODO: Check required config present
//TODO: If create add to user project list
func updateProject(request router.Request) (int, []byte) {
var project ProjectStruct
err := json.Unmarshal(request.GetContent(), &project)
if err != nil {
log.Infof(request.GetContext(), "error: %v", err)
return http.StatusBadRequest, []byte(err.Error())
}
projectDTO, err := project.GetDTO()
if err != nil {
return http.StatusInternalServerError, []byte(err.Error())
}
err = SaveProjectDTOToGAE(projectDTO, request.GetContext())
if err != nil {
log.Infof(request.GetContext(), "error: %v", err)
return http.StatusInternalServerError, []byte(err.Error())
}
return http.StatusOK, nil
}