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


Golang render.Render类代码示例

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


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


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