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


Golang Context.Render方法代码示例

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


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

示例1: RegisterPost

// RegisterPost handles registration form, and create a session for the new user if the registration
// process is complete.
//
//		Method           POST
//
//		Route            /auth/register
//
//		Restrictions     None
//
// 		Template         None (All actions redirect to other routes )
//
// Flash messages may be set before redirection.
func RegisterPost(ctx *echo.Context) error {
	var flashMessages = flash.New()
	f := forms.New(utils.GetLang(ctx))
	lf := f.RegisterForm()(ctx.Request())
	if !lf.IsValid() {

		// Case the form is not valid, ships it back with the errors exclusively
		utils.SetData(ctx, authForm, lf)
		return ctx.Render(http.StatusOK, tmpl.RegisterTpl, utils.GetData(ctx))
	}

	// we are not interested in the returned user, rather we make sure the user has
	// been created.
	_, err := query.CreateNewUser(lf.GetModel().(forms.Register))
	if err != nil {
		flashMessages.Err(msgAccountCreateFailed)
		flashMessages.Save(ctx)
		ctx.Redirect(http.StatusFound, "/auth/register")
		return nil
	}

	// TODO: improve the message to include directions to use the current email and
	// password to login?
	flashMessages.Success(msgAccountCreate)
	flashMessages.Save(ctx)

	// Don't create session in this route, its best to leave only one place which
	// messes with the main user session. So we redirect to the login page, and encourage
	// the user to login.
	ctx.Redirect(http.StatusFound, "/auth/login")
	return nil
}
开发者ID:jwulf,项目名称:zedlist,代码行数:44,代码来源:local.go

示例2: index

func index(c *echo.Context) error {
	deviceids, err := tracksDB.GetDevicesID(groupID)
	if err != nil {
		return err
	}
	return c.Render(http.StatusOK, "index.html", deviceids)
}
开发者ID:jtprog,项目名称:geotrack,代码行数:7,代码来源:main.go

示例3: ArchiveView

// ArchiveView shows a list of posts arranged by its date
func ArchiveView(c *echo.Context) error {
	id := c.Param("id")
	var err error

	// Get archive data
	var archive models.Archive
	err = database.Current.Get(&archive, database.Queries.ArchiveBySignature, id)
	if err != nil {
		log.Println("Cannot get archive by signature", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Get related posts
	var posts []models.AuthoredPost
	err = database.Current.Select(&posts, database.Queries.ArchiveAuthoredPosts, id)
	if err != nil {
		log.Println("Cannot select posts", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Create our render context and fill base data
	ac := archiveContext{
		Archive:      archive,
		RelatedPosts: posts,
	}

	err = fillBlogContext(c, &ac.blogContext)
	if err != nil {
		log.Println("Cannot fill blog context", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	return c.Render(200, "archive", ac)
}
开发者ID:cedmundo,项目名称:site,代码行数:35,代码来源:handlers.go

示例4: welcome

func welcome(c *echo.Context) error {
	type User struct {
		Name string
		Age  int8
	}
	return c.Render(http.StatusOK, "welcome", User{Name: "schaffer", Age: 23})
}
开发者ID:schaffers,项目名称:typed,代码行数:7,代码来源:handler.go

示例5: Home

// Home shows the resumes home page.
//
//		Method           GET
//
//		Route            /resume/
//
//		Restrictions     Yes
//
// 		Template         resume/home.html
func Home(ctx *echo.Context) error {
	user := ctx.Get("User").(*models.Person)
	if res, err := query.GetAllPersonResumes(user); err == nil {
		utils.SetData(ctx, "resumes", res)
	}
	return ctx.Render(http.StatusOK, tmpl.ResumeHomeTpl, utils.GetData(ctx))
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:16,代码来源:resume.go

示例6: Register

// Register renders registration form.
//
//		Method           GET
//
//		Route            /auth/register
//
//		Restrictions     None
//
// 		Template         auth/register.html
func Register(ctx *echo.Context) error {
	f := forms.New(utils.GetLang(ctx))
	utils.SetData(ctx, authForm, f.RegisterForm()())

	// set page tittle to register
	utils.SetData(ctx, "PageTitle", "register")
	return ctx.Render(http.StatusOK, tmpl.RegisterTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:17,代码来源:local.go

示例7: RegionsHome

// RegionsHome renders regions home page.
//
//
//		Method           GET
//
//		Route            /jobs/regions
//
//		Restrictions     None
//
// 		Template         base/regions.html
//
func RegionsHome(ctx *echo.Context) error {
	regs, err := query.GetAllRegions()
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	utils.SetData(ctx, settings.RegionsListKey, regs)
	return ctx.Render(http.StatusOK, tmpl.BaseRegionsTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:20,代码来源:base.go

示例8: HandleError

func HandleError(err error, c *echo.Context) {
	err = c.Render(500, "500", baseContext{
		Info:  config.BlogInfo,
		Error: err,
	})
	if err != nil {
		log.Println("Cannot report error:", err)
	}
}
开发者ID:cedmundo,项目名称:site,代码行数:9,代码来源:handlers.go

示例9: CategoryView

// CategoryView shows a list of posts arranged by its category
func CategoryView(c *echo.Context) error {
	// Parse pagination attributes
	pn, ps := utils.GetPage(c)
	id, _ := strconv.Atoi(c.Param("id"))

	// Get category using id
	var category models.Category
	err := database.Current.Get(&category, database.Queries.CategoryByID, id)
	if err != nil {
		log.Println("Cannot select category:", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Query the posts
	var posts []models.AuthoredPost
	err = database.Current.Select(&posts, database.Queries.AuthoredPostsByCategory, id, ps, ps*(pn-1))
	if err != nil {
		log.Println("Cannot select posts:", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	var count int
	err = database.Current.Get(&count, database.Queries.PostByCategoryCount, id)
	if err != nil {
		log.Println("Cannot count posts:", err)
	}

	pc := int(math.Floor(float64(count/ps))) + 1

	// Generate preview for all posts
	for _, p := range posts {
		p.Preview = createPreview(p.TextContent)
	}

	// Create our context and fill base data
	cc := categoryContext{
		Category: category,
		RelatedPosts: models.Paginated{
			TotalObjects:  count,
			PageCount:     pc,
			PageNumber:    pn,
			PageSize:      ps,
			NextAvailable: pn < pc,
			Results:       posts,
		},
	}

	err = fillBlogContext(c, &cc.blogContext)
	if err != nil {
		log.Println("Cannot fill blog context", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Render the results
	return c.Render(200, "category", cc)
}
开发者ID:cedmundo,项目名称:site,代码行数:57,代码来源:handlers.go

示例10: Login

// Login renders login form.
//
//		Method           GET
//
//		Route            /auth/login
//
//		Restrictions     None
//
// 		Template         auth/login.html
//
func Login(ctx *echo.Context) error {

	f := forms.New(utils.GetLang(ctx))
	utils.SetData(ctx, authForm, f.LoginForm()())

	// set page tittle to login
	utils.SetData(ctx, "PageTitle", "login")

	return ctx.Render(http.StatusOK, tmpl.LoginTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:20,代码来源:local.go

示例11: Login

func Login(context echo.Context) error {
	_, err := helpers.ValidateJWT(context)
	if err != nil {
		return context.Render(http.StatusOK, "login", os.Getenv("AUTH0_CALLBACK"))
	}

	context.Redirect(http.StatusMovedPermanently, "/frontend")

	return context.String(http.StatusOK, "Done")
}
开发者ID:jessemillar,项目名称:byudzhet,代码行数:10,代码来源:views.go

示例12: Home

// Home displays home page
func (*SiteController) Home(c echo.Context) error {
	var site models.Site

	ret, err := site.Home()
	if err != nil {
		return c.Render(500, "500", err)
	}

	return c.Render(200, "index", ret)
}
开发者ID:mewben,项目名称:onix,代码行数:11,代码来源:sites.go

示例13: Single

// Single shows single page
func (*SiteController) Single(c echo.Context) error {
	var site models.Site

	ret, err := site.Single(c.P(0))
	if err != nil {
		return c.Render(400, "404", err)
	}

	return c.Render(200, "index", ret)
}
开发者ID:mewben,项目名称:onix,代码行数:11,代码来源:sites.go

示例14: JobsHome

// JobsHome renders jobs home page
//
//
//		Method           GET
//
//		Route            /jobs/
//
//		Restrictions     None
//
// 		Template         base/jobs.html
func JobsHome(ctx *echo.Context) error {
	jobs, err := query.GetLatestJobs()
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))

	}
	utils.SetData(ctx, settings.JobsListKey, jobs)
	utils.SetData(ctx, settings.PageTitleKey, "jobs")
	return ctx.Render(http.StatusOK, tmpl.BaseJobsHomeTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:21,代码来源:base.go

示例15: RegionsJobView

// RegionsJobView renders jobs from a gien region. The region name should be in short form.
//
//
//		Method           GET
//
//		Route            /jobs/regions/:name
//
//		Restrictions     None
//
// 		Template         base/regions_job.html
//
func RegionsJobView(ctx *echo.Context) error {
	name := ctx.Param("name")
	jobs, count, err := query.GetJobByRegionShort(name)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	utils.SetData(ctx, settings.JobsFound, count)
	utils.SetData(ctx, settings.JobsListKey, jobs)
	return ctx.Render(http.StatusOK, tmpl.BaseRegionsJobViewTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:22,代码来源:base.go


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