本文整理汇总了Golang中gitlab.com/leanlabsio/kanban/modules/middleware.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Configure
func Configure(ctx *middleware.Context, form models.BoardRequest) {
status, err := models.ConfigureBoard(ctx.User, ctx.Provider, &form)
if err != nil {
ctx.JSON(status, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{})
}
示例2: CreateMilestone
// CreateMilestone creates a new board milestone.
func CreateMilestone(ctx *middleware.Context, form models.MilestoneRequest) {
milestone, code, err := ctx.DataSource.CreateMilestone(&form)
if err != nil {
ctx.JSON(code, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: milestone,
})
}
示例3: ListBoards
// ListBoards gets a list of board accessible by the authenticated user.
func ListBoards(ctx *middleware.Context) {
boards, err := models.ListBoards(ctx.User, ctx.Provider)
if err != nil {
ctx.JSON(http.StatusUnauthorized, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: boards,
})
}
示例4: CreateComment
// CreateComment creates new kanban comment
func CreateComment(ctx *middleware.Context, form models.CommentRequest) {
com, code, err := models.CreateComment(ctx.User, ctx.Provider, &form)
if err != nil {
ctx.JSON(code, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: com,
})
}
示例5: SignUp
// SignUp sing ups with data
func SignUp(ctx *middleware.Context, form auth.SignUp) {
u, err := models.UserSignUp(form.Uname, form.Email, form.Pass, form.Token, ctx.Provider)
if err != nil {
ctx.JSON(http.StatusBadRequest, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
tokens, _ := u.SignedString()
ctx.JSON(http.StatusOK, auth.ResponseAuth{
Success: true,
Token: tokens,
})
}
示例6: MoveToCard
// MoveToCard updates an existing board card.
func MoveToCard(ctx *middleware.Context, form models.CardRequest) {
card, code, err := ctx.DataSource.UpdateCard(&form)
if err != nil {
ctx.JSON(code, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: card,
})
ctx.Broadcast(card.RoutingKey(), &models.Response{
Data: card,
Event: "card.move",
})
source := models.ParseLabelToStage(form.Stage["source"])
dest := models.ParseLabelToStage(form.Stage["dest"])
if source.Name != dest.Name {
com := models.CommentRequest{
CardId: form.CardId,
ProjectId: form.ProjectId,
Body: fmt.Sprintf("moved issue from **%s** to **%s**", source.Name, dest.Name),
}
go func() {
ctx.DataSource.CreateComment(&com)
}()
}
}
示例7: ListComments
// ListComments gets a list of comment on board and card
// accessible by the authenticated user.
func ListComments(ctx *middleware.Context) {
boards, err := models.ListComments(ctx.User, ctx.Provider, ctx.Query("project_id"), ctx.Query("issue_id"))
if err != nil {
ctx.JSON(http.StatusUnauthorized, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: boards,
})
}
示例8: ListMembers
// ListMembers gets a list of member on board accessible by the authenticated user.
func ListMembers(ctx *middleware.Context) {
members, err := ctx.DataSource.ListMembers(ctx.Query("project_id"))
if err != nil {
ctx.JSON(http.StatusUnauthorized, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, members)
}
示例9: ItemBoard
// ItemBoard gets a specific board, identified by project ID or
// NAMESPACE/BOARD_NAME, which is owned by the authenticated user.
func ItemBoard(ctx *middleware.Context) {
board, err := models.ItemBoard(ctx.User, ctx.Provider, ctx.Query("project_id"))
if err != nil {
if err, ok := err.(models.ReceivedDataErr); ok {
ctx.JSON(err.StatusCode, &models.ResponseError{
Success: false,
Message: err.Error(),
})
}
ctx.JSON(http.StatusInternalServerError, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: board,
})
}
示例10: ListLabels
// ListLabels gets a list of label on board accessible by the authenticated user.
func ListLabels(ctx *middleware.Context) {
labels, err := ctx.DataSource.ListLabels(ctx.Query("board_id"))
if err != nil {
ctx.JSON(http.StatusUnauthorized, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: labels,
})
}
示例11: DeleteCard
// DeleteCard closed an existing board card.
func DeleteCard(ctx *middleware.Context, form models.CardRequest) {
card, code, err := ctx.DataSource.DeleteCard(&form)
if err != nil {
ctx.JSON(code, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: card,
})
ctx.Broadcast(card.RoutingKey(), &models.Response{
Data: card,
Event: "card.delete",
})
}
示例12: UpdateCard
// UpdateCard updates an existing board card.
func UpdateCard(ctx *middleware.Context, form models.CardRequest) {
card, code, err := models.UpdateCard(ctx.User, ctx.Provider, &form)
if err != nil {
ctx.JSON(code, &models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, &models.Response{
Data: card,
})
ctx.Broadcast(card.RoutingKey(), &models.Response{
Data: card,
Event: "card.update",
})
}
示例13: OauthLogin
// OauthLogin logins with gitlab and get access token
func OauthLogin(ctx *middleware.Context, form auth.Oauth2) {
tok, err := models.Exchange(form.Provider, form.Code)
if err != nil {
log.Printf("%s", err.Error())
ctx.JSON(http.StatusBadRequest, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
user, err := models.UserOauthSignIn(form.Provider, tok)
if err != nil {
log.Printf("%s", err.Error())
ctx.JSON(http.StatusBadRequest, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
user, err = models.LoadByToken(user, ctx.Provider)
if err != nil {
log.Printf("%s", err.Error())
ctx.JSON(http.StatusBadRequest, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
user.Username = fmt.Sprintf("%s_%s", user.Username, ctx.Provider)
_, err = models.UpdateUser(user)
// todo add validation by oauth provider
if err != nil {
user, err = models.CreateUser(user)
}
if err != nil {
log.Printf("%s", err.Error())
ctx.JSON(http.StatusInternalServerError, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
tokens, err := user.SignedString()
if err != nil {
log.Printf("%s", err.Error())
ctx.JSON(http.StatusBadRequest, models.ResponseError{
Success: false,
Message: err.Error(),
})
return
}
ctx.JSON(http.StatusOK, auth.ResponseAuth{
Success: true,
Token: tokens,
})
}
示例14: OauthUrl
// OauthUrl redirects to url for authorisation
func OauthUrl(ctx *middleware.Context) {
ctx.Redirect(models.AuthCodeURL(ctx.Query("provider")))
}
示例15: OauthHandler
// OauthHandler handles request from other services
func OauthHandler(ctx *middleware.Context) {
ctx.HTML(200, "templates/oauth")
}