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


Golang web.Context类代码示例

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


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

示例1: RSS

func (c *Index) RSS(ctx *web.Context) string {
	p := PostModelInit()
	results := p.RSS()

	ctx.ContentType("xml")
	return mustache.RenderFile("templates/rss.mustache", map[string][]map[string]string{"posts": results})
}
开发者ID:JessonChan,项目名称:bloody.go,代码行数:7,代码来源:index.go

示例2: Start

func Start(ctx *web.Context, handler *MHandler) *Session {
	session := new(Session)
	session.handler = handler
	session.handler.Clean()
	old := false
	if ctx.Cookies != nil {
		if id, exists := ctx.Cookies["bloody_sess"]; exists {
			session.id = id
			old = true
		}
	}
	if !old {
		// Starts new session
		session.generateId()
		session.handler.Store(session.GetID(), nil)
	}
	rt := session.handler.Retrieve(session.GetID())
	json.Unmarshal(rt.SessionData, &session.Data)
	if session.Data == nil {
		t := make(map[string]interface{})
		session.Data = t
	}
	ctx.SetCookie("bloody_sess", session.GetID(), time.Now().Unix()+3600)
	return session
}
开发者ID:JessonChan,项目名称:bloody.go,代码行数:25,代码来源:session.go

示例3: index

func index(ctx *web.Context, val string) string {
	switch val {
	case "Liberator":
		ctx.Redirect(302, util.Settings.WebHome())
	}
	return val
}
开发者ID:gtalent,项目名称:LiberatorAdventures,代码行数:7,代码来源:web.go

示例4: LoadPost

func LoadPost(ctx *web.Context, val string) {
	username := ctx.Params["username"]
	password := ctx.Params["password"]

	salt := strconv.Itoa64(time.Nanoseconds()) + username

	var h hash.Hash = sha256.New()
	h.Write([]byte(password + salt))

	s, _err := conn.Prepare("INSERT INTO users VALUES(NULL, ?, ?, ?)")
	utils.ReportErr(_err)

	s.Exec(username, string(h.Sum()), salt)
	s.Finalize()
	conn.Close()
	sidebar := utils.Loadmustache("admin.mustache", &map[string]string{})

	//TESTING, REMOVE LATER
	script := "<script type=\"text/javascript\" src=\"../inc/adminref.js\"></script>"
	content := "Welcome to the admin panel, use the control box on your right to control the site content"
	//ENDTESTING

	mapping := map[string]string{"css": "../inc/site.css",
		"title":   "Proggin: Admin panel",
		"sidebar": sidebar,
		"content": content,
		"script":  script}

	output := utils.Loadmustache("frame.mustache", &mapping)
	ctx.WriteString(output)
}
开发者ID:Chownie,项目名称:Proggin,代码行数:31,代码来源:newuser.go

示例5: get_delete

func get_delete(ctx *web.Context, id string) {
	log.Printf("get_delete %s\n", id)
	if e, err := Load(id); err == nil {
		ctx.WriteString(page(edit_form("/delete", e.Id, e.Date, e.Body, "Really delete")))
	} else {
		ctx.WriteString(page("<p>Invalid ID</p>"))
	}
}
开发者ID:tengteng,项目名称:nobodycares,代码行数:8,代码来源:web_interface.go

示例6: checkGodLevel

func checkGodLevel(ctx *web.Context) bool {
	godlevel, _ := ctx.GetSecureCookie("godlevel")
	godlevel = godHash(godlevel)
	if godlevel == admin_pass {
		return true
	}
	return false
}
开发者ID:andradeandrey,项目名称:fettemama,代码行数:8,代码来源:admin.go

示例7: create_person

func create_person(ctx *web.Context) {
	var p Personne
	Personnes := gouda.M(p)
	p.Id = 0
	p.Nom = ctx.Request.Params["nom"][0]
	p.Age, _ = strconv.Atoi(ctx.Request.Params["age"][0])
	Personnes.Save(p)
	ctx.Redirect(302, "/")
}
开发者ID:zetaben,项目名称:gouda,代码行数:9,代码来源:sample_web_app.go

示例8: ReadPost

func (c *Index) ReadPost(ctx *web.Context, postId string) string {
	p := PostModelInit()
	result := p.RenderPost(postId)

	viewVars := make(map[string]interface{})
	viewVars["Title"] = result.Title
	viewVars["Content"] = result.Content
	viewVars["Date"] = time.Unix(result.Created, 0).Format(blogConfig.Get("dateFormat"))
	viewVars["Id"] = objectIdHex(result.Id.String())
	// To be used within the {{Comments}} blog
	viewVars["PostId"] = objectIdHex(result.Id.String())

	if result.Status == 0 {
		sessionH := session.Start(ctx, h)
		defer sessionH.Save()
		if sessionH.Data["logged"] == nil {
			ctx.Redirect(302, "/")
			return ""
		}
	}

	if blogConfig.Get("enableComment") != "" {
		viewVars["EnableComment"] = true
	} else {
		viewVars["EnableComment"] = false
	}

	// Render comments
	comments := make([]map[string]string, 0)
	for i, v := range result.Comments {
		comments = append(comments, map[string]string{
			"Number":  strconv.Itoa(i + 1),
			"Date":    time.Unix(v.Created, 0).Format(blogConfig.Get("dateFormat")),
			"Id":      v.Id[0:9],
			"RealId":  v.Id,
			"Content": v.Content,
			"Author":  v.Author})
	}
	viewVars["Comments"] = comments

	if next, exists := p.GetNextId(objectIdHex(result.Id.String())); exists {
		viewVars["Next"] = next
	}
	if last, exists := p.GetLastId(objectIdHex(result.Id.String())); exists {
		viewVars["Last"] = last
	}

	sessionH := session.Start(ctx, h)
	defer sessionH.Save()
	viewVars["Admin"] = false
	if sessionH.Data["logged"] != nil {
		viewVars["Admin"] = true
	}

	output := mustache.RenderFile("templates/view-post.mustache", viewVars)
	return render(output, result.Title)
}
开发者ID:JessonChan,项目名称:bloody.go,代码行数:57,代码来源:index.go

示例9: adminIndexGet

func adminIndexGet(ctx *web.Context) string {
	sessionH := session.Start(ctx, h)
	defer sessionH.Save()
	if sessionH.Data["logged"] != nil {
		ctx.Redirect(302, "/admin/post/list")
		return ""
	}
	ctx.Redirect(302, "/admin/login")
	return ""
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例10: saveHandler

func saveHandler(ctx *web.Context, title string) {
	body, ok := ctx.Request.Params["body"]
	if !ok {
		ctx.Abort(500, "No body supplied.")
		return
	}
	page := makePage(title, string(body))
	page.save()
	redirect(ctx, "view", title)
}
开发者ID:bmatsuo,项目名称:gowiki,代码行数:10,代码来源:handler.go

示例11: redirect

/*redirects the shortened URL to the real URL*/
func redirect(ctx *web.Context, key string) {
	/*fetch our URL*/
	url, _ := redisClient.Get(getRedisKey(key))
	if url == nil {
		printError(ctx, "I can't find that URL")
	} else {
		/*redirect*/
		ctx.Redirect(301, string(url))
	}
}
开发者ID:hernan43,项目名称:gourl,代码行数:11,代码来源:gourl.go

示例12: update_person

func update_person(ctx *web.Context) {
	var p Personne
	Personnes := gouda.M(p)
	i, _ := strconv.Atoi(ctx.Request.Params["id"][0])
	p = Personnes.Where(gouda.F("id").Eq(i)).First().(Personne)
	p.Nom = ctx.Request.Params["nom"][0]
	p.Age, _ = strconv.Atoi(ctx.Request.Params["age"][0])
	Personnes.Save(p)
	ctx.Redirect(302, "/person/"+fmt.Sprint(p.Id))
}
开发者ID:zetaben,项目名称:gouda,代码行数:10,代码来源:sample_web_app.go

示例13: adminLoginGet

func adminLoginGet(ctx *web.Context) string {
	sessionH := session.Start(ctx, h)
	defer sessionH.Save()
	if sessionH.Data["logged"] != nil {
		ctx.Redirect(302, "/admin/post/list")
		return ""
	}
	output := mustache.RenderFile("templates/admin-login.mustache")
	return render(output, "Login")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例14: newPostGet

func newPostGet(ctx *web.Context) string {
	sessionH := session.Start(ctx, h)
	defer sessionH.Save()
	if sessionH.Data["logged"] == nil {
		ctx.Redirect(302, "/admin/login")
		return ""
	}
	output := mustache.RenderFile("templates/new-post.mustache")
	return render(output, "New Post")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例15: Get

func Get(ctx *web.Context, val string) {
	v := strings.Split(val, "/", 2)
	controllerName := ""
	actionName := ""
	if len(v) == 2 {
		controllerName, actionName = v[0], v[1]
	} else if len(v) == 1 {
		controllerName = v[0]
		actionName = "index"
	}

	if conType, ok := C.Controllers[controllerName]; ok {
		conTypePtr := reflect.PtrTo(conType)
		actionMethName := strings.ToUpper(string(actionName[0:1])) + actionName[1:]
		var actionMeth reflect.Method
		found := false
		for i := 0; i < conTypePtr.NumMethod(); i++ {
			if conTypePtr.Method(i).Name == actionMethName {
				actionMeth = conTypePtr.Method(i)
				found = true
				break
			}
		}
		if !found {
			return
		}
		conValue := reflect.New(conType)
		conIndirect := reflect.Indirect(conValue)

		// Inject Params
		conIndirect.FieldByName("Params").Set(reflect.ValueOf(ctx.Request.Params))

		// Inject beans
		for beanName, setterFunc := range bean.Registry() {
			if _, ok := conType.FieldByName(beanName); ok {
				if f := conIndirect.FieldByName(beanName); f.IsValid() {
					f.Set(reflect.ValueOf(setterFunc()))
				}
			}
		}

		action := actionMeth.Func
		ret := action.Call([]reflect.Value{conValue})
		if len(ret) == 2 {
			m := ret[0].Interface().(mv.Model)
			v := ret[1].Interface().(mv.View)
			controllerName = v.String()
			ctx.WriteString(mustache.RenderFile("app/view/"+controllerName+"/index.m", m))
		} else if len(ret) == 1 {
			m := ret[0].Interface().(mv.Model)
			ctx.WriteString(mustache.RenderFile("app/view/"+controllerName+"/"+actionName+".m", m))
		}
	}
	return
}
开发者ID:chanwit,项目名称:gon,代码行数:55,代码来源:starter.go


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