当前位置: 首页>>代码示例>>Golang>>正文


Golang goku.HttpContext类代码示例

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


在下文中一共展示了HttpContext类的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: 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: OnActionExecuting

func (f *ThirdPartyBindFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {

	sessionIdBase, err := ctx.Request.Cookie(config.ThirdPartyCookieKey)
	if err != nil || len(sessionIdBase.Value) == 0 {
		ar = ctx.NotFound("no user binding context found.")
		return
	}
	ctx.Data["thirdPartySessionIdBase"] = sessionIdBase.Value

	profileSessionId := models.ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase.Value)
	profile := models.ThirdParty_GetThirdPartyProfileFromSession(profileSessionId)

	if profile == nil {
		ar = ctx.NotFound("no user binding context found.")
		return
	}

	ctx.ViewData["profile"] = profile
	if len(profile.Email) > 0 {
		sensitiveInfoRemovedEmail := utils.GetSensitiveInfoRemovedEmail(profile.Email)
		ctx.ViewData["directCreateEmail"] = sensitiveInfoRemovedEmail
	}

	var profileShow struct {
		Avatar bool
		Link   bool
		Name   string
	}
	profileShow.Avatar = (len(profile.AvatarUrl) > 0)
	profileShow.Link = (len(profile.Link) > 0)
	profileShow.Name = profile.GetDisplayName()
	ctx.ViewData["profileShow"] = profileShow

	return
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:35,代码来源:third_party_bind.go

示例4: user_Fans

// 查看粉丝
func user_Fans(ctx *goku.HttpContext) goku.ActionResulter {

	userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	var user *models.User
	if userId > 0 {
		user = models.User_GetById(userId)
	} else {
		if u, ok := ctx.Data["user"]; ok {
			user = u.(*models.User)
			ctx.ViewData["UserMenu"] = "um-fans"
		}
	}

	if user == nil {
		ctx.ViewData["errorMsg"] = "用户不存在"
		return ctx.Render("error", nil)
	}

	page, pagesize := utils.PagerParams(ctx.Request)
	followers, _ := models.UserFollow_Followers(user.Id, page, pagesize)

	ctx.ViewData["Followers"] = models.User_ToVUsers(followers, ctx)
	ctx.ViewData["HasMoreFollowers"] = len(followers) >= pagesize
	return ctx.View(models.User_ToVUser(user, ctx))

}
开发者ID:venliong,项目名称:ohlala,代码行数:27,代码来源:user.go

示例5: setCookieForOtherPlatformUser

//为别的平台用户写cookie
func setCookieForOtherPlatformUser(userId int64, email string, seconds int, ctx *goku.HttpContext) {
	//注册成功,写cookie
	now := time.Now()
	h := md5.New()
	h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
	ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
	expires := now.Add(time.Duration(seconds) * time.Second)
	redisClient := models.GetRedis()
	defer redisClient.Quit()
	err := redisClient.Set(ticket, userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	} else {
		_, err = redisClient.Expireat(ticket, expires.Unix())
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		c := &http.Cookie{
			Name:     "_glut",
			Value:    ticket,
			Expires:  expires,
			Path:     "/",
			HttpOnly: true,
		}
		ctx.SetCookie(c)
	}
}
开发者ID:t7er,项目名称:ohlala,代码行数:28,代码来源:user_reg_login.go

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

示例7: admin_index

func admin_index(ctx *goku.HttpContext) goku.ActionResulter {
	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()

	linkCount, err := db.Count("link", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["linkCount"] = linkCount

	userCount, err := db.Count("user", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["userCount"] = userCount

	topicCount, err := db.Count("topic", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["topicCount"] = topicCount

	commentCount, err := db.Count("comment", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["commentCount"] = commentCount

	return ctx.View(nil)
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:34,代码来源:index.go

示例8: ThirdParty_SaveThirdPartyProfileToSession

func ThirdParty_SaveThirdPartyProfileToSession(
	ctx *goku.HttpContext,
	profile *ThirdPartyUserProfile) (err error) {

	providerName := profile.ProviderName
	sessionKeyBase := thirdParty_GetSessionKeyBase(providerName, profile.Id)
	profileSessionId := ThirdParty_GetThirdPartyProfileSessionId(sessionKeyBase)
	expires := time.Now().Add(time.Duration(3600) * time.Second)

	b, _ := json.Marshal(profile)
	s := string(b)
	err = SaveItemToSession(profileSessionId, s, expires)
	if err != nil {
		return
	}

	c := &http.Cookie{
		Name:     config.ThirdPartyCookieKey,
		Value:    sessionKeyBase,
		Expires:  expires,
		Path:     "/",
		HttpOnly: true,
	}
	ctx.SetCookie(c)

	return
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:27,代码来源:third_party_user.go

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

示例10: loginThirdPartyUser

func loginThirdPartyUser(u *models.ThirdPartyUser, ctx *goku.HttpContext) goku.ActionResulter {
	user := u.User()
	userId, email, expireInSeconds := user.Id, user.Email, 24*3600
	/*if !u.TokenExpireTime.IsZero() {
	    utcNow := time.Now().UTC()
	    expireInSeconds = int(u.TokenExpireTime.Sub(utcNow) / time.Second)
	}*/
	setCookieForOtherPlatformUser(userId, email, expireInSeconds, ctx)

	return ctx.Redirect("/")
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:11,代码来源:user_reg_login.go

示例11: thirdParty_ClearThirdPartyProfileFromSession

func thirdParty_ClearThirdPartyProfileFromSession(ctx *goku.HttpContext) {
	sessionIdBase := ctx.Data["thirdPartySessionIdBase"].(string)
	sessinId := ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase)
	RemoveItemFromSession(sessinId)

	c := &http.Cookie{
		Name:    config.ThirdPartyCookieKey,
		Expires: time.Now().Add(-10 * time.Second),
		Path:    "/",
	}
	ctx.SetCookie(c)
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:12,代码来源:third_party_user.go

示例12: admin_users

func admin_users(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	users, total, err := models.User_GetList(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["UserList"] = users
	ctx.ViewData["UserCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:13,代码来源:user.go

示例13: admin_comments

func admin_comments(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	comments, total, err := models.Comment_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["CommentList"] = comments
	ctx.ViewData["CommentCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:13,代码来源:comment.go

示例14: admin_links

func admin_links(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	links, total, err := models.Link_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["LinkList"] = links
	ctx.ViewData["TotalLinks"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:13,代码来源:link.go

示例15: admin_topics

func admin_topics(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	topics, total, err := models.Topic_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["TopicList"] = topics
	ctx.ViewData["TopicCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	ctx.ViewData["TabName"] = "topics"
	return ctx.View(nil)
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:14,代码来源:topic.go


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