当前位置: 首页>>代码示例>>Golang>>正文


Golang response.JSON函数代码示例

本文整理汇总了Golang中github.com/dorajistyle/goyangi/api/response.JSON函数的典型用法代码示例。如果您正苦于以下问题:Golang JSON函数的具体用法?Golang JSON怎么用?Golang JSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JSON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createUserAuthentication

// @Title createUserAuthentication
// @Description Create a user session.
// @Accept  json
// @Param   loginEmail        form   string     true        "User email."
// @Param   loginPassword        form   string  true        "User password."
// @Success 201 {object} response.BasicResponse "User authentication created"
// @Failure 401 {object} response.BasicResponse "Password incorrect"
// @Failure 404 {object} response.BasicResponse "User is not found"
// @Resource /authentications
// @Router /authentications [post]
func createUserAuthentication(c *gin.Context) {
	status, err := userService.CreateUserAuthentication(c)
	messageTypes := &response.MessageTypes{OK: "login.done",
		Unauthorized: "login.error.passwordIncorrect",
		NotFound:     "login.error.userNotFound"}
	messages := &response.Messages{OK: "User logged in successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:18,代码来源:authentication.go

示例2: createCommentOnArticle

// @Title createCommentOnArticle
// @Description Create a comment on an article.
// @Accept  json
// @Param   articleId        form   int     true        "Article Id."
// @Param   content        form   string     true        "Comment content."
// @Param   imageName        form   string     true        "Article image name."
// @Param   description        form   string  false        "Article description."
// @Success 201 {object} response.BasicResponse "Comment created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 403 {object} response.BasicResponse "FormUser's Id is not identical with currentUser's Id"
// @Failure 404 {object} response.BasicResponse "Article is not found"
// @Resource /articles
// @Router /articles/comments [post]
func createCommentOnArticle(c *gin.Context) {
	status, err := articleService.CreateCommentOnArticle(c)
	messageTypes := &response.MessageTypes{
		Created:      "comment.created.done",
		Unauthorized: "comment.error.unauthorized",
		Forbidden:    "comment.error.forbidden",
		NotFound:     "comment.error.notFound"}
	messages := &response.Messages{OK: "Comment is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:23,代码来源:articles.go

示例3: deleteArticle

// @Title deleteArticle
// @Description Delete an article.
// @Accept  json
// @Param   id        path    int     true        "Article Id"
// @Success 200 {object} response.BasicResponse "Article deleted"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /articles
// @Router /articles/{id} [delete]
func deleteArticle(c *gin.Context) {
	status, err := articleService.DeleteArticle(c)
	messageTypes := &response.MessageTypes{
		OK:           "article.view.deleted.done",
		BadRequest:   "article.view.deleted.fail",
		Unauthorized: "article.error.isNotAuthor",
		NotFound:     "article.error.notFound"}
	messages := &response.Messages{OK: "Article is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:19,代码来源:articles.go

示例4: uploadAndSyncArticles

// @Title uploadAndSyncArticles
// @Description upload images to storage. And sync article data. Request should contain multipart form data.
// @Accept  json
// @Success 201 {object} gin.H "Uploaded"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Upload failed"
// @Resource /upload/articles
// @Router /upload [post]
func uploadAndSyncArticles(c *gin.Context) {
	status, err := uploadService.UploadAndSyncArticles(c)
	messageTypes := &response.MessageTypes{
		OK:                  "upload.done",
		Unauthorized:        "upload.error.unauthorized",
		InternalServerError: "upload.error.internalServerError",
	}
	messages := &response.Messages{OK: "Files uploaded successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:18,代码来源:upload.go

示例5: createLikingOnArticle

// @Title createLikingOnArticle
// @Description Create a liking on an article.
// @Accept  json
// @Param   articleId        form   int     true        "Article Id."
// @Param   content        form   string     true        "Liking content."
// @Param   imageName        form   string     true        "Article image name."
// @Param   description        form   string  false        "Article description."
// @Success 201 {object} response.BasicResponse "Liking created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 403 {object} response.BasicResponse "FormUser's Id is not identical with currentUser's Id"
// @Failure 404 {object} response.BasicResponse "Article is not found"
// @Resource /articles
// @Router /articles/likings [post]
func createLikingOnArticle(c *gin.Context) {
	status, err := articleService.CreateLikingOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:           "liking.like.done",
		BadRequest:   "liking.like.fail",
		Unauthorized: "liking.error.unauthorized",
		NotFound:     "liking.error.notFound"}
	messages := &response.Messages{OK: "Article liking is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:23,代码来源:articles.go

示例6: updateCommentOnLocation

// @Title updateCommentOnLocation
// @Description Update a comment on location.
// @Accept  json
// @Param   locationId        path    int     true        "Location Id"
// @Param   id                path    int     true        "Comment Id"
// @Success 200 {object} model.Comment "Comment updated successfully"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 403 {object} response.BasicResponse "FormUser's Id is not identical with currentUser's Id"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Comment is not updated"
// @Resource /locations
// @Router /locations/{id}/comments/{commentId} [put]
func updateCommentOnLocation(c *gin.Context) {
	status, err := locationService.UpdateCommentOnLocation(c)
	messageTypes := &response.MessageTypes{
		OK:                  "comment.updated.done",
		Unauthorized:        "comment.error.unauthorized",
		Forbidden:           "comment.error.forbidden",
		NotFound:            "comment.error.notFound",
		InternalServerError: "comment.updated.fail"}
	messages := &response.Messages{OK: "Comment is created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:23,代码来源:locations.go

示例7: deleteLocation

// @Title deleteLocation
// @Description Delete an location.
// @Accept  json
// @Param   id        path    int     true        "Location Id"
// @Success 200 {object} response.BasicResponse "Location deleted"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /locations
// @Router /locations/{id} [delete]
func deleteLocation(c *gin.Context) {
	status, err := locationService.DeleteLocation(c)
	messageTypes := &response.MessageTypes{
		OK:           "location.view.deleted.done",
		BadRequest:   "location.view.deleted.fail",
		Unauthorized: "location.error.isNotAuthor",
		NotFound:     "location.error.notFound"}
	messages := &response.Messages{OK: "Location is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)

}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:20,代码来源:locations.go

示例8: verifyEmail

// @Title verifyEmail
// @Description Create a user session.
// @Accept  json
// @Param   token        form   string     true        "User email validation token"
// @Success 200 {object} response.BasicResponse "User email verified."
// @Failure 400 {object} response.BasicResponse "User email not verified."
// @Resource /user
// @Router /user/verify/email [put]
func verifyEmail(c *gin.Context) {
	status, err := userService.EmailVerification(c)
	messageTypes := &response.MessageTypes{
		OK:                  "emailVerification.done",
		Forbidden:           "emailVerification.error.tokenExpired",
		NotFound:            "error.notFound",
		InternalServerError: "emailVerification.fail",
	}
	messages := &response.Messages{OK: "Email verified successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:19,代码来源:users.go

示例9: sendEmailVerificationToken

// @Title sendEmailVerificationToken
// @Description Create a user session.
// @Accept  json
// @Success 201 {object} response.BasicResponse "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Email verification token not sent"
// @Resource /user
// @Router /user/send/email/verification/token [post]
func sendEmailVerificationToken(c *gin.Context) {
	status, err := userService.SendVerification(c)
	messageTypes := &response.MessageTypes{
		OK:                  "emailVerification.send.sent.done",
		Unauthorized:        "error.unauthorized",
		NotFound:            "error.notFound",
		InternalServerError: "emailVerification.send.sent.fail",
	}
	messages := &response.Messages{OK: "Email verification token sent successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:19,代码来源:users.go

示例10: resetPassword

// @Title resetPassword
// @Description Create a user session.
// @Accept  json
// @Param   token        form   string     true        "User password reset token"
// @Param   newPassword        form   string     true        "New password"
// @Success 200 {object} response.BasicResponse "User password updated"
// @Failure 400 {object} response.BasicResponse "User password is not updated."
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Password reset token not sent"
// @Resource /user
// @Router /user/reset/password [put]
func resetPassword(c *gin.Context) {
	status, err := userService.ResetPassword(c)
	messageTypes := &response.MessageTypes{
		OK:                  "passwordReset.reset.updated.done",
		Forbidden:           "passwordReset.error.tokenExpired",
		NotFound:            "error.notFound",
		InternalServerError: "passwordReset.reset.updated.fail",
	}
	messages := &response.Messages{OK: "Password reset successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:22,代码来源:users.go

示例11: sendPasswordResetToken

// @Title sendPasswordResetToken
// @Description Create a user session.
// @Accept  json
// @Param   email        form   string     true        "User email."
// @Success 200 {object} response.BasicResponse "Sent"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Password reset token not sent"
// @Resource /user
// @Router /user/send/password/reset/token [post]
func sendPasswordResetToken(c *gin.Context) {
	status, err := userService.SendPasswordResetToken(c)
	messageTypes := &response.MessageTypes{
		OK:                  "passwordReset.send.sent.done",
		Unauthorized:        "error.unauthorized",
		NotFound:            "error.notFound",
		InternalServerError: "passwordReset.send.sent.fail",
	}
	messages := &response.Messages{OK: "Password reset token sent successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:20,代码来源:users.go

示例12: deleteLikingOnUser

// @Title deleteLikingOnUser
// @Description Delete a liking on user.
// @Accept  json
// @Param   userId        path    int     true        "User ID"
// @Param   id                path    int     true        "Liking ID"
// @Success 200 {object} response.BasicResponse
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Liking is not deleted"
// @Resource /users
// @Router /users/{id}/likings/{likingId} [delete]
func deleteLikingOnUser(c *gin.Context) {
	status, err := userLiking.DeleteLikingOnUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "liking.unlike.done",
		Unauthorized:        "liking.error.unauthorized",
		NotFound:            "liking.error.notFound",
		InternalServerError: "liking.unlike.fail",
	}
	messages := &response.Messages{OK: "Liking is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:22,代码来源:users.go

示例13: removeRoleFromUser

// @Title removeRoleFromUser
// @Description Remove a role from user.
// @Accept  json
// @Param   id        path   int  true        "User ID."
// @Param   roleId        form   int  true        "Role ID."
// @Success 200 {object} response.BasicResponse "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Role is not deleted from a user"
// @Resource /users
// @Router /users/{id}/roles/{roleId} [delete]
func removeRoleFromUser(c *gin.Context) {
	status, err := userService.RemoveRoleFromUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "admin.user.role.delete.done",
		Unauthorized:        "user.error.unauthorized",
		NotFound:            "user.error.notFound",
		InternalServerError: "admin.user.role.delete.fail",
	}
	messages := &response.Messages{OK: "Role is deleted from a user successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:22,代码来源:users.go

示例14: addRoleToUser

// @Title addRoleToUser
// @Description Add a role to user.
// @Accept  json
// @Param   userId        form   int  true        "User ID."
// @Param   roleId        form   int  true        "Role ID."
// @Success 201 {object} response.BasicResponse "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "User or role is not found"
// @Failure 500 {object} response.BasicResponse "Role is not added to a user"
// @Resource /users
// @Router /users/roles [post]
func addRoleToUser(c *gin.Context) {
	status, err := userService.AddRoleToUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "admin.user.role.add.done",
		Unauthorized:        "user.error.unauthorized",
		NotFound:            "user.error.notFound",
		InternalServerError: "admin.user.role.add.fail",
	}
	messages := &response.Messages{OK: "Role is added to a user successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:22,代码来源:users.go

示例15: deleteCommentOnArticle

// @Title deleteCommentOnArticle
// @Description Delete a comment on article.
// @Accept  json
// @Param   articleId        path    int     true        "Article Id"
// @Param   id                path    int     true        "Comment Id"
// @Success 200 {object} response.BasicResponse "Comment is deleted successfully"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 403 {object} response.BasicResponse "FormUser's Id is not identical with currentUser's Id"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "Comment is not deleted"
// @Resource /articles
// @Router /articles/{id}/comments/{commentId} [delete]
func deleteCommentOnArticle(c *gin.Context) {
	status, err := articleService.DeleteCommentOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:                  "comment.deleted.done",
		Unauthorized:        "comment.error.unauthorized",
		Forbidden:           "comment.error.forbidden",
		NotFound:            "comment.error.notFound",
		InternalServerError: "comment.deleted.fail"}
	messages := &response.Messages{OK: "Comment is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:23,代码来源:articles.go


注:本文中的github.com/dorajistyle/goyangi/api/response.JSON函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。