本文整理汇总了Golang中github.com/dorajistyle/goyangi/api/response.ErrorJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorJSON函数的具体用法?Golang ErrorJSON怎么用?Golang ErrorJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorJSON函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: retrieveFile
// @Title retrieveFile
// @Description Retrieve a file.
// @Accept json
// @Param id path int true "File ID"
// @Success 200 {object} model.File "OK"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /upload/files
// @Router /upload/{id} [get]
func retrieveFile(c *gin.Context) {
file, status, err := uploadService.RetrieveFile(c)
if err == nil {
c.JSON(status, gin.H{"file": file})
} else {
messageTypes := &response.MessageTypes{NotFound: "upload.file.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例2: createLocation
// @Title createLocation
// @Description Create an location.
// @Accept json
// @Param title form string true "Location title."
// @Param url form string true "Location url"
// @Param latitude form int true "Location latitude"
// @Param longitude form int true "Location longitude"
// @Param content form string false "Location content"
// @Success 201 {object} model.Location "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Location is not created"
// @Resource /locations
// @Router /locations [post]
func createLocation(c *gin.Context) {
location, status, err := locationService.CreateLocation(c)
if err == nil {
c.JSON(status, gin.H{"location": location})
} else {
messageTypes := &response.MessageTypes{InternalServerError: "location.error.notCreated"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例3: retrieveRole
// @Title retrieveRole
// @Description Retrieve a role.
// @Accept json
// @Param id path int true "Role ID"
// @Success 200 {object} model.Role "OK"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /roles
// @Router /roles/{id} [get]
func retrieveRole(c *gin.Context) {
role, status, err := roleService.RetrieveRole(c)
if err == nil {
c.JSON(status, gin.H{"role": role})
} else {
messageTypes := &response.MessageTypes{NotFound: "role.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例4: createArticle
// @Title createArticle
// @Description Create an article.
// @Accept json
// @Param title form string true "Article title."
// @Param url form string true "Article url."
// @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 /articles
// @Router /articles [post]
func createArticle(c *gin.Context) {
article, status, err := articleService.CreateArticle(c)
if err == nil {
c.JSON(status, gin.H{"article": article})
} else {
messageTypes := &response.MessageTypes{InternalServerError: "article.error.notCreated"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例5: retrieveArticles
// @Title retrieveArticles
// @Description Retrieve article array.
// @Accept json
// @Success 200 {array} model.Article "OK"
// @Resource /articles
// @Router /articles [get]
func retrieveArticles(c *gin.Context) {
articles, canWrite, category, currentPage, hasPrev, hasNext, status, err := articleService.RetrieveArticles(c)
if err == nil {
c.JSON(status, gin.H{"articles": articles, "canWrite": canWrite, "category": category, "currentPage": currentPage,
"hasPrev": hasPrev, "hasNext": hasNext})
} else {
messageTypes := &response.MessageTypes{}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例6: retrieveCommentsOnLocation
// @Title retrieveCommentsOnLocation
// @Description Retrieve comments on an location.
// @Accept json
// @Param locationId path int true "Location 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 [get]
func retrieveCommentsOnLocation(c *gin.Context) {
comments, currentPage, hasPrev, hasNext, count, status, err := locationService.RetrieveCommentsOnLocation(c)
if err == nil {
c.JSON(status, gin.H{"comments": comments, "currentPage": currentPage, "hasPrev": hasPrev, "hasNext": hasNext, "count": count})
} else {
messageTypes := &response.MessageTypes{
NotFound: "comment.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例7: retrieveLocations
// @Title retrieveLocations
// @Description Retrieve location array.
// @Accept json
// @Success 200 {array} model.Location "OK"
// @Resource /locations
// @Router /locations [get]
func retrieveLocations(c *gin.Context) {
locations, canWrite, currentPage, hasPrev, hasNext, status, err := locationService.RetrieveLocations(c)
if err == nil {
c.JSON(status, gin.H{"locations": locations, "canWrite": canWrite, "currentPage": currentPage,
"hasPrev": hasPrev, "hasNext": hasNext})
} else {
messageTypes := &response.MessageTypes{}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例8: retrieveOauthStatus
// @Title retrieveOauthStatus
// @Description Retrieve oauth connections.
// @Accept json
// @Success 200 {array} oauthService.oauthStatusMap "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Resource /oauth
// @Router /oauth [get]
func retrieveOauthStatus(c *gin.Context) {
oauthStatus, status, err := oauthService.RetrieveOauthStatus(c)
if err == nil {
c.JSON(status, gin.H{"oauthStatus": oauthStatus})
} else {
messageTypes := &response.MessageTypes{
Unauthorized: "oauth.error.unauthorized",
}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例9: createRole
// @Title createRole
// @Description Create a role.
// @Accept json
// @Param name form string true "Name of Role."
// @Param description form string true "Description of Role."
// @Success 201 {object} model.Role "Created"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 500 {object} response.BasicResponse "Role is not created"
// @Resource /roles
// @Router /roles [post]
func createRole(c *gin.Context) {
role, status, err := roleService.CreateRole(c)
if err == nil {
c.JSON(status, gin.H{"role": role})
} else {
messageTypes := &response.MessageTypes{Unauthorized: "role.error.unauthorized",
InternalServerError: "admin.role.create.fail"}
response.ErrorJSON(c, status, messageTypes, err)
// c.JSON(400, gin.H{"role": nil})
}
}
示例10: retrieveLocation
// @Title retrieveLocation
// @Description Retrieve an location.
// @Accept json
// @Param id path int true "Location Id"
// @Success 200 {object} model.Location "OK"
// @Failure 404 {object} response.BasicResponse "Location is not found"
// @Resource /locations
// @Router /locations/{id} [get]
func retrieveLocation(c *gin.Context) {
location, isAuthor, currentUserId, status, err := locationService.RetrieveLocation(c)
if err == nil {
c.JSON(status, gin.H{"location": location, "isAuthor": isAuthor, "currentUserId": currentUserId})
} else {
messageTypes := &response.MessageTypes{
NotFound: "location.error.notFound",
}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例11: retrieveArticle
// @Title retrieveArticle
// @Description Retrieve an article.
// @Accept json
// @Param id path int true "Article Id"
// @Success 200 {object} model.Article "OK"
// @Failure 404 {object} response.BasicResponse "Article is not found"
// @Resource /articles
// @Router /articles/{id} [get]
func retrieveArticle(c *gin.Context) {
article, isAuthor, currentUserId, status, err := articleService.RetrieveArticle(c)
if err == nil {
c.JSON(status, gin.H{"article": article, "isAuthor": isAuthor, "currentUserId": currentUserId})
} else {
messageTypes := &response.MessageTypes{
NotFound: "article.error.notFound",
}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例12: retrieveLikingsOnArticles
// @Title retrieveLikingsOnArticles
// @Description Retrieve likings on an article.
// @Accept json
// @Param articleId path int true "Article Id"
// @Success 200 {array} model.PublicUser "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Resource /articles
// @Router /articles/{id}/likings [get]
func retrieveLikingsOnArticles(c *gin.Context) {
likings, currentPage, hasPrev, hasNext, count, status, err := articleService.RetrieveLikingsOnArticles(c)
if err == nil {
c.JSON(status, gin.H{"likings": likings, "currentPage": currentPage,
"hasPrev": hasPrev, "hasNext": hasNext, "count": count})
} else {
messageTypes := &response.MessageTypes{
NotFound: "liking.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例13: updateFile
// @Title updateFile
// @Description Update a file.
// @Accept json
// @Param id path int true "File ID"
// @Success 200 {object} model.File "OK"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Not found"
// @Failure 500 {object} response.BasicResponse "File is not updated"
// @Resource /upload/files
// @Router /upload/{id} [put]
func updateFile(c *gin.Context) {
file, status, err := uploadService.UpdateFile(c)
if err == nil {
c.JSON(status, gin.H{"file": file})
} else {
messageTypes := &response.MessageTypes{Unauthorized: "upload.file.error.unauthorized",
NotFound: "upload.file.error.notFound",
InternalServerError: "upload.file.update.fail"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例14: updateArticle
// @Title updateArticle
// @Description Update an article.
// @Accept json
// @Param id path int true "Article Id"
// @Success 200 {object} model.Article "OK"
// @Failure 400 {object} response.BasicResponse "Article is not updated"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Article is not found"
// @Resource /articles
// @Router /articles/{id} [put]
func updateArticle(c *gin.Context) {
article, status, err := articleService.UpdateArticle(c)
if err == nil {
c.JSON(status, gin.H{"article": article})
} else {
messageTypes := &response.MessageTypes{
BadRequest: "article.view.updated.fail",
Unauthorized: "article.error.isNotAuthor",
NotFound: "article.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}
示例15: updateLocation
// @Title updateLocation
// @Description Update an location.
// @Accept json
// @Param id path int true "Location Id"
// @Success 200 {object} model.Location "OK"
// @Failure 400 {object} response.BasicResponse "Location is not updated"
// @Failure 401 {object} response.BasicResponse "Authentication required"
// @Failure 404 {object} response.BasicResponse "Location is not found"
// @Resource /locations
// @Router /locations/{id} [put]
func updateLocation(c *gin.Context) {
location, status, err := locationService.UpdateLocation(c)
if err == nil {
c.JSON(status, gin.H{"location": location})
} else {
messageTypes := &response.MessageTypes{
BadRequest: "location.view.updated.fail",
Unauthorized: "location.error.isNotAuthor",
NotFound: "location.error.notFound"}
response.ErrorJSON(c, status, messageTypes, err)
}
}