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


Golang httprouter.Params类代码示例

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


在下文中一共展示了Params类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HandleGamePageNewAction

func HandleGamePageNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if params.ByName("wild") == "new" && models.SignedIn(w, r) {
		title := r.FormValue("gameTitle")
		dev := r.FormValue("gameDeveloper")
		pub := r.FormValue("gamePublisher")
		trailer := r.FormValue("gameTrailer")
		//copy := r.FormValue("gameCopyright")
		desc := r.FormValue("gameDescription")
		tagstr := r.FormValue("gameTags")
		var tags []string
		err := json.Unmarshal([]byte(tagstr), &tags)
		if err != nil || tags == nil {
			tags = []string{}
		}
		game := models.NewGame(title, pub, trailer)
		game.Description = desc
		game.Developer = dev
		err = models.Dal.CreateGame(*game)
		if err != nil {
			panic(err)
		}
		for _, tag := range tags {
			models.Dal.AddGameTag(game.GameId, tag)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(game.GameId), http.StatusFound)
	} else {
		http.NotFound(w, r)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:29,代码来源:handlers.go

示例2: HandleReviewEditAction

func HandleReviewEditAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		reviewid := params.ByName("wild")
		//reviewid := r.FormValue("reviewID")
		user := models.RequestUser(r)
		//gameid := r.FormValue("gameID")
		review := r.FormValue("reviewBody")
		rating, _ := strconv.ParseFloat(r.FormValue("reviewRate"), 64)
		rev, err := models.Dal.FindReview(reviewid)
		if err != nil {
			panic(err)
		}
		rev.Body = review
		rev.Rating = rating
		if rev.UserId != user.UserId {
			models.RenderTemplate(w, r, "review/edit", map[string]interface{}{"Review": rev})
			return
		}
		err = models.Dal.UpdateReview(*rev)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/review/"+rev.ReviewId, http.StatusFound)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:25,代码来源:handlers.go

示例3: HandleGamePage

func HandleGamePage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	encgameid := params.ByName("wild")
	if encgameid == "new" {
		HandleGamePageNew(w, r, params)
		return
	}
	var err error
	gameid, err := url.QueryUnescape(encgameid)
	if err != nil {
		panic(err)
	}
	var game *models.Game
	game, err = models.Dal.FindGame(gameid)
	if err != nil {
		panic(err)
	}
	game.UpdateRating()
	revs, err := models.Dal.FindTopReviewsByGame(gameid, 5)
	if err != nil {
		panic(err)
	}
	vids, err := models.Dal.FindTopVideosByGame(gameid, 6)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "game/page", map[string]interface{}{"Game": game, "TopReviews": revs, "TopUserVids": vids})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:27,代码来源:handlers.go

示例4: HandleVideo

func HandleVideo(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	videoid := params.ByName("wild")
	vid, err := models.Dal.FindVideo(videoid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "video/uservideo", map[string]interface{}{"Video": vid, "VideoWidth": 640, "VideoHeight": 480})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:8,代码来源:handlers.go

示例5: HandleReview

func HandleReview(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	reviewid := params.ByName("wild")
	rev, err := models.Dal.FindReview(reviewid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "review/review", map[string]interface{}{"Review": rev})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:8,代码来源:handlers.go

示例6: HandleReviewNew

func HandleReviewNew(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		gam, err := models.Dal.FindGame(gameid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "review/new", map[string]interface{}{"Game": gam})
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:10,代码来源:handlers.go

示例7: HandleGameClaimAction

func HandleGameClaimAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		err := models.Dal.AddUserGame(models.RequestUser(r).UserId, gameid)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(gameid), http.StatusFound)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:10,代码来源:handlers.go

示例8: HandleReviewNewAction

func HandleReviewNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		//reviewid := r.FormValue("reviewID")
		user := models.RequestUser(r)
		//gameid := r.FormValue("gameID")
		review := r.FormValue("reviewBody")
		rating, _ := strconv.ParseFloat(r.FormValue("reviewRate"), 64)
		rev := models.NewReview(user.UserId, gameid, review, rating)
		http.Redirect(w, r, "/review/"+rev.ReviewId, http.StatusFound)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:12,代码来源:handlers.go

示例9: HandleVideoNewAction

func HandleVideoNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		vidurl := r.FormValue("vidURL")
		user := models.RequestUser(r)
		vid := models.NewVideo(user.UserId, gameid, vidurl)
		err := models.Dal.CreateVideo(*vid)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/videos/"+url.QueryEscape(vid.ID), http.StatusFound)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:13,代码来源:handlers.go

示例10: HandleGameVideos

func HandleGameVideos(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	gameid := params.ByName("wild")
	game, err := models.Dal.FindGame(gameid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	vids, err = models.Dal.FindVideosByGame(gameid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "videos/allgamevideos", map[string]interface{}{"Game": game, "AllVideos": vids})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:13,代码来源:handlers.go

示例11: HandleUserVideos

func HandleUserVideos(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	userid := params.ByName("wild")
	user, err := models.GlobalUserStore.FindUser(userid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	vids, err = models.Dal.FindVideosByUser(user.UserId)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "videos/alluservideos", map[string]interface{}{"User": user, "AllVideos": vids})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:13,代码来源:handlers.go

示例12: HandleGameEditAction

func HandleGameEditAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		title := r.FormValue("gameTitle")
		dev := r.FormValue("gameDeveloper")
		pub := r.FormValue("gamePublisher")
		trailer := r.FormValue("gameTrailer")
		//copy := r.FormValue("gameCopyright")
		desc := r.FormValue("gameDescription")
		tagstr := r.FormValue("gameTags")
		var tags []string
		err := json.Unmarshal([]byte(tagstr), &tags)
		if err != nil || tags == nil {
			tags = []string{}
		}
		for k, v := range tags {
			t, err := url.QueryUnescape(v)
			if err == nil {
				tags[k] = t
			}
		}
		var currtags []string
		currtags, err = models.Dal.FindTagsByGame(gameid)
		if err != nil || currtags == nil {
			currtags = []string{}
		}
		game := models.Game{GameId: gameid, Title: title, Developer: dev, Publisher: pub, URL: trailer, Description: desc}
		err = models.Dal.UpdateGame(game)
		if err != nil {
			panic(err)
		}
		for _, t := range currtags {
			found := false
			for k, v := range tags {
				if t == v {
					found = true
					tags = append(tags[:k], tags[k+1:]...)
					break
				}
			}
			if !found {
				models.Dal.DeleteGameTag(gameid, t)
			}
		}
		for _, t := range tags {
			models.Dal.AddGameTag(gameid, t)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(game.GameId), http.StatusFound)
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:50,代码来源:handlers.go

示例13: HandleUserPage

func HandleUserPage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	userid := params.ByName("wild")
	user, err := models.GlobalUserStore.FindUser(userid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	var revs []models.Review
	vids, err = models.Dal.FindTopVideosByUser(userid, 10)
	if err != nil {
		panic(err)
	}
	revs, err = models.Dal.FindTopReviewsByUser(userid, 10)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "users/view", map[string]interface{}{"User": user, "Reviews": revs, "Videos": vids})
}
开发者ID:anogowski,项目名称:gamebase,代码行数:18,代码来源:handlers.go

示例14: HandleFriendAdd

func HandleFriendAdd(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		friendid := params.ByName("wild")
		friend, err := models.GlobalUserStore.FindUser(friendid)
		if err != nil {
			panic(err)
		}
		user := models.RequestUser(r)
		if user == nil || friend == nil || user.UserId == friend.UserId {
			models.RenderTemplate(w, r, "users/friend", nil)
			return
		}
		err = models.Dal.AddUserFriend(user.UserId, friendid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "users/friend", map[string]interface{}{"Friend": friend})
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:19,代码来源:handlers.go

示例15: HandleGameEditPage

func HandleGameEditPage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		game, err := models.Dal.FindGame(gameid)
		if err != nil {
			panic(err)
		}
		if game == nil {
			http.Redirect(w, r, "/?flash=Game+Not+Found", http.StatusNotFound)
			return
		}
		tags := []string{}
		tags, err = models.Dal.FindTagsByGame(gameid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "game/edit", map[string]interface{}{"Game": game, "Tags": tags})
	}
}
开发者ID:anogowski,项目名称:gamebase,代码行数:19,代码来源:handlers.go


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