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

Golang web.Context类代码示例

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

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



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


示例16: resolve

// function to resolve a shorturl and redirect
func resolve(ctx *web.Context, short string) {
	kurl, err := load(short)
	if err == nil {
		go redis.Hincrby(kurl.Key, "Clicks", 1)
		ctx.Redirect(http.StatusMovedPermanently,
			kurl.LongUrl)
	} else {
		ctx.Redirect(http.StatusMovedPermanently,
			ROLL)
	}
}
开发者ID:vormplus,项目名称:kurz.go,代码行数:12,代码来源:kurz.go


示例17: get_specific_id

func get_specific_id(ctx *web.Context, id string) {
	log.Printf("get_specific_id %s\n", id)
	if e, err := Load(id); err == nil {
		t := entry_template
		m := map[string]interface{}{"Id": e.Id, "Date": e.Date, "Body": e.Body}
		s := mustache.Render(t, m)
		ctx.WriteString(page(s))
	} else {
		ctx.WriteString(page(fmt.Sprintf("<p>Invalid ID</p> <!--%v-->", err)))
	}
}
开发者ID:tengteng,项目名称:nobodycares,代码行数:11,代码来源:web_interface.go


示例18: newPostPost

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


示例19: index

// renders /
func index(ctx *web.Context) string {
	css, ok := ctx.Params["css"]
	if ok {
		SetCSS(ctx, css)
		ctx.Redirect(302, "/")
		return "ok"
	}
	//posts := postsForMonth(time.LocalTime()) //Db.GetLastNPosts(10)

	//	posts := lastPosts(0xff)
	posts := postsForLastNDays(4)
	if len(posts) <= 0 {
		posts = lastPosts(23)
	}
	//fmt.Printf("posts: %#v\n", posts)
	//embedded struct - our mustache templates need a NumOfComments field to render
	//but we don't want to put that field into the BlogPost Struct so it won't get stored
	//into the DB
	type MyPost struct {
		BlogPost
		NumOfComments int
	}

	//posts ordered by date. this is ugly. TODO: look up if mustache hase something to handle this situation
	type Date struct {
		Date  string
		Posts []MyPost
	}
	Db := DBGet()
	defer Db.Close()

	//loop through our posts and put them into the appropriate date structure
	dates := []Date{}
	var cur_date time.Time
	var date *Date
	for _, p := range posts {
		post_date := time.SecondsToLocalTime(p.Timestamp)
		if !(cur_date.Day == post_date.Day && cur_date.Month == post_date.Month && cur_date.Year == post_date.Year) {
			cur_date = *post_date
			dates = append(dates, Date{Date: cur_date.Format("Mon Jan _2 2006")})
			date = &dates[len(dates)-1]
		}
		p.Comments, _ = Db.GetComments(p.Id)
		mp := MyPost{p, len(p.Comments)}
		date.Posts = append(date.Posts, mp)
	}
	m := map[string]interface{}{
		"Dates": dates,
	}

	tmpl, _ := mustache.ParseFile("templ/index.mustache")
	s := tmpl.Render(&m, getCSS(ctx))
	return s
}
开发者ID:kybernetyk,项目名称:fettemama,代码行数:55,代码来源:index.go


示例20: adminDelPage

func adminDelPage(ctx *web.Context, id string) {
	sessionH := session.Start(ctx, h)
	defer sessionH.Save()
	if sessionH.Data["logged"] == nil {
		ctx.Redirect(302, "/admin/login")
		return
	}
	p := PageModelInit()
	p.Delete(id)

	ctx.Redirect(302, "/admin/page/list")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:12,代码来源:admin.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang websocket.Handler函数代码示例发布时间:2022-05-28
下一篇:
Golang web.Run函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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