本文整理汇总了Golang中github.com/polaris1119/goutils.MustInt函数的典型用法代码示例。如果您正苦于以下问题:Golang MustInt函数的具体用法?Golang MustInt怎么用?Golang MustInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustInt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadCatResources
// ReadCatResources 某个分类的资源列表
func (ResourceController) ReadCatResources(ctx echo.Context) error {
curPage := goutils.MustInt(ctx.QueryParam("p"), 1)
paginator := logic.NewPaginator(curPage)
catid := goutils.MustInt(ctx.Param("catid"))
resources, total := logic.DefaultResource.FindByCatid(ctx, paginator, catid)
pageHtml := paginator.SetTotal(total).GetPageHtml(ctx.Request().URL().Path())
return render(ctx, "resources/index.html", map[string]interface{}{"activeResources": "active", "resources": resources, "categories": logic.AllCategory, "page": template.HTML(pageHtml), "curCatid": catid})
}
示例2: NodeTopics
// NodeTopics 某节点下的主题列表
func (TopicController) NodeTopics(ctx echo.Context) error {
curPage := goutils.MustInt(ctx.QueryParam("p"), 1)
paginator := logic.NewPaginator(curPage)
querystring, nid := "nid=?", goutils.MustInt(ctx.Param("nid"))
topics := logic.DefaultTopic.FindAll(ctx, paginator, "topics.mtime DESC", querystring, nid)
total := logic.DefaultTopic.Count(ctx, querystring, nid)
pageHtml := paginator.SetTotal(total).GetPageHtml(ctx.Request().URL().Path())
// 当前节点信息
node := logic.GetNode(nid)
return render(ctx, "topics/node.html", map[string]interface{}{"activeTopics": "active", "topics": topics, "page": template.HTML(pageHtml), "total": total, "node": node})
}
示例3: ReadingList
// ReadingList 晨读列表页
func (ReadingController) ReadingList(ctx echo.Context) error {
limit := 20
lastId := goutils.MustInt(ctx.QueryParam("lastid"))
rtype := goutils.MustInt(ctx.QueryParam("rtype"), model.RtypeGo)
readings := logic.DefaultReading.FindBy(ctx, limit+5, rtype, lastId)
num := len(readings)
if num == 0 {
if lastId == 0 {
return ctx.Redirect(http.StatusSeeOther, "/")
} else {
return ctx.Redirect(http.StatusSeeOther, "/readings")
}
}
var (
hasPrev, hasNext bool
prevId, nextId int
)
if lastId > 0 {
prevId = lastId
// 避免因为项目下线,导致判断错误(所以 > 5)
if prevId-readings[0].Id > 5 {
hasPrev = false
} else {
prevId += limit
hasPrev = true
}
}
if num > limit {
hasNext = true
readings = readings[:limit]
nextId = readings[limit-1].Id
} else {
nextId = readings[num-1].Id
}
pageInfo := map[string]interface{}{
"has_prev": hasPrev,
"prev_id": prevId,
"has_next": hasNext,
"next_id": nextId,
}
return render(ctx, "readings/list.html", map[string]interface{}{"activeReadings": "active", "readings": readings, "page": pageInfo, "rtype": rtype})
}
示例4: Detail
// Detail 文章详细页
func (ArticleController) Detail(ctx echo.Context) error {
article, prevNext, err := logic.DefaultArticle.FindByIdAndPreNext(ctx, goutils.MustInt(ctx.Param("id")))
if err != nil {
return ctx.Redirect(http.StatusSeeOther, "/articles")
}
if article == nil || article.Id == 0 || article.Status == model.ArticleStatusOffline {
return ctx.Redirect(http.StatusSeeOther, "/articles")
}
likeFlag := 0
hadCollect := 0
me, ok := ctx.Get("user").(*model.Me)
if ok {
likeFlag = logic.DefaultLike.HadLike(ctx, me.Uid, article.Id, model.TypeArticle)
hadCollect = logic.DefaultFavorite.HadFavorite(ctx, me.Uid, article.Id, model.TypeArticle)
}
logic.Views.Incr(Request(ctx), model.TypeArticle, article.Id)
// 为了阅读数即时看到
article.Viewnum++
return render(ctx, "articles/detail.html,common/comment.html", map[string]interface{}{"activeArticles": "active", "article": article, "prev": prevNext[0], "next": prevNext[1], "likeflag": likeFlag, "hadcollect": hadCollect})
}
示例5: FindOne
// FindOne 某个wiki页面详细信息
func (WikiLogic) FindOne(ctx context.Context, uri string) *model.Wiki {
objLog := GetLogger(ctx)
wiki := &model.Wiki{}
if _, err := MasterDB.Where("uri=?", uri).Get(wiki); err != nil {
objLog.Errorln("wiki logic FindOne error:", err)
return nil
}
if wiki.Id == 0 {
return nil
}
uidSet := set.New(set.NonThreadSafe)
uidSet.Add(wiki.Uid)
if wiki.Cuid != "" {
cuids := strings.Split(wiki.Cuid, ",")
for _, cuid := range cuids {
uidSet.Add(goutils.MustInt(cuid))
}
}
wiki.Users = DefaultUser.FindUserInfos(ctx, set.IntSlice(uidSet))
return wiki
}
示例6: SetupConfig
func (self InstallController) SetupConfig(ctx echo.Context) error {
// config/env.ini 存在
if db.MasterDB != nil {
if logic.DefaultInstall.IsTableExist(ctx) {
return ctx.Redirect(http.StatusSeeOther, "/")
}
return ctx.Redirect(http.StatusSeeOther, "/install/do")
}
step := goutils.MustInt(ctx.QueryParam("step"))
if step == 2 {
err := self.genConfig(ctx)
if err != nil {
data := map[string]interface{}{
"dbhost": ctx.FormValue("dbhost"),
"dbport": ctx.FormValue("dbport"),
"dbname": ctx.FormValue("dbname"),
"uname": ctx.FormValue("uname"),
"err_type": 1,
}
if err == db.ConnectDBErr {
data["err_type"] = 1
} else if err == db.UseDBErr {
data["err_type"] = 2
}
return renderInstall(ctx, "install/setup-err.html", data)
}
}
return renderInstall(ctx, "install/setup-config.html", map[string]interface{}{"step": step})
}
示例7: ReadList
// 消息列表
func (MessageController) ReadList(ctx echo.Context) error {
user := ctx.Get("user").(*model.Me)
msgtype := ctx.Param("msgtype")
if msgtype == "" {
msgtype = "system"
}
curPage := goutils.MustInt(ctx.QueryParam("p"), 1)
paginator := logic.NewPaginator(curPage)
var (
messages []map[string]interface{}
total int64
)
switch msgtype {
case "system":
messages = logic.DefaultMessage.FindSysMsgsByUid(ctx, user.Uid, paginator)
total = logic.DefaultMessage.SysMsgCount(ctx, user.Uid)
case "inbox":
messages = logic.DefaultMessage.FindToMsgsByUid(ctx, user.Uid, paginator)
total = logic.DefaultMessage.ToMsgCount(ctx, user.Uid)
case "outbox":
messages = logic.DefaultMessage.FindFromMsgsByUid(ctx, user.Uid, paginator)
total = logic.DefaultMessage.FromMsgCount(ctx, user.Uid)
default:
return ctx.Redirect(http.StatusSeeOther, "/")
}
pageHtml := paginator.SetTotal(total).GetPageHtml(fmt.Sprintf("/message/%s", msgtype))
return render(ctx, "messages/list.html", map[string]interface{}{"messages": messages, "msgtype": msgtype, "page": template.HTML(pageHtml)})
}
示例8: EmailUnsub
// EmailUnsub 邮件订阅/退订页面
func (UserController) EmailUnsub(ctx echo.Context) error {
token := ctx.FormValue("u")
if token == "" {
return ctx.Redirect(http.StatusSeeOther, "/")
}
// 校验 token 的合法性
email := ctx.FormValue("email")
user := logic.DefaultUser.FindOne(ctx, "email", email)
if user.Email == "" {
return ctx.Redirect(http.StatusSeeOther, "/")
}
realToken := logic.DefaultEmail.GenUnsubscribeToken(user)
if token != realToken {
return ctx.Redirect(http.StatusSeeOther, "/")
}
if ctx.Request().Method() != "POST" {
data := map[string]interface{}{
"email": email,
"token": token,
"unsubscribe": user.Unsubscribe,
}
return render(ctx, "user/email_unsub.html", data)
}
logic.DefaultUser.EmailSubscribe(ctx, user.Uid, goutils.MustInt(ctx.FormValue("unsubscribe")))
return success(ctx, nil)
}
示例9: Modify
// Modify 修改主题
func (TopicController) Modify(ctx echo.Context) error {
tid := goutils.MustInt(ctx.FormValue("tid"))
if tid == 0 {
return ctx.Redirect(http.StatusSeeOther, "/topics")
}
nodes := logic.GenNodes()
if ctx.Request().Method() != "POST" {
topics := logic.DefaultTopic.FindByTids([]int{tid})
if len(topics) == 0 {
return ctx.Redirect(http.StatusSeeOther, "/topics")
}
return render(ctx, "topics/new.html", map[string]interface{}{"nodes": nodes, "topic": topics[0], "activeTopics": "active"})
}
me := ctx.Get("user").(*model.Me)
err := logic.DefaultTopic.Publish(ctx, me, ctx.FormParams())
if err != nil {
if err == logic.NotModifyAuthorityErr {
return fail(ctx, 1, "没有权限操作")
}
return fail(ctx, 2, "服务错误,请稍后重试!")
}
return success(ctx, nil)
}
示例10: ReadList
// ReadList 获得wiki列表
func (WikiController) ReadList(ctx echo.Context) error {
limit := 20
lastId := goutils.MustInt(ctx.QueryParam("lastid"))
wikis := logic.DefaultWiki.FindBy(ctx, limit+5, lastId)
if wikis == nil {
logger.Errorln("wiki controller: find wikis error")
return ctx.Redirect(http.StatusSeeOther, "/wiki")
}
num := len(wikis)
if num == 0 {
if lastId == 0 {
return ctx.Redirect(http.StatusSeeOther, "/")
}
return ctx.Redirect(http.StatusSeeOther, "/wiki")
}
var (
hasPrev, hasNext bool
prevId, nextId int
)
if lastId != 0 {
prevId = lastId
// 避免因为wiki下线,导致判断错误(所以 > 5)
if prevId-wikis[0].Id > 5 {
hasPrev = false
} else {
prevId += limit
hasPrev = true
}
}
if num > limit {
hasNext = true
wikis = wikis[:limit]
nextId = wikis[limit-1].Id
} else {
nextId = wikis[num-1].Id
}
pageInfo := map[string]interface{}{
"has_prev": hasPrev,
"prev_id": prevId,
"has_next": hasNext,
"next_id": nextId,
}
// 获取当前用户喜欢对象信息
// me, ok := ctx.Get("user").(*model.Me)
// var likeFlags map[int]int
// if ok {
// likeFlags, _ = logic.DefaultLike.FindUserLikeObjects(ctx, me.Uid, model.TypeWiki, wikis[0].Id, nextId)
// }
return render(ctx, "wiki/list.html", map[string]interface{}{"wikis": wikis, "activeWiki": "active", "page": pageInfo})
}
示例11: Like
// Like 喜欢(或取消喜欢)
func (LikeController) Like(ctx echo.Context) error {
form := ctx.FormParams()
if !util.CheckInt(form, "objtype") || !util.CheckInt(form, "flag") {
return fail(ctx, 1, "参数错误")
}
user := ctx.Get("user").(*model.Me)
objid := goutils.MustInt(ctx.Param("objid"))
objtype := goutils.MustInt(ctx.FormValue("objtype"))
likeFlag := goutils.MustInt(ctx.FormValue("flag"))
err := logic.DefaultLike.LikeObject(ctx, user.Uid, objid, objtype, likeFlag)
if err != nil {
return fail(ctx, 2, "服务器内部错误")
}
return success(ctx, nil)
}
示例12: ReadList
// ReadList 开源项目列表页
func (ProjectController) ReadList(ctx echo.Context) error {
limit := 20
lastId := goutils.MustInt(ctx.QueryParam("lastid"))
projects := logic.DefaultProject.FindBy(ctx, limit+5, lastId)
num := len(projects)
if num == 0 {
if lastId == 0 {
return ctx.Redirect(http.StatusSeeOther, "/")
} else {
return ctx.Redirect(http.StatusSeeOther, "/projects")
}
}
var (
hasPrev, hasNext bool
prevId, nextId int
)
if lastId > 0 {
prevId = lastId
// 避免因为项目下线,导致判断错误(所以 > 5)
if prevId-projects[0].Id > 5 {
hasPrev = false
} else {
prevId += limit
hasPrev = true
}
}
if num > limit {
hasNext = true
projects = projects[:limit]
nextId = projects[limit-1].Id
} else {
nextId = projects[num-1].Id
}
pageInfo := map[string]interface{}{
"has_prev": hasPrev,
"prev_id": prevId,
"has_next": hasNext,
"next_id": nextId,
}
// 获取当前用户喜欢对象信息
me, ok := ctx.Get("user").(*model.Me)
var likeFlags map[int]int
if ok {
likeFlags, _ = logic.DefaultLike.FindUserLikeObjects(ctx, me.Uid, model.TypeProject, projects[0].Id, nextId)
}
return render(ctx, "projects/list.html", map[string]interface{}{"projects": projects, "activeProjects": "active", "page": pageInfo, "likeflags": likeFlags})
}
示例13: Create
// Create 收藏(取消收藏)
func (FavoriteController) Create(ctx echo.Context) error {
objtype := goutils.MustInt(ctx.FormValue("objtype"))
objid := goutils.MustInt(ctx.Param("objid"))
collect := goutils.MustInt(ctx.FormValue("collect"))
user := ctx.Get("user").(*model.Me)
var err error
if collect == 1 {
err = logic.DefaultFavorite.Save(ctx, user.Uid, objid, objtype)
} else {
err = logic.DefaultFavorite.Cancel(ctx, user.Uid, objid, objtype)
}
if err != nil {
return fail(ctx, 1, err.Error())
}
return success(ctx, nil)
}
示例14: Create
// Create 评论(或回复)
func (CommentController) Create(ctx echo.Context) error {
user := ctx.Get("user").(*model.Me)
// 入库
objid := goutils.MustInt(ctx.Param("objid"))
comment, err := logic.DefaultComment.Publish(ctx, user.Uid, objid, ctx.FormParams())
if err != nil {
return fail(ctx, 1, "服务器内部错误")
}
return success(ctx, comment)
}
示例15: initMaxOnlineNum
func initMaxOnlineNum() {
maxRwMu.Lock()
defer maxRwMu.Unlock()
if maxOnlineNum == 0 {
data, err := ioutil.ReadFile(getDataFile())
if err != nil {
logger.Errorln("read data file error:", err)
return
}
maxOnlineNum = goutils.MustInt(strings.TrimSpace(string(data)))
}
}