本文整理匯總了Golang中github.com/nerdzeu/nerdz-api/rest.SelectFields函數的典型用法代碼示例。如果您正苦於以下問題:Golang SelectFields函數的具體用法?Golang SelectFields怎麽用?Golang SelectFields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SelectFields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PostComment
// PostComment handles the request and returns the single comment required
func PostComment() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts/{pid}/comments/{cid} project post comment GetProjectPostComment
//
// Shows selected comment on specified post, filtered by some parameters.
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:read", c) {
return rest.InvalidScopeResponse("project_comments:read", c)
}
comment := c.Get("comment").(*nerdz.ProjectPostComment)
me := c.Get("me").(*nerdz.User)
return rest.SelectFields(comment.GetTO(me), c)
}
}
示例2: Whitelist
// Whitelist handles the request and returns the user whitelist
func Whitelist() echo.HandlerFunc {
// swagger:route GET /users/{id}/whitelist user whitelist GetWhitelist
//
// Show the whitelist of the specified user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
whitelist := c.Get("other").(*nerdz.User).Whitelist()
return rest.SelectFields(rest.GetUsersInfo(whitelist), c)
}
}
示例3: Blacklisting
// Blacklisting handles the request and returns the user blacklisting
func Blacklisting() echo.HandlerFunc {
// swagger:route GET /users/{id}/blacklisting user blacklisting GetWhitelisting
//
// Show the user that placed the specified user in their blacklist
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
blacklisting := c.Get("other").(*nerdz.User).Blacklisting()
return rest.SelectFields(rest.GetUsersInfo(blacklisting), c)
}
}
示例4: UserFollowing
// UserFollowing handles the request and returns the user following
func UserFollowing() echo.HandlerFunc {
// swagger:route GET /users/{id}/following/users user info following GetUserFollowing
//
// Shows the following informations for the specified user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
following := c.Get("other").(*nerdz.User).UserFollowing()
return rest.SelectFields(rest.GetUsersInfo(following), c)
}
}
示例5: Followers
// Followers handles the request and returns the project followers
func Followers() echo.HandlerFunc {
// swagger:route GET /projects/{id}/followers project info followers getProjectFollowers
//
// Shows the followers informations for the specified project
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: projects:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("projects:read", c) {
return rest.InvalidScopeResponse("projects:read", c)
}
followers := c.Get("project").(*nerdz.Project).Followers()
return rest.SelectFields(rest.GetUsersInfo(followers), c)
}
}
示例6: Post
// Post handles the request and returns the single post required
func Post() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts/{pid} project post getProjectPost
//
// Shows selected posts with id pid on specified project board
//
// This will show the last comments on the post by default.
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:read", c) {
return rest.InvalidScopeResponse("project_messages:read", c)
}
me := c.Get("me").(*nerdz.User)
postTO := c.Get("post").(*nerdz.ProjectPost).GetTO(me)
return rest.SelectFields(postTO, c)
}
}
示例7: Pm
// Pm handles the request and returns the specified Private Message
func Pm() echo.HandlerFunc {
// swagger:route GET /me/pms/{other}/{pmid} user pms GetUserPm
//
// Update the speficied post on the specified user board
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: pms:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("pms:read", c) {
return rest.InvalidScopeResponse("pms:read", c)
}
pm := c.Get("pm").(*nerdz.Pm)
me := c.Get("me").(*nerdz.User)
return rest.SelectFields(pm.GetTO(me), c)
}
}
示例8: NewBlacklisted
// NewBlacklisted handles the request and creates and adds target user to current user whitelist
func NewBlacklisted() echo.HandlerFunc {
// swagger:route POST /me/whitelist/{target} user whitelist NewBlacklisted
//
// Adds target to the whitelist of the current user
//
// Produces:
// - application/json
//
// Consumes:
// - application/json
//
// Security:
// oauth: profile:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:write", c) {
return rest.InvalidScopeResponse("profile:write", c)
}
var target *nerdz.User
var err error
if target, err = rest.User("target", c); err != nil {
return err
}
// Read a rest.NewMessage from the body request.
message := rest.NewMessage{}
if err := c.Bind(&message); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
me := c.Get("me").(*nerdz.User)
if err = me.BlacklistUser(target, message.Message); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Return selected field from the followed User
return rest.SelectFields(target.GetTO(me), c)
}
}
示例9: NewPostCommentVote
// NewPostCommentVote handles the request and creates a new vote on the user comment post
func NewPostCommentVote() echo.HandlerFunc {
// swagger:route POST /projects/{id}/posts/{pid}/comments/{cid}votes project post comment vote NewProjectPostCommentVote
//
// Adds a new vote on the current project post comment
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:write", c) {
return rest.InvalidScopeResponse("project_comments:write", c)
}
// Read a rest.NewVote from the body request.
body := rest.NewVote{}
if err := c.Bind(&body); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Send it
me := c.Get("me").(*nerdz.User)
comment := c.Get("comment").(*nerdz.ProjectPostComment)
vote, err := me.Vote(comment, body.Vote)
if err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Extract the TO from the new post and return
// selected fields.
return rest.SelectFields(vote.(*nerdz.ProjectPostCommentVote).GetTO(me), c)
}
}
示例10: Posts
// Posts handles the request and returns the required posts written by the specified project
func Posts() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts project posts getProjectPosts
//
// List posts on project board, filtered by some parameters.
//
// This will show the last posts on the project board by default.
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:read", c) {
return rest.InvalidScopeResponse("project_messages:read", c)
}
project := c.Get("project").(*nerdz.Project)
options := c.Get("postlistOptions").(*nerdz.PostlistOptions)
options.Model = nerdz.ProjectPost{}
posts := project.Postlist(*options)
if posts == nil {
errstr := "Unable to fetch post list for the specified project"
c.JSON(http.StatusBadRequest, &rest.Response{
HumanMessage: errstr,
Message: "project.Postlist error",
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
me := c.Get("me").(*nerdz.User)
var postsAPI []*nerdz.PostTO
for _, p := range *posts {
// posts contains ExistingPost elements
// we need to convert back to a ProjectPost in order to get a correct PostTO
if projectPost := p.(*nerdz.ProjectPost); projectPost != nil {
postsAPI = append(postsAPI, projectPost.GetTO(me))
}
}
return rest.SelectFields(postsAPI, c)
}
}
示例11: Conversation
// Conversation handles the request and returns the user private conversation with the other user
func Conversation() echo.HandlerFunc {
// swagger:route GET /me/pms/{other} user post pms getUserConversation
//
// Returns the private conversation of the current user with the other user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("pms:read", c) {
return rest.InvalidScopeResponse("pms:read", c)
}
var other *nerdz.User
var err error
if other, err = rest.User("other", c); err != nil {
return err
}
// fetch conversation between me and other
var conversation *[]nerdz.Pm
options := c.Get("pmsOptions").(*nerdz.PmsOptions)
me := c.Get("me").(*nerdz.User)
conversation, err = me.Pms(other.ID(), *options)
if err != nil {
errstr := "Unable to fetch conversation with the specified user"
c.JSON(http.StatusBadRequest, &rest.Response{
HumanMessage: errstr,
Message: "me.Conversation error",
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
var conversationTO []*nerdz.PmTO
for _, pm := range *conversation {
conversationTO = append(conversationTO, pm.GetTO(me))
}
return rest.SelectFields(conversationTO, c)
}
}
示例12: NewPostUserLock
// NewPostUserLock handles the request and creates a new lock for the notification
// caused by the target user
func NewPostUserLock() echo.HandlerFunc {
// swagger:route POST /projects/{id}/posts/{pid}/locks/{target} project post vote NewUserNewPostUserLock
//
// Locks the notification from the target user to the current logged user, on the specified post
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:write", c) {
return rest.InvalidScopeResponse("project_messages:write", c)
}
var target *nerdz.User
var err error
if target, err = rest.User("target", c); err != nil {
return err
}
me := c.Get("me").(*nerdz.User)
post := c.Get("post").(*nerdz.ProjectPost)
var lock *[]nerdz.Lock
lock, err = me.Lock(post, target)
if err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Extract the TO from the new lock and return selected fields.
return rest.SelectFields((*lock)[0].(*nerdz.ProjectPostUserLock).GetTO(me), c)
}
}
示例13: NewPostComment
// NewPostComment handles the request and creates a new post
func NewPostComment() echo.HandlerFunc {
// swagger:route POST /projects/{id}/posts/{pid}/comments project post comment NewProjectPostComment
//
// Creates a new post on the specified project board
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:write", c) {
return rest.InvalidScopeResponse("project_comments:write", c)
}
// Read a rest.Message from the body request.
message := rest.NewMessage{}
if err := c.Bind(&message); err != nil {
return err
}
// Create a nerdz.ProjectPostComment from the message
// and current context.
comment := nerdz.ProjectPostComment{}
comment.Message = message.Message
comment.Lang = message.Lang
comment.To = c.Get("project").(*nerdz.Project).ID()
comment.Hpid = c.Get("post").(*nerdz.ProjectPost).ID()
// Send it
me := c.Get("me").(*nerdz.User)
if err := me.Add(&comment); err != nil {
return err
}
// Extract the TO from the new post and return
// selected fields.
return rest.SelectFields(comment.GetTO(me), c)
}
}
示例14: PostComments
// PostComments handles the request and returns the specified list of comments
func PostComments() echo.HandlerFunc {
// swagger:route GET /users/{id}/posts/{pid}/comments user post comments GetUserPostComments
//
// List comments on specified post, filtered by some parameters.
//
// This will show the last posts on the user board by default.
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile_comments:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile_comments:read", c) {
return rest.InvalidScopeResponse("profile_comments:read", c)
}
comments := c.Get("post").(*nerdz.UserPost).Comments(*(c.Get("commentlistOptions").(*nerdz.CommentlistOptions)))
if comments == nil {
errstr := "Unable to fetch comment list for the specified post"
c.JSON(http.StatusBadRequest, &rest.Response{
HumanMessage: errstr,
Message: "UserPost.Comments(options) error",
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
var commentsAPI []*nerdz.UserPostCommentTO
me := c.Get("me").(*nerdz.User)
for _, p := range *comments {
// comments contains ExistingPost elements
// we need to convert back to a UserPostComment in order to get a correct UserPostCommentTO
if userPostComment := p.(*nerdz.UserPostComment); userPostComment != nil {
commentsAPI = append(commentsAPI, userPostComment.GetTO(me))
}
}
return rest.SelectFields(commentsAPI, c)
}
}
示例15: EditPostComment
// EditPostComment handles the request and edits the post comment
func EditPostComment() echo.HandlerFunc {
// swagger:route PUT /projects/{id}/posts/{pid}/comments/{cid} project post comment EditProjectPost
//
// Update the speficied post on the specified project board
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:write", c) {
return rest.InvalidScopeResponse("project_comments:write", c)
}
// Read a rest.Message from the body request.
message := rest.NewMessage{}
if err := c.Bind(&message); err != nil {
return err
}
comment := c.Get("comment").(*nerdz.ProjectPostComment)
// Update filds
comment.Message = message.Message
if comment.Lang != "" {
comment.Lang = message.Lang
}
// Edit
me := c.Get("me").(*nerdz.User)
if err := me.Edit(comment); err != nil {
return err
}
// Extract the TO from the comment and return selected fields.
return rest.SelectFields(comment.GetTO(me), c)
}
}