本文整理汇总了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)
}
示例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})
}
示例3: getRegisterPage
func getRegisterPage(user sessionauth.User, r render.Render) {
if user.IsAuthenticated() {
r.Redirect(INDEX_PAGE)
return
}
r.HTML(200, REGISTER_PAGE, nil)
}
示例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())
}
示例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")
}
示例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)
}
示例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)
}
示例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)
}
示例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})
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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")
}
}
示例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)
}
}
示例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)
}