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

Golang httperr.New函数代码示例

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

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



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

示例1: AddPost

func AddPost(requesterID string, post *types.Post) httperr.Error {
	jsonFields, err := json.Marshal(post.Fields)
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	err = db.Exec("INSERT INTO posts "+
		"(p_postid, p_userid_creator, p_channelname, p_title, p_thumbnail, p_time, p_location, p_fields) "+
		"VALUES (?, ?, ?, ?, ?, ?, ST_MakePoint(?,?), ?)",
		post.ID, post.CreatorID, post.Channel, post.Title, post.Thumbnail, post.Time,
		post.Location.Longitude, post.Location.Latitude, jsonFields).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:15,代码来源:posts.go


示例2: AddComment

func AddComment(requesterID string, comment *types.Comment) httperr.Error {
	err := db.Create(comment).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:7,代码来源:comments.go


示例3: RemoveComment

func RemoveComment(requesterID, commentID string) httperr.Error {
	err := db.Where("cmd_commentid = ?", commentID).Delete(&types.Comment{}).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:7,代码来源:comments.go


示例4: AddChannel

func AddChannel(channel *types.Channel) httperr.Error {
	err := db.Create(channel).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:7,代码来源:channels.go


示例5: AddUser

// AddUser adds the given User to the database, or returns an error if the
// insertion was unsuccessful.
func AddUser(user *types.User) httperr.Error {
	err := db.Create(user).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:9,代码来源:users.go


示例6: GetComments

func GetComments(requesterID, postID string) ([]*types.Comment, httperr.Error) {
	var comments []*types.Comment
	err := db.Where("cmt_postid = ?", postID).Order("cmt_time").Find(&comments).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return comments, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:8,代码来源:comments.go


示例7: IsCommentCreator

func IsCommentCreator(requesterID, userID, commentID string) (bool, httperr.Error) {
	var comment types.Comment
	err := db.Where("cmt_commentid = ?", commentID).First(&comment).Error
	if err == gorm.ErrRecordNotFound {
		return false, nil
	} else if err != nil {
		return false, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return true, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:10,代码来源:comments.go


示例8: GetComment

// GetComment returns a comment with the given ID, or nil if it does not exist.
// An error is returned if some issue occurred with the database.
func GetComment(requesterID, commentID string) (*types.Comment, httperr.Error) {
	var comment types.Comment
	err := db.Where("cmt_commentid = ?", commentID).First(&comment).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		}
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return &comment, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:13,代码来源:comments.go


示例9: GetUserByID

// GetUserByID returns the user with the given ID if one exists, nil otherwise.
// Returns an error if some error occurs within the database.
func GetUserByID(userID string) (*types.User, httperr.Error) {
	var user types.User
	err := db.Where("u_userid = ?", userID).First(&user).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		}
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return &user, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:13,代码来源:users.go


示例10: GetChannels

func GetChannels(requesterID string) ([]*types.PersonalizedChannelInfo, httperr.Error) {
	var channels []*types.PersonalizedChannelInfo
	err := db.Table("channels").
		Joins("LEFT JOIN user_subscriptions ON (ch_channelname = us_channelname AND us_userid = ?)", requesterID).
		Joins("LEFT JOIN users ON (u_userid = ch_userid_creator)").
		Select("*, (us_channelname IS NOT NULL) AS subscribed").
		Order("ch_channelname").Find(&channels).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return channels, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:12,代码来源:channels.go


示例11: GetPost

func GetPost(requesterID, postID string) (*types.PersonalizedPost, httperr.Error) {
	var post types.PersonalizedPost
	err := db.Table("posts").
		Where("p_postid = ?", postID).
		Joins("LEFT JOIN user_favorites ON (p_postid = uf_postid AND uf_userid = ?)", requesterID).
		Joins("LEFT JOIN users ON (u_userid = p_userid_creator)").
		Select("*, (uf_postid IS NOT NULL) AS favorited, ST_AsText(p_location) AS location").
		First(&post).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return &post, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:13,代码来源:posts.go


示例12: RemoveFavorite

// RemoveFavorite removes the given post from the user with ID userID's set of
// favorites. This transaction is executed under the permission level of the
// requester. Returns an error if the requester does not have sufficient
// permission, or if some other error occurs within the database.
func RemoveFavorite(requesterID, userID, postID string) httperr.Error {
	permission, httpErr := CanModifyFavorites(requesterID, userID)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("DELETE FROM user_favorites WHERE uf_userid = ? AND uf_postid = ?", requesterID, postID).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:17,代码来源:favorites.go


示例13: AddFavorite

// AddFavorite adds the given post to the set of favorites for the user with ID
// userID. This transaction is executed under the permission level of the
// requester. Returns an error if the requester does not have sufficient
// permission, or if some other error occurs within the database.
func AddFavorite(requesterID, userID, postID string) httperr.Error {
	permission, httpErr := CanModifyFavorites(requesterID, userID)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("INSERT INTO user_favorites (uf_userid, uf_postid) VALUES (?, ?)", requesterID, postID).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:17,代码来源:favorites.go


示例14: RemoveSubscription

func RemoveSubscription(requesterID, userID, channelname string) httperr.Error {
	permission, httpErr := CanModifySubscriptions(requesterID, userID)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("DELETE FROM user_subscriptions WHERE us_userid = ? AND us_channelname = ?", requesterID, channelname).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:13,代码来源:subscriptions.go


示例15: RemoveBan

// RemoveBan removes the user with ID userID from the ban list for the given
// channel. This transaction is executed under the permission level of the given
// requester. Returns an error if the requester does not have sufficient
// permission, or if some other error occurs within the database.
func RemoveBan(requesterID, userID, channelname string) error {
	permission, httpErr := CanModifyBans(requesterID, channelname)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("DELETE FROM channel_bans WHERE chb_userid = ? and chb_channelname = ?", userID, channelname).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:17,代码来源:bans.go


示例16: AddSubscription

func AddSubscription(requesterID, userID, channelname string) httperr.Error {
	permission, httpErr := CanModifySubscriptions(requesterID, userID)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("INSERT INTO user_subscriptions (us_userid, us_channelname) VALUES (?, ?)", requesterID, channelname).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:13,代码来源:subscriptions.go


示例17: AddBan

// AddBan adds the user with ID userID to the ban list for the given channel.
// This transaction is executed under the permission level of the given
// requester. Returns an error if the requester does not have sufficient
// permission, or if some other error occurs within the database.
func AddBan(requesterID, userID, channelname string) httperr.Error {
	permission, httpErr := CanModifyBans(requesterID, channelname)
	if httpErr != nil {
		return httpErr
	} else if !permission {
		return ErrInsufficientPermission
	}
	err := db.Exec("INSERT INTO channel_bans (chb_userid, chb_channelname) VALUES (?, ?);", userID, channelname).Error
	if err != nil {
		return httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:17,代码来源:bans.go


示例18: GetBans

// GetBans returns the list of users which are banned from the given channel.
// This transaction is executed under the permission level of the given
// requester. Returns an error if the requester does not have sufficient
// permission, or if some other error occurs within the database.
func GetBans(requesterID, channelname string) ([]string, httperr.Error) {
	permission, httpErr := CanViewBans(requesterID, channelname)
	if httpErr != nil {
		return nil, httpErr
	} else if !permission {
		return nil, ErrInsufficientPermission
	}
	var bans []string
	err := db.Table("channel_bans").Select("chb_userid").Where("chb_channelname = ?", channelname).Scan(&bans).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return bans, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:18,代码来源:bans.go


示例19: GetChannel

func GetChannel(requesterID, channelname string) (*types.PersonalizedChannel, httperr.Error) {
	// TODO: Account for requester permission
	var channel types.PersonalizedChannel
	err := db.Table("channels").
		Joins("LEFT JOIN user_subscriptions ON (ch_channelname = us_channelname AND us_userid = ?)", requesterID).
		Joins("LEFT JOIN users ON (u_userid = ch_userid_creator)").
		Select("*, (us_channelname IS NOT NULL) AS subscribed").
		Where("ch_channelname = ?", channelname).
		First(&channel).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return &channel, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:14,代码来源:channels.go


示例20: GetPosts

func GetPosts(requesterID string, postQueryParams *PostQueryParams) ([]*types.PersonalizedPostInfo, httperr.Error) {
	var posts []*types.PersonalizedPostInfo
	query := db.Table("posts").
		Joins("LEFT JOIN user_favorites ON (p_postid = uf_postid AND uf_userid = ?)", requesterID).
		Joins("LEFT JOIN user_subscriptions ON (p_channelname = us_channelname AND us_userid = ?)", requesterID).
		Joins("LEFT JOIN users ON (u_userid = p_userid_creator)").
		Select("*, (uf_postid IS NOT NULL) AS favorited, ST_AsText(p_location) AS location, (us_channelname IS NOT NULL) AS subscribed").
		Order("p_time desc")

	if postQueryParams.Flags != nil {
		if postQueryParams.Flags.Mine {
			query = query.Where("p_userid_creator = ?", requesterID)
		}
		if postQueryParams.Flags.Favorites {
			query = query.Where("uf_postid IS NOT NULL")
		}
		if postQueryParams.Flags.Subscriptions {
			query = query.Where("us_channelname IS NOT NULL")
		}
	}
	if postQueryParams.LocationRange != nil {
		query = query.Where("p_location && ST_MakeEnvelope (?,?,?,?)",
			postQueryParams.LocationRange.Min.Longitude,
			postQueryParams.LocationRange.Min.Latitude,
			postQueryParams.LocationRange.Max.Longitude,
			postQueryParams.LocationRange.Max.Latitude)
	}
	if postQueryParams.TimeRange != nil {
		query = query.Where("p_time > ? AND p_time < ?",
			postQueryParams.TimeRange.Min,
			postQueryParams.TimeRange.Max)
	}
	if postQueryParams.Limit != nil {
		query = query.Limit(*postQueryParams.Limit)
	}
	if postQueryParams.Offset != nil {
		query = query.Offset(*postQueryParams.Offset)
	}

	err := query.Find(&posts).Error
	if err != nil {
		return nil, httperr.New(err.Error(), http.StatusInternalServerError)
	}
	return posts, nil
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:45,代码来源:posts.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang gcode.Block类代码示例发布时间:2022-05-23
下一篇:
Golang session.Instance函数代码示例发布时间: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