• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang render.Render类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: SignUp

func SignUp(s sessions.Session, r render.Render, x csrf.CSRF) {
	returnvals := map[string]interface{}{
		"csrf":  x.GetToken(),
		"Title": "Nightcrawler Signup",
	}
	r.HTML(200, "sign_up", returnvals)
}
开发者ID:neovintage,项目名称:nightcrawler,代码行数:7,代码来源:authentication.go


示例2: ReadListQnA

func ReadListQnA(req *http.Request, r render.Render, db *mgo.Database) {
	appid := req.Header.Get("Application-Id")
	if appid == "" {
		r.JSON(handlers.HttpErr(http.StatusNotFound, "insert to Application-Id"))
		return
	}
	////
	colQuerier := bson.M{}
	change := bson.M{"$set": bson.M{"reception": true}}
	CollectionName := handlers.CollectionNameQnA(appid)
	if _, err := db.C(CollectionName).UpdateAll(colQuerier, change); err != nil {
		r.JSON(handlers.HttpErr(http.StatusNotFound, err.Error()))
		return
	}
	var qnas []QnA
	if err := db.C(CollectionName).Find(bson.M{}).Sort("-time").All(&qnas); err != nil {
		r.JSON(handlers.HttpErr(http.StatusNotFound, err.Error()))
		return
	}

	if qnas == nil {
		r.JSON(http.StatusOK, map[string]interface{}{"return": bson.D{}})
		return
	}

	r.JSON(http.StatusOK, map[string]interface{}{"return": qnas})
}
开发者ID:haruio,项目名称:haru-golang-helpcenter,代码行数:27,代码来源:QnAController.go


示例3: getRegisterPage

func getRegisterPage(user sessionauth.User, r render.Render) {
	if user.IsAuthenticated() {
		r.Redirect(INDEX_PAGE)
		return
	}
	r.HTML(200, REGISTER_PAGE, nil)
}
开发者ID:jmptrader,项目名称:chatgo,代码行数:7,代码来源:user.go


示例4: Login

func Login(session sessions.Session, re render.Render, r *http.Request) {
	client_id := common.Config.OAuth2Client_ID

	letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	b := make([]rune, 10)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	session.AddFlash(string(b), "state")

	redirectBack := r.URL.Query().Get("redirect_back")
	ref := r.Referer()

	if redirectBack == "true" && ref != "" {
		session.Set("redirect_to", ref)
	} else {
		session.Set("redirect_to", nil)
	}

	query := url.Values{}
	query.Set("client_id", client_id)
	query.Set("state", string(b))
	query.Set("scope", "repo")

	dest := url.URL{
		Scheme:   "https",
		Host:     "github.com",
		Path:     "/login/oauth/authorize",
		RawQuery: query.Encode(),
	}
	re.Redirect(dest.String())
}
开发者ID:SemQuery,项目名称:web,代码行数:33,代码来源:session.go


示例5: UpdUserTodo

func UpdUserTodo(r render.Render, rq *http.Request) {
	for i := 0; i < 1; i++ {

		idStr := strings.TrimSpace(rq.FormValue("id"))
		id, err := strconv.ParseInt(idStr, 10, 64)
		if err != nil {
			break
		}

		username := strings.TrimSpace(rq.FormValue("username"))
		if len(username) == 0 {
			break
		}

		password := strings.TrimSpace(rq.FormValue("password"))
		if len(password) == 0 {
			break
		}

		user := make(map[string]interface{}, 2)
		user["username"] = username
		user["password"] = password

		models.UpdUser(id, user)
	}

	r.Redirect("/user/list")
}
开发者ID:Zxnui,项目名称:go-martini-test,代码行数:28,代码来源:controller_user.go


示例6: Login

func (ac *AuthController) Login(user models.User, r render.Render) {
	getuser := models.User{}
	session := ac.session.DB(os.Getenv("DB_NAME")).C("users")
	err := session.Find(bson.M{"email": user.Email}).One(&getuser)
	if err != nil {
		panic(err)
	}

	err = bcrypt.CompareHashAndPassword([]byte(getuser.Password), []byte(user.Password))

	if err != nil {
		panic(err)
	}

	token := jwt.New(jwt.GetSigningMethod("HS256"))
	token.Claims["user_id"] = getuser.Id
	token.Claims["email"] = getuser.Email
	token.Claims["exp"] = time.Now().Add(time.Minute * 5).Unix()
	tokenString, err := token.SignedString([]byte(SecretKey))
	if err != nil {
		r.JSON(500, map[string]interface{}{"_error": "500: Signing Error."})
		return
	}

	data := map[string]string{
		"token": tokenString,
	}

	r.JSON(200, data)
}
开发者ID:EwanValentine,项目名称:TeamLeague,代码行数:30,代码来源:auth_controllers.go


示例7: genericResponseFormatter

func genericResponseFormatter(r render.Render, apikey string, payload map[string]interface{}, extErr error) {
	var (
		statusCode int
		err        error
		res        Response
	)

	if extErr != nil {
		statusCode = FailureStatus
		res = Response{
			ErrorMsg: extErr.Error(),
		}

	} else {

		if _, err = json.Marshal(payload); err != nil {
			statusCode = FailureStatus
			res = Response{
				ErrorMsg: err.Error(),
			}

		} else {
			statusCode = SuccessStatus
			res = Response{
				APIKey:  apikey,
				Payload: payload,
			}
		}
	}
	r.JSON(statusCode, res)
}
开发者ID:malston,项目名称:pezauth,代码行数:31,代码来源:func.go


示例8: GroupCreate

func GroupCreate(db gorm.DB, r render.Render, group models.Group) {
	if err := db.Save(&group).Error; err != nil {
		r.JSON(http.StatusConflict, map[string]interface{}{"error": "Group conflict"})
		return
	}
	r.JSON(http.StatusCreated, group)
}
开发者ID:RadioTerminal,项目名称:podcaster,代码行数:7,代码来源:group.go


示例9: IndexHandler

func IndexHandler(rr render.Render, w http.ResponseWriter, r *http.Request) {
	var pp models.Post
	p := make([]models.Post, 0)
	namefs := utils.Getlistfileindirectory(Pathposts)
	tnamefs := namefs
	vsegopost := len(namefs)
	if len(namefs) != 0 {
		namefs = utils.SorttoDown(namefs)
		if Kolpost > len(namefs) {
			tnamefs = namefs[:]
		} else {
			tnamefs = namefs[:Kolpost]
		}

		for _, namef := range tnamefs {
			pp.GetPostfromFileMd(Pathposts + string(os.PathSeparator) + namef)
			if !pp.GetDraft() { // не отражаются черновики
				p = append(p, pp)
			}
		}
	} else {
		p = append(p, models.Post{Id: "ПОСТОВ НЕТ", Title: "ЭТОТ БЛОГ ПУСТ. ПРИХОДИТЕ ПОЗЖЕ ;)", ContentText: ""})
	}

	rr.HTML(200, "index", &models.PagePost{TitlePage: "Блог проектов kaefik", Posts: p, Postright: vsegopost - Kolpost})
}
开发者ID:kaefik,项目名称:go-little-blog,代码行数:26,代码来源:routes.go


示例10: UpdateQuestion

/**
更新
**/
func UpdateQuestion(r render.Render, req *http.Request) {
	c := appengine.NewContext(req)
	id, _ := strconv.Atoi(req.FormValue("Key"))
	key := datastore.NewKey(c, "Question", "", int64(id), nil)
	var question Question
	if err := datastore.Get(c, key, &question); err != nil {
		c.Criticalf(err.Error())
	}
	question.Content = req.FormValue("Content")
	question.LargeCategoryKey = req.FormValue("LargeCategoryKey")
	question.MediumCategoryKey = req.FormValue("MediumCategoryKey")
	question.SmallCategoryKey = req.FormValue("SmallCategoryKey")
	question.Rubric = req.FormValue("Rubric")
	question.Percentage, _ = strconv.ParseFloat(req.FormValue("Percentage"), 64)
	question.Status = req.FormValue("Status")
	question.Level = req.FormValue("Level")
	question.UserKey = req.FormValue("UserKey")
	_, err := datastore.Put(c, key, &question)
	if err != nil {
		c.Criticalf("%s", err)
		r.JSON(400, err)
	} else {
		r.JSON(200, question)
	}
}
开发者ID:KojiTakahara,项目名称:dragon-formula,代码行数:28,代码来源:questionController.go


示例11: Create

func (ps ProjectService) Create(projet models.Project, r render.Render) {
	err := utils.ORM.Save(&projet).Error
	if err != nil {
		utils.Log.Error("Failed to create project: %v", err)
		r.HTML(403, "project/new", projet)
	}
}
开发者ID:gophergala2016,项目名称:chroniton,代码行数:7,代码来源:projects.go


示例12: DeleteItem

func DeleteItem(r render.Render, params martini.Params, c *redis.Client) {
	err := c.HDel("godo:items", params["id"]).Err()
	if err != nil {
		panic(err)
	}
	r.JSON(http.StatusOK, nil)
}
开发者ID:gabrtv,项目名称:example-todo,代码行数:7,代码来源:main.go


示例13: PreventReauth

func PreventReauth(session sessions.Session, r render.Render) {
	_, ok := session.Get("id").(int64)
	if ok {
		session.AddFlash("warning: You are already signed in!")
		r.Redirect("/dashboard")
	}
}
开发者ID:gophergala2016,项目名称:chroniton,代码行数:7,代码来源:handlers.go


示例14: awardUser

func awardUser(db *mgo.Database, session sessions.Session, r render.Render, x csrf.CSRF) {
	template := make(map[string]string)
	template["contactUrl"] = os.Getenv("CONTACT_URL")
	template["contactValue"] = os.Getenv("CONTACT_VALUE")
	user := session.Get("user").(string)
	status := checkStatus(db, user)
	if status == 0 {
		template["message"] = "Can't seem to find records of you :/"
		r.HTML(http.StatusUnauthorized, "error", template)
	} else if status == 1 {
		err := userHasAuth(db, user)
		if err != nil {
			log.Println(err)
			template["message"] = "Uh oh! Please report this :("
			r.HTML(http.StatusInternalServerError, "error", template)
		} else {
			r.HTML(http.StatusOK, "form", x.GetToken())
		}
	} else if status == 2 {
		r.HTML(http.StatusOK, "form", x.GetToken())
	} else if status == 3 {
		template["message"] = "Hey buddy, it seems you have been awarded before."
		r.HTML(http.StatusUnauthorized, "error", template)
	}
}
开发者ID:nquinlan,项目名称:contribot,代码行数:25,代码来源:github.go


示例15: updateUser

func updateUser(r render.Render, params martini.Params, re *http.Request, f *fishhub.DBService, userForm user.UserUpdateForm) {
	d := f.DB.Copy()
	defer d.Close()
	query := bson.M{"_id": bson.ObjectIdHex(params["id"])}

	update := bson.M{
		"address":      userForm.Address,
		"contactno":    userForm.ContactNo,
		"country":      userForm.Country,
		"email":        userForm.Email,
		"locale":       userForm.Locale,
		"name":         userForm.Name,
		"notification": userForm.Notification,
		"role":         userForm.Role,
	}

	err := d.Update("users", query, bson.M{"$set": update})

	if err != nil {
		displayUnknownError(r)
		return
	}

	r.JSON(200, userForm)
}
开发者ID:greensolutionsonly,项目名称:fishhub,代码行数:25,代码来源:user.go


示例16: recovery

func recovery(
	c martini.Context,
	req *http.Request,
	ren render.Render,
	dec formDecoder,
) {
	defer func() {
		if r := recover(); r != nil {
			switch err := r.(type) {
			case jsonError:
				handleJsonError(err, ren)
			case authError:
				authenticate(err, dec, ren, req)
			case userError:
				ren.HTML(200, "error", m{
					"Message": formatMessage(err.Error()),
				})
			case csql.Error:
				ren.HTML(200, "error", m{
					"Message": formatMessage(err.Error()),
				})
			default:
				panic(r)
			}
		}
	}()
	c.Next()
}
开发者ID:BurntSushi,项目名称:lcmweb,代码行数:28,代码来源:web.go


示例17: ListBuckets

func ListBuckets(r render.Render, db database.Database) {
	if buckets, err := db.ListBuckets(); err != nil {
		JsonErrorf(r, http.StatusBadRequest, err.Error())
	} else {
		r.JSON(http.StatusOK, buckets)
	}
}
开发者ID:aroravishal,项目名称:changes-artifacts,代码行数:7,代码来源:buckethandler.go


示例18: webAuth

func webAuth(
	lg *log.Logger,
	c martini.Context,
	routes martini.Routes,
	params martini.Params,
	r *http.Request,
	w http.ResponseWriter,
	s *sessions.Session,
	ren render.Render,
	dec formDecoder,
	mdec multiDecoder,
) {
	userId := sessGet(s, sessionUserId)
	if len(userId) == 0 {
		panic(ae(""))
	}
	state := &web{
		lg: lg, c: c, routes: routes, params: params,
		r: r, w: w, s: s, ren: ren,
		decode: dec, multiDecode: mdec,
		user: findUserById(userId),
	}
	ren.Template().Funcs(template.FuncMap{
		"url": state.url,
	})
	c.Map(state)
}
开发者ID:BurntSushi,项目名称:lcmweb,代码行数:27,代码来源:web.go


示例19: GetAllRelations

//Get /users/:user_id/relationships
func (u *UserHandler) GetAllRelations(request *http.Request, rd render.Render, params martini.Params) {
	// 获取 url 参数
	userid, err := strconv.ParseInt(params["user_id"], 10, 64)
	if err != nil {
		rd.Text(400, "The request cannot be fulfilled due to bad syntax.")
		return
	}

	//验证 user 是否存在
	_, err = u.userService.GetUser(userid)
	if err != nil {
		if err == pg.ErrNoRows {
			rd.Text(400, fmt.Sprintln("user", userid, "not exist"))
		} else {
			rd.Text(500, err.Error())
		}
		return
	}

	rs, err := u.userService.GetUserRelations(userid)
	if err != nil {
		rd.Text(500, err.Error())
		return
	}

	relations := make([]interface{}, 0, 0)
	for _, r := range rs {
		relations = append(relations, fmtRelationShip(r))
	}

	rd.JSON(200, relations)
}
开发者ID:Arthurli,项目名称:RestfulDemo,代码行数:33,代码来源:user.go


示例20: CollectionResponse

func CollectionResponse(r render.Render, collection []interface{}, err error) {
	if err != nil {
		r.JSON(404, nil)
	} else {
		r.JSON(200, collection)
	}
}
开发者ID:jartek,项目名称:meh,代码行数:7,代码来源:server.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sessionauth.User类代码示例发布时间:2022-05-23
下一篇:
Golang render.Renderer函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap