當前位置: 首頁>>代碼示例>>Golang>>正文


Golang HttpContext.Json方法代碼示例

本文整理匯總了Golang中github.com/QLeelulu/goku.HttpContext.Json方法的典型用法代碼示例。如果您正苦於以下問題:Golang HttpContext.Json方法的具體用法?Golang HttpContext.Json怎麽用?Golang HttpContext.Json使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/QLeelulu/goku.HttpContext的用法示例。


在下文中一共展示了HttpContext.Json方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: link_ajaxDel

// 刪除link
func link_ajaxDel(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil {
		user := ctx.Data["user"].(*models.User)
		link, err := models.Link_GetById(linkId)
		if err == nil {
			// 隻可以刪除自己的鏈接
			if link.UserId == user.Id {
				err = models.Link_DelById(linkId)
				if err == nil {
					ok = true
				}
			} else {
				errs = "不允許的操作"
			}
		}
	}

	if err != nil {
		errs = err.Error()
	}

	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
開發者ID:polaris1119,項目名稱:ohlala,代碼行數:33,代碼來源:link.go

示例2: discover_loadMoreLink

// 加載更多link
func discover_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		ot := ctx.Get("o")
		if ot == "" {
			ot = "hot"
		}
		dt, _ := strconv.Atoi(ctx.Get("dt"))
		links, _ := models.LinkForHome_GetByPage(ot, dt, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "參數錯誤"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:31,代碼來源:discover.go

示例3: link_incClick

// 增加鏈接的點擊統計數
func link_incClick(ctx *goku.HttpContext) goku.ActionResulter {
	var success bool
	var errorMsgs string
	id := ctx.Get("id")
	if id == "" {
		errorMsgs = "參數錯誤"
	} else {
		linkId, err := strconv.ParseInt(id, 10, 64)
		if err == nil && linkId > 0 {
			_, err = models.Link_IncClickCount(linkId, 1)
			if err == nil {
				success = true
			}
		}
		if err != nil {
			goku.Logger().Error(err.Error())
			errorMsgs = err.Error()
		}
	}

	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
	}
	return ctx.Json(r)
}
開發者ID:kicool,項目名稱:ohlala,代碼行數:27,代碼來源:link.go

示例4: admin_banUser

func admin_banUser(ctx *goku.HttpContext) goku.ActionResulter {
	var err error
	var errs string
	var ok = false
	var userId, status int64

	userId, err = strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		status, err = strconv.ParseInt(ctx.Get("status"), 10, 64)
	}
	if err == nil {
		_, err = models.User_Update(userId, map[string]interface{}{"Status": status})
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:26,代碼來源:user.go

示例5: favorite_loadMoreLink

func favorite_loadMoreLink(ctx *goku.HttpContext) goku.ActionResulter {
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		user := ctx.Data["user"].(*models.User)

		links := models.FavoriteLink_ByUser(user.Id, page, golink.PAGE_SIZE)
		if links != nil && len(links) > 0 {
			ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
			vr := ctx.RenderPartial("loadmorelink", nil)
			vr.Render(ctx, vr.Body)
			html = vr.Body.String()
			hasmore = len(links) >= golink.PAGE_SIZE
		}
		success = true
	} else {
		errorMsgs = "參數錯誤"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:27,代碼來源:favorite.go

示例6: link_search_loadMore

// 加載更多的搜索link
func link_search_loadMore(ctx *goku.HttpContext) goku.ActionResulter {
	term, _ := url.QueryUnescape(ctx.Get("term"))
	page, err := strconv.Atoi(ctx.Get("page"))
	success, hasmore := false, false
	errorMsgs, html := "", ""
	if err == nil && page > 1 {
		ls := utils.LinkSearch{}
		searchResult, err := ls.SearchLink(term, page, golink.PAGE_SIZE)
		if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil {
			if len(searchResult.HitResult.HitArray) > 0 {
				links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray)
				if links != nil && len(links) > 0 {
					ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
					vr := ctx.RenderPartial("loadmorelink", nil)
					vr.Render(ctx, vr.Body)
					html = vr.Body.String()
					hasmore = len(links) >= golink.PAGE_SIZE
				}
			}
			success = true
		}
	} else {
		errorMsgs = "參數錯誤"
	}
	r := map[string]interface{}{
		"success": success,
		"errors":  errorMsgs,
		"html":    html,
		"hasmore": hasmore,
	}
	return ctx.Json(r)
}
開發者ID:hippasus,項目名稱:ohlala,代碼行數:33,代碼來源:link.go

示例7: actionUpimg

/**
 * 上傳話題圖片
 */
func actionUpimg(ctx *goku.HttpContext) goku.ActionResulter {
	var ok = false
	var errs string
	topicId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil && topicId > 0 {
		imgFile, header, err2 := ctx.Request.FormFile("topic-image")
		err = err2
		defer func() {
			if imgFile != nil {
				imgFile.Close()
			}
		}()

		if err == nil {
			ext := path.Ext(header.Filename)
			if acceptFileTypes.MatchString(ext[1:]) == false {
				errs = "錯誤的文件類型"
			} else {
				sid := strconv.FormatInt(topicId, 10)
				saveDir := path.Join(ctx.RootDir(), golink.PATH_IMAGE_AVATAR, "topic", sid[len(sid)-2:])
				err = os.MkdirAll(saveDir, 0755)
				if err == nil {
					saveName := fmt.Sprintf("%v_%v%v",
						strconv.FormatInt(topicId, 36),
						strconv.FormatInt(time.Now().UnixNano(), 36),
						ext)
					savePath := path.Join(saveDir, saveName)
					var f *os.File
					f, err = os.Create(savePath)
					defer f.Close()
					if err == nil {
						_, err = io.Copy(f, imgFile)
						if err == nil {
							// update to db
							_, err2 := models.Topic_UpdatePic(topicId, path.Join(sid[len(sid)-2:], saveName))
							err = err2
							if err == nil {
								ok = true
							}
						}
					}
				}
			}
		}
	} else if topicId < 1 {
		errs = "參數錯誤"
	}

	if err != nil {
		errs = err.Error()
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}
	return ctx.Json(r)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:60,代碼來源:topic.go

示例8: OnActionExecuting

func (tf *RequireLoginFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	if u, ok := ctx.Data["user"]; !ok || u == nil {
		if ctx.IsAjax() {
			ar = ctx.Json(map[string]interface{}{
				"success":   false,
				"needLogin": true,
				"errors":    "請先登陸",
			})
		} else {
			ar = ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI))
		}
	}
	return
}
開發者ID:polaris1119,項目名稱:ohlala,代碼行數:14,代碼來源:require_login.go

示例9: comment_LoadMore

/**
 * 加載更多評論
 */
func comment_LoadMore(ctx *goku.HttpContext) goku.ActionResulter {

	htmlObject := CommentHtml{""}
	exceptIds := ctx.Get("except_ids")
	fmt.Println("exceptIds:", exceptIds)
	parentPath := ctx.Get("parent_path")
	sortType := ctx.Get("sort_type")
	topId, err1 := strconv.ParseInt(ctx.Get("top_parent_id"), 10, 64)
	linkId, err2 := strconv.ParseInt(ctx.Get("link_id"), 10, 64)
	if err1 == nil && err2 == nil {
		htmlObject.Html = models.GetSortComments(exceptIds, parentPath, topId, linkId, sortType, "", true)
	}

	return ctx.Json(htmlObject)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:18,代碼來源:comment.go

示例10: checkUserStatus

// 檢查用戶的狀態(禁言、封號等)
func checkUserStatus(user *models.User, ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	if user != nil && user.IsBaned() {
		if ctx.Request.Method == "POST" {
			if ctx.IsAjax() {
				ar = ctx.Json(map[string]interface{}{
					"success":   false,
					"needLogin": false,
					"errors":    "你已經被禁言。",
				})
			} else {
				ctx.ViewData["errorMsg"] = "你已經被禁言"
				ar = ctx.Render("error", nil)
			}
		}
	}
	return
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:18,代碼來源:util-middleware.go

示例11: link_ajax_comment

/**
 * 提交評論並保存到數據庫
 */
func link_ajax_comment(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.NewCommentSubmitForm()
	f.FillByRequest(ctx.Request)

	var success bool
	var errorMsgs, commentHTML string
	var commentId int64
	if ctx.RouteData.Params["id"] != f.Values()["link_id"] {
		errorMsgs = "參數錯誤"
	} else {
		var errors []string
		user := ctx.Data["user"].(*models.User)
		success, commentId, errors = models.Comment_SaveForm(f, user.Id)
		if errors != nil {
			errorMsgs = strings.Join(errors, "\n")
		} else {
			linkId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
			m := f.CleanValues()
			cn := models.CommentNode{}
			cn.Id = commentId
			cn.LinkId = linkId
			cn.UserId = user.Id
			cn.Status = 1
			cn.Content = m["content"].(string)
			cn.ParentId = m["parent_id"].(int64)
			cn.ChildrenCount = 0
			cn.VoteUp = 1
			cn.CreateTime = time.Now()
			cn.UserName = user.Name

			sortType := ""
			var b *bytes.Buffer = new(bytes.Buffer)
			cn.RenderSelfOnly(b, sortType)
			commentHTML = b.String()
			//models.GetPermalinkComment(linkId, commentId, "")
		}
	}
	r := map[string]interface{}{
		"success":     success,
		"errors":      errorMsgs,
		"commentHTML": commentHTML,
	}
	return ctx.Json(r)
}
開發者ID:kicool,項目名稱:ohlala,代碼行數:48,代碼來源:link.go

示例12: admin_del_links

// 刪除link
func admin_del_links(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		err = models.Link_DelById(linkId)
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:22,代碼來源:link.go

示例13: admin_del_comments

// 刪除comment
func admin_del_comments(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	id, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil {
		err = models.Comment_DelById(id)
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:22,代碼來源:comment.go

示例14: admin_topicEditName

/**
 * 修改話題名稱
 */
func admin_topicEditName(ctx *goku.HttpContext) goku.ActionResulter {
	var ok = false
	var errs, name string
	topicId, err := strconv.ParseInt(ctx.Get("id"), 10, 64)
	name = ctx.Request.FormValue("name")
	if err == nil && topicId > 0 && name != "" {
		_, err = models.Topic_UpdateName(topicId, name)
		if err == nil {
			ok = true
		}
	} else if topicId < 1 || name == "" {
		errs = "參數錯誤"
	}

	if err != nil {
		errs = err.Error()
	}
	r := map[string]interface{}{
		"success": ok,
		"name":    name,
		"errors":  errs,
	}
	return ctx.Json(r)
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:27,代碼來源:topic.go


注:本文中的github.com/QLeelulu/goku.HttpContext.Json方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。