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


Golang HttpContext.Get方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: home_index

func home_index(ctx *goku.HttpContext) goku.ActionResulter {
	u, ok := ctx.Data["user"]
	if !ok || u == nil {
		return ctx.Redirect("/discover")
	}
	user := u.(*models.User)
	if user.FriendCount+user.FtopicCount < 1 {
		return home_guideForNew(ctx)
	}
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	ctx.ViewData["Order"] = ot
	links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新鏈接的未讀提醒
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_Friends(user.Id, user.LastReadFriendLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(user.Id, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		models.NewestLinkUnread_UpdateForUser(user.Id, links[0].Id)
	}

	return ctx.View(nil)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:28,代碼來源:home.go

示例4: 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

示例5: 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

示例6: link_submit

/**
 * 提交一個鏈接並保存到數據庫
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

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

	var resubmit bool
	if ctx.Get("resubmit") == "true" {
		resubmit = true
	}
	user := ctx.Data["user"].(*models.User)
	success, linkId, errorMsgs, _ := models.Link_SaveForm(f, user.Id, resubmit)

	if success {
		go addLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本   TODO:

		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else if linkId > 0 {
		return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
開發者ID:hippasus,項目名稱:ohlala,代碼行數:28,代碼來源:link.go

示例7: actionPopupBoxInfo

/**
 * 獲取用戶信息
 * 用於浮動層
 */
func actionPopupBoxInfo(ctx *goku.HttpContext) goku.ActionResulter {

	topicName := ctx.Get("t")
	topic, _ := models.Topic_GetByName(topicName)

	if topic != nil {
		return ctx.RenderPartial("pop-info", models.Topic_ToVTopic(topic, ctx))
	}
	return ctx.Html("")
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:14,代碼來源:topic.go

示例8: discover_index

// 發現 首頁
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	return ctx.Render("/home/index", nil)
}
開發者ID:hippasus,項目名稱:ohlala,代碼行數:14,代碼來源:discover.go

示例9: link_showWithComments

func link_showWithComments(ctx *goku.HttpContext, slinkId, scommentId string) goku.ActionResulter {

	linkId, err1 := strconv.ParseInt(slinkId, 10, 64)
	commentId, err2 := strconv.ParseInt(scommentId, 10, 64)
	if err1 != nil || err2 != nil {
		ctx.ViewData["errorMsg"] = "參數錯誤"
		return ctx.Render("error", nil)
	}
	link, err := models.Link_GetById(linkId)
	if err != nil {
		ctx.ViewData["errorMsg"] = "服務器開小差了 >_<!!"
		return ctx.Render("error", nil)
	}

	if link == nil {
		ctx.ViewData["errorMsg"] = "內容不存在,去首頁逛逛吧"
		return ctx.Render("error", nil)
	}

	if link.Deleted() {
		ctx.ViewData["errorMsg"] = "內容已被摧毀,去首頁逛逛吧"
		return ctx.Render("error", nil)
	}

	if !utils.IsSpider(ctx.Request.UserAgent()) {
		// 更新鏈接的評論查看計數
		models.Link_IncViewCount(link.Id, 1)
	}

	vlink := models.Link_ToVLink([]models.Link{*link}, ctx)
	sortType := strings.ToLower(ctx.Get("cm_order")) //"hot":熱門;"hotc":熱議;"time":最新;"vote":得分;"ctvl":"爭議"
	if sortType == "" {
		sortType = "hot"
	}
	var comments string
	if commentId > 0 {
		comments = models.GetPermalinkComment(linkId, commentId, sortType)
		ctx.ViewData["SubLinkUrl"] = fmt.Sprintf("permacoment/%d/%d/", linkId, commentId)
	} else {
		comments = models.GetSortComments("", "/", int64(0), linkId, sortType, "", false) //models.Comment_SortForLink(link.Id, "hot")
		ctx.ViewData["SubLinkUrl"] = linkId
	}

	ctx.ViewData["Comments"] = template.HTML(comments)
	ctx.ViewData["SortType"] = sortType
	ctx.ViewData["SortTypeName"] = ORDER_NAMES[sortType]

	return ctx.Render("/link/show", vlink[0])
}
開發者ID:kicool,項目名稱:ohlala,代碼行數:49,代碼來源:link.go

示例10: link_search

//link搜索界麵
func link_search(ctx *goku.HttpContext) goku.ActionResulter {
	ls := utils.LinkSearch{}
	searchResult, err := ls.SearchLink(ctx.Get("term"), 1, golink.PAGE_SIZE)
	if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil && len(searchResult.HitResult.HitArray) > 0 {
		links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray)
		ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
		ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	} else {
		ctx.ViewData["Links"] = nil
		ctx.ViewData["HasMoreLink"] = false
	}
	ctx.ViewData["Term"] = ctx.Get("term")

	return ctx.Render("/link/search", nil)
}
開發者ID:hippasus,項目名稱:ohlala,代碼行數:16,代碼來源:link.go

示例11: 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

示例12: home_index

func home_index(ctx *goku.HttpContext) goku.ActionResulter {
	u, ok := ctx.Data["user"]
	if !ok || u == nil {
		return ctx.Redirect("/discover")
	}
	user := u.(*models.User)
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	ctx.ViewData["Order"] = ot
	links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	return ctx.View(nil)
}
開發者ID:t7er,項目名稱:ohlala,代碼行數:16,代碼來源:home.go

示例13: discover_index

// 發現 首頁
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新鏈接的未讀提醒
	var userId, lastReadLinkId int64
	unreadCookieName := "newestUnrLinkId"
	u, ok := ctx.Data["user"]
	if ok && u != nil {
		user := u.(*models.User)
		userId = user.Id
		lastReadLinkId = user.LastReadLinkId
	} else {
		// 從Cook讀取最後一次閱讀的鏈接id
		cLastReadLinkId, err := ctx.Request.Cookie(unreadCookieName)
		if err == nil {
			lastReadLinkId, _ = strconv.ParseInt(cLastReadLinkId.Value, 10, 64)
		}
	}
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_All(userId, lastReadLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(userId, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		if userId > 0 {
			models.NewestLinkUnread_UpdateForAll(userId, links[0].Id)
		} else {
			c := &http.Cookie{
				Name:     unreadCookieName,
				Value:    fmt.Sprintf("%d", links[0].Id),
				Expires:  time.Now().AddDate(0, 1, 0),
				Path:     "/",
				HttpOnly: true,
			}
			ctx.SetCookie(c)
		}
	}

	return ctx.Render("/home/index", nil)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:48,代碼來源:discover.go

示例14: 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

示例15: 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


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