• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang response.JSON函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: createUser

// @Title createUser
// @Description Create a user.
// @Accept  json
// @Param   registrationEmail        form   string     true        "User Email."
// @Param   registrationPassword        form   string  true        "User Password."
// @Success 201 {object} response.BasicResponse "User is registered successfully"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "User not logged in."
// @Failure 500 {object} response.BasicResponse "User is not created."
// @Resource /users
// @Router /users [post]
func createUser(c *gin.Context) {
	status, err := userService.CreateUser(c)
	messageTypes := &response.MessageTypes{
		OK:                  "registration.done",
		Unauthorized:        "login.error.fail",
		NotFound:            "registration.error.fail",
		InternalServerError: "registration.error.fail",
	}
	messages := &response.Messages{OK: "User is registered successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:22,代码来源:users.go


示例17: deleteFile

// @Title deleteFile
// @Description Delete a file.
// @Accept  json
// @Param   id        path    int     true        "File ID"
// @Success 200 {object} response.BasicResponse
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /upload/files
// @Router /upload/{id} [delete]
func deleteFile(c *gin.Context) {
	log.Debug("deleteFile performed")
	status, err := uploadService.DeleteFile(c)
	messageTypes := &response.MessageTypes{
		OK:           "destroy.done",
		BadRequest:   "destroy.fail",
		Unauthorized: "upload.file.error.unauthorized",
		NotFound:     "upload.file.error.notFound"}
	messages := &response.Messages{OK: "File is deleted successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:20,代码来源:upload.go


示例18: createArticles

// @Title createArticles
// @Description Create a file.
// @Accept  json
// @Param   title        form   string     true        "Article title."
// @Param   url        form   string     true        "Article url."
// @Param   imageName        form   string     true        "Article imagename."
// @Param   content        form   string  false        "Article content."
// @Success 201 {object} model.Article "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Article is not created"
// @Resource /upload/files
// @Router /upload [post]
func createArticles(c *gin.Context) {
	status, err := articleService.CreateArticles(c)

	messageTypes := &response.MessageTypes{
		OK:                  "article.create.done",
		Unauthorized:        "article.error.unauthorized",
		InternalServerError: "article.error.notCreated",
	}
	messages := &response.Messages{OK: "Metadata of articles are created successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:23,代码来源:articles.go


示例19: deleteLikingOnArticle

// @Title deleteLikingOnArticle
// @Description Delete a liking on article.
// @Accept  json
// @Param   articleId        path    int     true        "Article Id"
// @Param   id                path    int     true        "Liking Id"
// @Success 200 {object} response.BasicResponse "Liking 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 "Liking is not deleted"
// @Resource /articles
// @Router /articles/{id}/likings/{likingId} [delete]
func deleteLikingOnArticle(c *gin.Context) {
	status, err := articleService.DeleteLikingOnArticle(c)
	messageTypes := &response.MessageTypes{
		OK:                  "liking.unlike.done",
		Unauthorized:        "liking.error.unauthorized",
		Forbidden:           "liking.error.forbidden",
		NotFound:            "liking.error.notFound",
		InternalServerError: "liking.unlike.fail"}
	messages := &response.Messages{OK: "Article liked successfully."}

	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:tka,项目名称:goyangi,代码行数:24,代码来源:articles.go


示例20: 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 /articles/sync
// @Router /articles [post]
func uploadAndSyncArticles(c *gin.Context) {
	status, err := articleService.UploadAndSyncArticles(c)
	messageTypes := &response.MessageTypes{
		OK:                  "article.upload.done",
		BadRequest:          "article.upload.error.badRequest",
		Unauthorized:        "article.upload.error.unauthorized",
		Forbidden:           "article.upload.error.forbidden",
		NotFound:            "article.upload.error.notFound",
		InternalServerError: "article.upload.error.internalServerError",
	}
	messages := &response.Messages{OK: "Files uploaded successfully."}
	response.JSON(c, status, messageTypes, messages, err)
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:21,代码来源:articles.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang model.Location类代码示例发布时间:2022-05-23
下一篇:
Golang response.ErrorJSON函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap