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


Golang utils.GetData函数代码示例

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


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

示例1: Delete

// Delete deletes the resume.
//
//		Method           POST
//
//		Route            /resume/delete/:id
//
//		Restrictions     Yes
//
// 		Template         None
func Delete(ctx *echo.Context) error {
	var flashMessages = flash.New()
	id, err := utils.GetInt(ctx.Param("id"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	user := ctx.Get("User").(*models.Person)

	resume, err := query.GetResumeByID(id)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage)
	}

	// Users are allowed to delete resumes that they don't own.
	if resume.PersonID != user.ID {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}

	err = query.Delete(resume)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.ServerErrorMessage)
		return ctx.Render(http.StatusInternalServerError, tmpl.ErrServerTpl, utils.GetData(ctx))
	}

	flashMessages.Success("resume successful deleted")
	flashMessages.Save(ctx)
	ctx.Redirect(http.StatusFound, "/resume/")
	return nil
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:41,代码来源:resume.go

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

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

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

示例5: View

// View displays the resume.
//
//		Method           GET
//
//		Route            /resume/view
//
//		Restrictions     Yes
//
// 		Template         resume/view.html
func View(ctx *echo.Context) error {
	iid, err := utils.GetInt(ctx.Param("id"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	resume, err := query.GetResumeByID(iid)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage)
	}
	utils.SetData(ctx, "resume", resume)
	return ctx.Render(http.StatusOK, tmpl.ResumeViewTpl, utils.GetData(ctx))
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:23,代码来源:resume.go

示例6: DocsHome

// DocsHome renders the home.md document for the given language.
//
//		Method           GET
//
//		Route            /docs
//
//		Restrictions     None
//
// 		Template         base/docs_index.html
//
func DocsHome(ctx *echo.Context) error {
	data := utils.GetData(ctx).(utils.Data)
	lang := data.Get(settings.LangDataKey).(string)
	home := settings.DocsPath + "/" + lang + "/" + settings.DocsIndexPage
	d, err := static.Asset(home)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	data.Set("doc", string(d))
	data.Set(docIndex, getDocIndex(lang))
	data.Set("PageTitle", settings.DocsIndexPage)
	return ctx.Render(http.StatusOK, tmpl.BaseDocsHomeTpl, data)
}
开发者ID:jwulf,项目名称:zedlist,代码行数:24,代码来源:base.go

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

示例8: JobView

// JobView displays a single job by the given job id.
//
//
//		Method           GET
//
//		Route            /jobs/view/:id
//
//		Restrictions     None
//
// 		Template         base/jobs_view.html
func JobView(ctx *echo.Context) error {
	id, err := utils.GetInt(ctx.Param("id"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	job, err := query.GetJobByID(id)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	if job != nil {
		utils.SetData(ctx, "Job", job)
	}
	return ctx.Render(http.StatusOK, tmpl.BaseJobsViewTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:26,代码来源:base.go

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

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

示例11: Docs

// Docs renders individual zedlist document.
//
//		Method           GET
//
//		Route            /docs/:name
//
//		Restrictions     None
//
// 		Template         base/docs.html
func Docs(ctx *echo.Context) error {
	data := utils.GetData(ctx).(utils.Data)
	lang := data.Get(settings.LangDataKey).(string)
	fname := ctx.Param("name")
	if filepath.Ext(fname) != ".md" {
		fname = fname + ".md"
	}
	fPath := settings.DocsPath + "/" + lang + "/" + fname
	d, err := static.Asset(fPath)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, utils.GetData(ctx))
	}
	data.Set("doc", string(d))
	data.Set("PageTitle", fname)
	data.Set(docIndex, getDocIndex(lang))
	return ctx.Render(http.StatusOK, tmpl.BaseDocTpl, data)
}
开发者ID:jwulf,项目名称:zedlist,代码行数:27,代码来源:base.go

示例12: hello

func hello(ctx *echo.Context) error {
	token := ""
	d := utils.GetData(ctx).(utils.Data)
	tok := d.Get("CsrfToken")
	if tok != nil {
		token = tok.(string)
	}
	return ctx.String(http.StatusOK, token)
}
开发者ID:jwulf,项目名称:zedlist,代码行数:9,代码来源:csrf_test.go

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

示例14: RegionsJobPaginate

// RegionsJobPaginate a route frr /jobs/regions/:name/:from/:to. It handles pagination where
// form to is offset and limit respectively.
//
// For example route "/jobs/regions/mza/2/4" will render from 2nd to 4th latest jobs from mwanza.
//
//		Method           GET
//
//		Route            /jobs/regions/:name/:from/:to
//
//		Restrictions     None
//
// 		Template         base/regions.html
func RegionsJobPaginate(ctx *echo.Context) error {
	name := ctx.Param("name")
	offset, err := utils.GetInt(ctx.Param("from"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}

	limit, err := utils.GetInt(ctx.Param("to"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	jobs, err := query.GetJobByRegionPaginate(name, offset, limit)
	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)
	return ctx.Render(http.StatusOK, tmpl.BaseRegionsPaginateTpl, utils.GetData(ctx))
}
开发者ID:jwulf,项目名称:zedlist,代码行数:33,代码来源:base.go

示例15: Update

// Update renders the resume update page.
//
//		Method           GET
//
//		Route            /resume/update/:id
//
//		Restrictions     Yes
//
// 		Template         None
func Update(ctx *echo.Context) error {
	id, err := utils.GetInt(ctx.Param("id"))
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	user := ctx.Get("User").(*models.Person)

	resume, err := query.GetResumeByID(id)
	if err != nil {
		utils.SetData(ctx, "Message", tmpl.NotFoundMessage)
		return ctx.Render(http.StatusNotFound, tmpl.ErrNotFoundTpl, tmpl.NotFoundMessage)
	}

	// Users are allowed to update resumes that they own.
	if resume.PersonID != user.ID {
		utils.SetData(ctx, "Message", tmpl.BadRequestMessage)
		return ctx.Render(http.StatusBadRequest, tmpl.ErrBadRequest, utils.GetData(ctx))
	}
	utils.SetData(ctx, "resume", resume)
	return ctx.Render(http.StatusOK, tmpl.ResumeUpddateTpl, utils.GetData(ctx))
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:31,代码来源:resume.go


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