當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。