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


Golang Request.Param方法代码示例

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


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

示例1: 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

示例2: fetchBlog

func fetchBlog(res *wcg.Response, req *wcg.Request, includePosts bool) (*models.Blog, *supports.Page, error) {
	// default query for posts.
	id := req.Param("blog_id")
	driver := models.NewBlogDriver(gae.NewContext(req), req.Logger)
	blog, query, err := driver.PostQuery(id)
	if err != nil {
		if err == models.ErrBlogNotFound {
			res.WriteHeader(404)
			res.WriteString("Not found")
			res.End()
			return nil, nil, err
		}
		res.RenderInternalError(err.Error())
		return nil, nil, err
	}

	if !includePosts {
		return blog, supports.EmptyPage, nil
	}
	query = query.Filter("IsNew =", false).Filter("IsDraft =", false).Order("-PostDate").Order("-UpdatedAt")
	per_page := wcg.ParseInt(req.Query("num"), AppConfig.DefaultPostsFetched, 0, AppConfig.MaxPostsFetched)
	current := wcg.ParseInt(req.Query("p"), 0, 0, wcg.ParseIntMax)
	page, err := supports.NewPage(current, per_page, query)
	if err != nil {
		res.RenderInternalError("Post pagination error: %v", err)
		return nil, nil, err
	}
	return blog, page, nil
}
开发者ID:speedland,项目名称:rakugaki,代码行数:29,代码来源:blogs.go

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: historyInsights

func historyInsights(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
	}
	var insights amebloHistoryInsights
	mckey := fmt.Sprintf(MC_KEY_HISTORY, app.Key, member.Name)
	dent := NewAmebloEntryDriver(appCtx)
	dref := NewAmebloRefDriver(appCtx)
	mc := appCtx.NewMemcacheDriver()
	err := mc.CachedObject(mckey, &insights, func() (interface{}, error) {
		return getAmebloHistoryInsights(member, dent, dref)
	}, req.Query("force") == "1")
	if err != nil {
		lib.Error(res, req, err)
		return
	}
	res.WriteJson(insights)
}
开发者ID:speedland,项目名称:apps,代码行数:21,代码来源:func.go


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