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

Golang wcg.Request类代码示例

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

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



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

示例1: getResponseHelper

func getResponseHelper(req *wcg.Request) ResponseHelper {
	app := req.Local(LOCAL_APP_KEY).(*App)
	if strings.HasPrefix(req.URL().Path, "/api") {
		return app.Api
	}
	return app.Page
}
开发者ID:speedland,项目名称:apps,代码行数:7,代码来源:response_helper.go


示例2: fetchPost

func fetchPost(res *wcg.Response, req *wcg.Request, blog *models.Blog) (*models.Post, error) {
	driver := models.NewPostDriver(gae.NewContext(req), req.Logger)
	id := req.Param("post_id")
	blogId := req.Param("blog_id")
	post, err := driver.FindPostById(id, blogId)
	if err != nil {
		if err == models.ErrPostNotFound {
			res.WriteHeader(404)
			res.WriteString("Not found")
			res.End()
			return nil, err
		}
		res.RenderInternalError(err.Error())
		return nil, err
	}
	if post.PostState() != models.PostStatePublished {
		if post.OwnerId != req.User.Id() {
			res.WriteHeader(404)
			res.WriteString("Not found")
			res.End()
			return nil, err
		}
	}
	return post, err
}
开发者ID:speedland,项目名称:rakugaki,代码行数:25,代码来源:posts.go


示例3: NewContext

// Returns a Context Object.
func NewContext(req *wcg.Request) appengine.Context {
	ctx := req.Local("__gaetest__context")
	if ctx != nil {
		return ctx.(appengine.Context)
	}
	return appengine.NewContext(req.HttpRequest())
}
开发者ID:speedland,项目名称:wcg,代码行数:8,代码来源:util.go


示例4: queryShows

func queryShows(res *wcg.Response, req *wcg.Request, q *datastore.Query) (*showQueryResult, error) {
	var appCtx = lib.NewAppContextFromRequest(req)
	var showList []event.Show
	var basePath = req.HttpRequest().URL.Path
	per_page := 12 // Restict to 12 due to view rendering.
	page := wcg.ParseInt(req.Query("page"), 0, 0, wcg.ParseIntMax)
	if _, err := q.Offset(page * per_page).Limit(per_page).GetAll(&showList); err != nil {
		return nil, err
	}
	if showList == nil {
		return &showQueryResult{
			Shows: make([]EventShow, 0),
		}, nil
	}

	if list, err := NewEventShowList(appCtx, showList); err != nil {
		return nil, err
	} else {
		p := &showQueryResult{
			Shows:   list,
			Current: fmt.Sprintf("%s?page=%d&n=%d", basePath, page, per_page),
		}

		// prev url
		if page > 0 {
			p.Previous = fmt.Sprintf("%s?page=%d&n=%d", basePath, page-1, per_page)
		}

		// next url
		if len(p.Shows) == per_page {
			p.Next = fmt.Sprintf("%s?page=%d&n=%d", basePath, page+1, per_page)
		}
		return p, nil
	}
}
开发者ID:speedland,项目名称:apps,代码行数:35,代码来源:query.go


示例5: fetchPostForUpdate

func fetchPostForUpdate(req *wcg.Request, res *wcg.Response, blog *models.Blog) (*models.Post, error) {
	driver := models.NewPostDriver(gae.NewContext(req), req.Logger)
	id := req.Param("post_id")
	blogId := req.Param("blog_id")
	post, err := driver.FindPostById(id, blogId)
	if err != nil {
		if err == models.ErrPostNotFound {
			res.WriteHeader(404)
			res.WriteString("Not found")
			res.End()
			return nil, err
		}
		res.RenderInternalError(err.Error())
		return nil, err
	}
	if blog.Id != post.BlogId {
		res.WriteHeader(403)
		res.WriteString("You could not manage that blog.")
		res.End()
	}

	if post.OwnerId != req.User.Id() {
		res.WriteHeader(403)
		res.WriteString("You could not manage this post.")
		res.End()
		return nil, err
	}
	return post, err
}
开发者ID:speedland,项目名称:rakugaki,代码行数:29,代码来源:posts.go


示例6: GetCurrentApp

func GetCurrentApp(req *wcg.Request) *App {
	if app := req.Local(LOCAL_APP_KEY); app != nil {
		return app.(*App)
	} else {
		return nil
	}
}
开发者ID:speedland,项目名称:apps,代码行数:7,代码来源:response_helper.go


示例7: Forbidden

func (ph *PageHelper) Forbidden(res *wcg.Response, req *wcg.Request) {
	res.SetLocal("Ref", req.URL().RequestURI())
	res.TemplatesWithStatus(
		403,
		nil,
		"403.html", "header.html", "footer.html",
	)
}
开发者ID:speedland,项目名称:apps,代码行数:8,代码来源:page.go


示例8: crawlSpecifiedMembers

func crawlSpecifiedMembers(res *wcg.Response, req *wcg.Request, app *App) {
	member, ok := app.Members[req.Param("member")]
	if !ok {
		lib.NotFound(res, req)
		return
	}
	crawl(res, req, member, app)
}
开发者ID:speedland,项目名称:apps,代码行数:8,代码来源:func.go


示例9: Created

// HTTP 201 Created
func (api *ApiHelper) Created(res *wcg.Response, req *wcg.Request, id string) {
	loc := path.Join(req.URL().Path, fmt.Sprintf("%s.json", id))
	res.WriteJsonWithStatus(201, nil, map[string]interface{}{
		"ok":       true,
		"id":       id,
		"location": wcg.AbsoluteUrl(req, loc),
	})
}
开发者ID:speedland,项目名称:apps,代码行数:9,代码来源:api.go


示例10: indexSpecifiedMember

func indexSpecifiedMember(res *wcg.Response, req *wcg.Request, app *App) {
	var appCtx = lib.NewAppContextFromRequest(req)
	member, ok := app.Members[req.Param("member")]
	if !ok {
		lib.NotFound(res, req)
		return
	}

	num := wcg.ParseInt(req.Param("n"), 0, 0, wcg.ParseIntMax)
	if num == 0 {
		num = wcg.ParseIntMax
	}
	// Crawling
	crawler := ameblo.NewCrawler(appCtx.NewHttpClient())
	prefix := strings.TrimSuffix(member.BlogUrl, ".html") // xxxx.html => xxxx-{num}.html
	entries := make([]*ameblo.AmebloEntry, 0)
	for i := 1; i < num; i += 1 {
		url := fmt.Sprintf("%s-%d.html", prefix, i)
		req.Logger.Info("Indexing from %s ... ", url)
		newentries, err := crawler.CrawlEntryList(url)
		if err != nil {
			lib.InternalError(res, req, err)
			return
		}
		if len(newentries) > 20 {
			panic(fmt.Errorf("Unexpected number of entries (%d) are returned during indexing.", len(newentries)))
		}
		if len(newentries) == 0 {
			break
		}
		if len(newentries) < 20 {
			entries = append(entries, newentries...)
			break
		}
		if len(entries) > 0 && entries[len(entries)-1].Url == newentries[len(newentries)-1].Url {
			break
		}
		entries = append(entries, newentries...)
	}

	// Save and return resutls
	results := make([]string, 0)
	for _, ent := range entries {
		ent.Owner = member.Name
		results = append(results, ent.Url)
	}
	if err := updateIndexes(appCtx, entries); err != nil {
		req.Logger.Error("Failed to update the entry: %v", err)
		lib.InternalError(res, req, err) // stopped.
	} else {
		time.Sleep(10 * time.Second) // TODO: wait for all indexes are updated on datastore.
		mc := appCtx.NewMemcacheDriver()
		mckey := fmt.Sprintf(MC_KEY_HISTORY, app.Key, member.Name)
		mc.Delete(mckey)
		res.WriteJson(results)
	}
}
开发者ID:speedland,项目名称:apps,代码行数:57,代码来源:func.go


示例11: loadEvent

func loadEvent(app *App, req *wcg.Request, key string) (*event.Event, error) {
	var e event.Event
	d := NewEventDriver(lib.NewAppContextFromRequest(req))
	if err := d.Get(d.NewKey(req.Param(key), 0, nil), &e); err != nil {
		return nil, err
	} else {
		return &e, nil
	}
}
开发者ID:speedland,项目名称:apps,代码行数:9,代码来源:api_event.go


示例12: updateAttributesFromForm

func updateAttributesFromForm(res *wcg.Response, req *wcg.Request, e *event.Event) error {
	var err error
	if err = eventFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
		return err
	}
	e.Title = req.Form("title")
	e.Link = req.Form("link")
	e.ImageLink = req.Form("image_link")
	e.YAKeyword = req.Form("ya_keyword")
	e.EventType = event.ParseEventType(req.Form("event_type"))
	return nil
}
开发者ID:speedland,项目名称:apps,代码行数:12,代码来源:api_event.go


示例13: sendToBigQuery

func sendToBigQuery(req *wcg.Request) error {
	var errors = make([]error, 0)
	var svc *bigquery.Service
	var records []*wcg.LogRecord
	data := make(map[string][]*bigquery.TableDataInsertAllRequestRows)

	if tmp := req.Local(requestLocalLogCacheKey); tmp == nil {
		return nil
	} else {
		records = tmp.([]*wcg.LogRecord)
	}
	svc, err := bq.NewService(req)
	if err != nil {
		return err
	}

	for _, r := range records {
		tableId, row, err := bqTransform(r)
		if err != nil {
			errors = append(errors, err)
			continue
		}
		if rows, ok := data[tableId]; ok {
			rows = append(rows, row)
		} else {
			data[tableId] = []*bigquery.TableDataInsertAllRequestRows{row}
		}
	}
	for tableId, rows := range data {
		ret, err := svc.Tabledata.InsertAll(
			LogSinkConfig.BigqueryProject,
			LogSinkConfig.BigqueryDataset,
			tableId,
			&bigquery.TableDataInsertAllRequest{
				Kind: "bigquery#tableDataInsertAllRequest",
				Rows: rows,
			}).Do()
		if err != nil {
			errors = append(errors, err)
			continue
		}
		if len(ret.InsertErrors) > 0 {
			errors = append(errors, fmt.Errorf("InsertErrors: %s", ret.InsertErrors[0]))
			continue
		}
	}
	if len(errors) > 0 {
		return logTransmissionError(errors)
	}
	return nil
}
开发者ID:speedland,项目名称:wcg,代码行数:51,代码来源:bq_log.go


示例14: ahAuthHandler

func ahAuthHandler(res *wcg.Response, req *wcg.Request) bool {
	if strings.HasPrefix(req.URL().Path, "/_ah/") {
		req.User = &ApiUser{
			token: &models.ApiToken{
				Token:       "x-appengine-ah",
				Description: "Dummy API Token (_ah user)",
				CreatedAt:   time.Now(),
			},
			lastLogin: time.Now(),
		}
		return true
	}
	return false
}
开发者ID:speedland,项目名称:apps,代码行数:14,代码来源:auth.go


示例15: Redirect

func Redirect(res *wcg.Response, req *wcg.Request) {
	urlStr := req.Query("u")
	if urlobj, err := url.Parse(urlStr); err == nil && validateUrl(urlobj) {
		// TODO: Check blacklist
		res.Redirect(urlStr, 302)
		return
	}
	res.TemplatesWithStatus(
		404,
		nil,
		"404.html", "header.html", "footer.html",
	)
	return
}
开发者ID:speedland,项目名称:apps,代码行数:14,代码来源:redirector.go


示例16: cronAuthHandler

func cronAuthHandler(res *wcg.Response, req *wcg.Request) bool {
	cron := req.Header("X-Appengine-Cron")
	if cron == "true" {
		req.User = &ApiUser{
			token: &models.ApiToken{
				Token:       "x-appengine-cron",
				Description: "Dummy API Token (cron user)",
				CreatedAt:   time.Now(),
			},
			lastLogin: time.Now(),
		}
		return true
	}
	return false
}
开发者ID:speedland,项目名称:apps,代码行数:15,代码来源:auth.go


示例17: apiTokenAuthHandler

func apiTokenAuthHandler(res *wcg.Response, req *wcg.Request) bool {
	token := req.Header("X-SPEEDLAND-API-Token")
	if token != "" {
		// API Access
		d := NewApiTokenDriver(NewAppContextFromRequest(req))
		user, err := d.ApiUser(token)
		if err != nil || user == nil {
			req.Logger.Warn("API Token(%q) login failed: %v", token, err)
		} else {
			req.User = user
			return true
		}
	}
	return false
}
开发者ID:speedland,项目名称:apps,代码行数:15,代码来源:auth.go


示例18: showBlogHandler

func showBlogHandler(res *wcg.Response, req *wcg.Request) {
	blog, posts, err := fetchBlog(res, req, true)
	if err != nil {
		return
	}
	res.SetLocal("Og", &supports.Og{Title: blog.Title,
		Type: "blog", Url: wcg.AbsoluteUrl(req, req.URL().Path),
		Description: blog.Description, SiteName: AppConfig.SiteTitle,
	})
	res.SetLocal("blog", blog)
	res.SetLocal("is_owner", blog.OwnerId == req.User.Id())
	res.SetLocal("posts", posts)
	res.SetLocal("js", "/static/js/blog.js")
	res.Templates("blog.html", "header.html", "footer.html", "parts/post_part.html")
}
开发者ID:speedland,项目名称:rakugaki,代码行数:15,代码来源:blogs.go


示例19: deleteBlogHandler

func deleteBlogHandler(res *wcg.Response, req *wcg.Request) {
	driver := models.NewBlogDriver(gae.NewContext(req), req.Logger)
	err := driver.DeleteBlog(req.Param("blog_id"), req.User.Id())
	if err != nil {
		if supports.IsValidationError(err) {
			res.WriteJsonWithStatus(400, nil, err)
		} else if err == models.ErrBlogNotOwned {
			res.WriteJsonWithStatus(403, nil, no_permission)
		} else if err == models.ErrBlogNotFound {
			res.WriteJsonWithStatus(404, nil, not_found)
		} else {
			res.RenderInternalError(err.Error())
		}
		return
	}
	res.WriteJsonWithStatus(200, nil, ok)
}
开发者ID:speedland,项目名称:rakugaki,代码行数:17,代码来源:blogs.go


示例20: _processRequest

func (p *Page) _processRequest(res *wcg.Response, req *wcg.Request) {
	// instance of Page
	pi := &Page{}
	pi.App = p.App
	pi.Title = p.Title
	pi.Path = p.Path
	pi.assetPath = p.assetPath
	if p.templates != nil {
		pi.templates = make([]string, len(p.templates))
		for i := range p.templates {
			pi.templates[i] = p.templates[i]
		}
	}
	pi.Ogp("site_name", "SPEEDLAND Project")
	// pre process to update page attributes
	if p.handler != nil {
		p.handler(res, req, pi)
		if res.IsClosed() {
			return
		}
	}

	// automatically set ogp attributes if not set.
	if _, ok := pi.ogp["title"]; !ok {
		pi.Ogp("title", fmt.Sprintf("%s: %s", pi.App.Title, pi.Title))
	}
	if _, ok := pi.ogp["url"]; !ok {
		pi.Ogp("url", wcg.AbsoluteUrl(req, req.URL().RequestURI()))
	}

	// set default OGP from app settings.
	for k, v := range pi.App.DefaultOgp {
		pi.Ogp(k, v)
	}

	res.SetLocal("Page", pi)
	res.SetLocal("Ogp", pi.ogp)
	res.SetLocal("Request", req)
	res.SetLocal("TrackingCode", TrackingCode)
	res.SetLocal("__JsBundle__", pi.GetAssetPath())
	res.SetLocal("__APP_COMMIT", APP_COMMIT)
	res.SetLocal("__APP_TIMESTAMP", APP_TIMESTAMP)
	template_paths := []string{"./header.html", "./footer.html"}
	res.Templates(append(pi.GetTemplates(), template_paths...)...)
}
开发者ID:speedland,项目名称:apps,代码行数:45,代码来源:page.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang wcg.Response类代码示例发布时间:2022-05-28
下一篇:
Golang wcg.NewLogger函数代码示例发布时间: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