本文整理汇总了Golang中github.com/studygolang/mux.Vars函数的典型用法代码示例。如果您正苦于以下问题:Golang Vars函数的具体用法?Golang Vars怎么用?Golang Vars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vars函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UserHomeHandler
// 用户个人首页
// URI: /user/{username}
func UserHomeHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
username := vars["username"]
// 获取用户信息
user := service.FindUserByUsername(username)
if user == nil {
util.Redirect(rw, req, "/users")
return
}
topics := service.FindRecentTopics(user.Uid, "5")
resources := service.FindUserRecentResources(user.Uid)
resourceCats := make(map[int]string)
for _, resource := range resources {
resourceCats[resource.Catid] = service.GetCategoryName(resource.Catid)
}
projects := service.FindUserRecentProjects(user.Username)
comments := service.FindRecentComments(user.Uid, -1, "5")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeUsers": "active", "topics": topics, "resources": resources, "resource_cats": resourceCats, "projects": projects, "comments": comments, "user": user})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/profile.html")
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:user.go
示例2: CommentHandler
// 评论(或回复)
// uri: /comment/{objid:[0-9]+}.json
func CommentHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, _ := filter.CurrentUser(req)
if !util.CheckInt(req.PostForm, "objtype") {
fmt.Fprint(rw, `{"errno": 1, "error":"参数错误"}`)
return
}
// 入库
comment, err := service.PostComment(user["uid"].(int), util.MustInt(vars["objid"]), req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"服务器内部错误"}`)
return
}
buf, err := json.Marshal(comment)
if err != nil {
logger.Errorln("[RecentCommentHandler] json.marshal error:", err)
fmt.Fprint(rw, `{"errno": 1, "error":"解析json出错"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":"", "data":`+string(buf)+`}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:comment.go
示例3: CatResourcesHandler
// 某个分类的资源列表
// uri: /resources/cat/{catid:[0-9]+}
func CatResourcesHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
catid := vars["catid"]
resources := service.FindResourcesByCatid(catid)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/index.html")
filter.SetData(req, map[string]interface{}{"activeResources": "active", "resources": resources, "categories": model.AllCategory, "curCatid": catid})
}
开发者ID:BillyMC,项目名称:studygolang,代码行数:9,代码来源:resource.go
示例4: TopicDetailHandler
// 社区帖子详细页
// uri: /topics/{tid:[0-9]+}
func TopicDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
topic, replies, err := service.FindTopicByTid(vars["tid"])
if err != nil {
util.Redirect(rw, req, "/topics")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
tid := topic["tid"].(int)
likeFlag = service.HadLike(uid, tid, model.TYPE_TOPIC)
hadCollect = service.HadFavorite(uid, tid, model.TYPE_TOPIC)
}
service.Views.Incr(req, model.TYPE_TOPIC, util.MustInt(vars["tid"]))
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/detail.html,/template/common/comment.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topic": topic, "replies": replies, "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:topic.go
示例5: TopicsHandler
// 社区帖子列表页
// uri: /topics{view:(|/popular|/no_reply|/last)}
func TopicsHandler(rw http.ResponseWriter, req *http.Request) {
nodes := service.GenNodes()
// 设置内容模板
page, _ := strconv.Atoi(req.FormValue("p"))
if page == 0 {
page = 1
}
vars := mux.Vars(req)
order := ""
where := ""
view := ""
switch vars["view"] {
case "/no_reply":
view = "no_reply"
where = "lastreplyuid=0"
case "/last":
view = "last"
order = "ctime DESC"
}
topics, total := service.FindTopics(page, 0, where, order)
pageHtml := service.GetPageHtml(page, total, req.URL.Path)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes, "view": view})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:topic.go
示例6: AccountEditHandler
// 用户编辑个人信息
func AccountEditHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
curUser, _ := filter.CurrentUser(req)
if req.Method != "POST" || vars["json"] == "" {
// 获取用户信息
user := service.FindUserByUsername(curUser["username"].(string))
// 设置模板数据
filter.SetData(req, map[string]interface{}{"user": user, "default_avatars": service.DefaultAvatars})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/edit.html")
return
}
req.PostForm.Set("username", curUser["username"].(string))
if req.PostFormValue("open") != "1" {
req.PostForm.Set("open", "0")
}
// 更新个人信息
errMsg, err := service.UpdateUser(req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "msg":"个人资料更新成功!"}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:account.go
示例7: FavoriteHandler
// 收藏(取消收藏)
// uri: /favorite/{objid:[0-9]+}.json
func FavoriteHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, _ := filter.CurrentUser(req)
if !util.CheckInt(req.PostForm, "objtype") {
fmt.Fprint(rw, `{"ok": 0, "error":"参数错误"}`)
return
}
var err error
objtype := util.MustInt(req.PostFormValue("objtype"))
collect := util.MustInt(req.PostFormValue("collect"))
if collect == 1 {
err = service.SaveFavorite(user["uid"].(int), util.MustInt(vars["objid"]), objtype)
} else {
err = service.CancelFavorite(user["uid"].(int), util.MustInt(vars["objid"]), objtype)
}
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"`+err.Error()+`""}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "message":"success"}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:favorite.go
示例8: ProjectDetailHandler
// 项目详情
// uri: /p/{uniq}
func ProjectDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
project := service.FindProject(vars["uniq"])
if project == nil {
util.Redirect(rw, req, "/projects")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
likeFlag = service.HadLike(uid, project.Id, model.TYPE_PROJECT)
hadCollect = service.HadFavorite(uid, project.Id, model.TYPE_PROJECT)
}
service.Views.Incr(req, model.TYPE_PROJECT, project.Id)
// 为了阅读数即时看到
project.Viewnum++
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/detail.html,/template/common/comment.html")
filter.SetData(req, map[string]interface{}{"activeProjects": "active", "project": project, "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:project.go
示例9: IReadingHandler
// 点击 【我要晨读】,记录点击数,跳转
// uri: /readings/{id:[0-9]+}
func IReadingHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
url := service.IReading(vars["id"])
util.Redirect(rw, req, url)
return
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:9,代码来源:reading.go
示例10: NewTopicHandler
// 新建帖子
// uri: /topics/new{json:(|.json)}
func NewTopicHandler(rw http.ResponseWriter, req *http.Request) {
nodes := genNodes()
vars := mux.Vars(req)
title := req.FormValue("title")
// 请求新建帖子页面
if title == "" || req.Method != "POST" || vars["json"] == "" {
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/new.html")
filter.SetData(req, map[string]interface{}{"nodes": nodes})
return
}
user, _ := filter.CurrentUser(req)
// 入库
topic := model.NewTopic()
topic.Uid = user["uid"].(int)
topic.Nid = util.MustInt(req.FormValue("nid"))
topic.Title = req.FormValue("title")
topic.Content = req.FormValue("content")
errMsg, err := service.PublishTopic(topic)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
}
开发者ID:sndnvaps,项目名称:studygolang,代码行数:27,代码来源:topic.go
示例11: ModifyTopicHandler
// 修改主题
// uri: /topics/modify{json:(|.json)}
func ModifyTopicHandler(rw http.ResponseWriter, req *http.Request) {
tid := req.FormValue("tid")
if tid == "" {
util.Redirect(rw, req, "/topics")
return
}
nodes := service.GenNodes()
vars := mux.Vars(req)
// 请求编辑主题页面
if req.Method != "POST" || vars["json"] == "" {
topic := service.FindTopic(tid)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/new.html")
filter.SetData(req, map[string]interface{}{"nodes": nodes, "topic": topic, "activeTopics": "active"})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishTopic(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:32,代码来源:topic.go
示例12: NewResourceHandler
// 发布新资源
// uri: /resources/new{json:(|.json)}
func NewResourceHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
title := req.PostFormValue("title")
// 请求新建资源页面
if title == "" || req.Method != "POST" || vars["json"] == "" {
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/new.html")
filter.SetData(req, map[string]interface{}{"activeResources": "active", "categories": service.AllCategory})
return
}
errMsg := ""
resForm := req.PostFormValue("form")
if resForm == model.LinkForm {
if req.PostFormValue("url") == "" {
errMsg = "url不能为空"
}
} else {
if req.PostFormValue("content") == "" {
errMsg = "内容不能为空"
}
}
if errMsg != "" {
fmt.Fprint(rw, `{"ok": 0, "error":"`+errMsg+`"}`)
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishResource(user, req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误,请稍候再试!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:37,代码来源:resource.go
示例13: ReminderHandler
func ReminderHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
username := req.FormValue("username")
curUser, _ := filter.CurrentUser(req)
if username == "" || req.Method != "POST" || vars["json"] == "" {
// 获取用户信息
user := service.FindUserByUsername(curUser["username"].(string))
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeUsers": "active", "user": user})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/reminder.html")
return
}
// 只能编辑自己的信息
if username != curUser["username"].(string) {
fmt.Fprint(rw, `{"errno": 1, "error": "非法请求"}`)
return
}
// open传递过来的是“on”或没传递
if req.FormValue("Emailnotice") == "on" {
req.Form.Set("Emailnotice", "1")
} else {
req.Form.Set("Emailnotice", "0")
}
// 更新个人信息
errMsg, err := service.UpdateUserReminder(req.Form)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "msg":"个人reminder资料更新成功!"}`)
}
开发者ID:jackyxie,项目名称:btcrobot,代码行数:33,代码来源:account.go
示例14: ModifyProjectHandler
// 修改项目
// uri: /project/modify{json:(|.json)}
func ModifyProjectHandler(rw http.ResponseWriter, req *http.Request) {
id := req.FormValue("id")
if id == "" {
util.Redirect(rw, req, "/projects")
return
}
vars := mux.Vars(req)
// 请求编辑项目页面
if req.Method != "POST" || vars["json"] == "" {
project := service.FindProject(id)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/new.html")
filter.SetData(req, map[string]interface{}{"project": project, "activeProjects": "active"})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishProject(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:project.go
示例15: ModifyResourceHandler
// 修改資源
// uri: /resources/modify{json:(|.json)}
func ModifyResourceHandler(rw http.ResponseWriter, req *http.Request) {
id := req.FormValue("id")
if id == "" {
util.Redirect(rw, req, "/resources")
return
}
vars := mux.Vars(req)
// 请求编辑資源页面
if req.Method != "POST" || vars["json"] == "" {
resource := service.FindResourceById(id)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/new.html")
filter.SetData(req, map[string]interface{}{"resource": resource, "activeResources": "active", "categories": service.AllCategory})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishResource(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:resource.go
示例16: ArticleDetailHandler
// 文章详细页
// uri: /articles/{id:[0-9]+}
func ArticleDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
article, prevNext, err := service.FindArticlesById(vars["id"])
if err != nil {
util.Redirect(rw, req, "/articles")
return
}
if article == nil || article.Id == 0 || article.Status == model.StatusOffline {
util.Redirect(rw, req, "/articles")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
likeFlag = service.HadLike(uid, article.Id, model.TYPE_ARTICLE)
hadCollect = service.HadFavorite(uid, article.Id, model.TYPE_ARTICLE)
}
service.Views.Incr(req, model.TYPE_ARTICLE, article.Id)
// 为了阅读数即时看到
article.Viewnum++
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/articles/detail.html,/template/common/comment.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeArticles": "active", "article": article, "prev": prevNext[0], "next": prevNext[1], "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:35,代码来源:article.go
示例17: EngineHandler
func EngineHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
msgtype := vars["msgtype"]
if req.Method != "POST" && msgtype == "" {
// 获取用户信息
err := config.LoadOption()
if err != nil {
logger.Errorln(err)
fmt.Fprint(rw, `{"errno": 1, "msg":"`, "读取引擎配置数据失败", `"}`)
return
}
// 设置模板数据
filter.SetData(req, map[string]interface{}{"config": config.Option})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/trade/engine.html")
return
} else if req.Method != "POST" && msgtype == "ajax" {
Option_json, err := json.Marshal(config.Option)
if err != nil {
logger.Errorln(err)
fmt.Fprint(rw, `{"errno": 1, "msg":"`, "读取引擎配置数据失败", `"}`)
} else {
fmt.Fprint(rw, string(Option_json))
}
return
} else {
logger.Debugln("===[", req.FormValue("disable_trading"), "]")
if req.FormValue("disable_trading") == "on" {
config.Option["disable_trading"] = "1"
} else {
config.Option["disable_trading"] = "0"
}
logger.Debugln("===[", req.FormValue("disable_backtesting"), "]")
if req.FormValue("disable_backtesting") == "on" {
config.Option["disable_backtesting"] = "1"
} else {
config.Option["disable_backtesting"] = "0"
}
config.Option["tick_interval"] = req.FormValue("tick_interval")
config.Option["shortEMA"] = req.FormValue("shortEMA")
config.Option["longEMA"] = req.FormValue("longEMA")
config.Option["tradeAmount"] = req.FormValue("tradeAmount")
config.Option["totalHour"] = req.FormValue("totalHour")
// 更新个人信息
err := config.SaveOption()
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "msg":"`, "写入引擎配置数据失败", `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "msg":"更新引擎配置成功!"}`)
}
}
开发者ID:kalllx,项目名称:btcrobot,代码行数:59,代码来源:btcweb.go
示例18: LikeHandler
// 喜欢(或取消喜欢)
// uri: /like/{objid:[0-9]+}.json
func LikeHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, _ := filter.CurrentUser(req)
// 入库
err := service.PostComment(util.MustInt(vars["objid"]), util.MustInt(req.FormValue("objtype")), user["uid"].(int), req.FormValue("content"), req.FormValue("objname"))
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"服务器内部错误"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
}
开发者ID:jimmykuu,项目名称:studygolang,代码行数:13,代码来源:like.go
示例19: OtherTopicsHandler
// 某节点下其他帖子
func OtherTopicsHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
topics := service.FindTopicsByNid(vars["nid"], vars["tid"])
data, err := json.Marshal(topics)
if err != nil {
logger.Errorln("[OtherTopicsHandler] json.marshal error:", err)
fmt.Fprint(rw, `{"errno": 1, "error":"解析json出错"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "data":`+string(data)+`}`)
}
开发者ID:jimmykuu,项目名称:studygolang,代码行数:12,代码来源:ajax.go
示例20: WikiContentHandler
// 展示wiki页
// uri: /wiki/{uri}
func WikiContentHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
uri := vars["uri"]
wiki := service.FindWiki(uri)
if wiki == nil {
NotFoundHandler(rw, req)
return
}
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/wiki/content.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeWiki": "active", "wiki": wiki})
}
开发者ID:BillyMC,项目名称:studygolang,代码行数:14,代码来源:wiki.go
注:本文中的github.com/studygolang/mux.Vars函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论