當前位置: 首頁>>代碼示例>>Golang>>正文


Golang template.TmplInfo類代碼示例

本文整理匯總了Golang中hellogolang/HooGL/template.TmplInfo的典型用法代碼示例。如果您正苦於以下問題:Golang TmplInfo類的具體用法?Golang TmplInfo怎麽用?Golang TmplInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TmplInfo類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PeopleAvatarEdit

func PeopleAvatarEdit(rw http.ResponseWriter, req *http.Request) {
	people := isLogin(req)

	if people == nil {
		errorMessage(rw, req)
		return
	}

	if req.Method == "GET" {
		tmpl := template.New("people-ucenter-avatar")
		tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
		tmpl.ParseFiles(
			"template/front/header.tmpl",
			"template/front/people-ucenter-avatar.tmpl",
			"template/front/footer.tmpl",
			"template/front/people-ucenter-sidebar.tmpl")

		tmplInfo := hgTemplate.TmplInfo{}
		tmplInfo.AddData("people", people)
		tmplInfo.Js = []string{
			"js/jquery.validate.js"}

		tmpl.ExecuteTemplate(rw, "people-ucenter-avatar", map[string]interface{}{"tmplInfo": tmplInfo})

	} else if req.Method == "POST" {

		req.ParseMultipartForm(32 << 20)
		file, handler, err := req.FormFile("uploadfile")
		if err != nil {
			fmt.Println(err)
			return
		}
		defer file.Close()

		f, err := os.OpenFile("tmp/"+handler.Filename, os.O_RDWR|os.O_CREATE, 0777)
		if err != nil {
			fmt.Println(err)
			return
		}
		defer f.Close()

		io.Copy(f, file)
		f.Seek(0, 0)

		ext := hgQiniu.GetExt(handler.Filename)
		fk := hgQiniu.GetFk(people.Idpeople)

		err = hgQiniu.UploadAvatar(f, fk+"."+ext)
		if err == nil {
			people.Avatar = "http://hellogolang.qiniudn.com/" + fk + "." + ext
			peopleModel.Update(*people)
			http.Redirect(rw, req, "/people/ucenter/", http.StatusFound)
		} else {
			fmt.Println(err)
			return
		}
	}
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:58,代碼來源:peopleHandler.go

示例2: PeopleUcenter

func PeopleUcenter(rw http.ResponseWriter, req *http.Request) {
	people := isLogin(req)

	idpeople := hgForm.GetInt64(req, "idpeople", 0)

	tmpl := template.New("people-ucenter")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/people-ucenter.tmpl",
		"template/front/footer.tmpl",
		"template/front/people-ucenter-sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.AddData("people", people)

	if idpeople != 0 {
		vpeople := peopleModel.Find(idpeople)
		tmplInfo.AddData("vpeople", vpeople)
	} else {
		tmplInfo.AddData("vpeople", people)
	}

	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmpl.ExecuteTemplate(rw, "people-ucenter", map[string]interface{}{"tmplInfo": tmplInfo})

}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:29,代碼來源:peopleHandler.go

示例3: errorMessage

func errorMessage(rw http.ResponseWriter, req *http.Request) {
	tmpl := template.New("error-message")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})

	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/error-message.tmpl",
		"template/front/footer.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmpl.ExecuteTemplate(rw, "error-message", map[string]interface{}{"tmplInfo": tmplInfo})
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:15,代碼來源:errorHandler.go

示例4: PeopleRegist

/*
 * 注冊操作
 */
func PeopleRegist(rw http.ResponseWriter, req *http.Request) {
	//檢測是否已經登錄
	//people := isLogin(req)

	if req.Method == "GET" {
		tmpl := template.New("registView")
		tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
		tmpl.ParseFiles(
			"template/front/header.tmpl",
			"template/front/people-regist.tmpl",
			"template/front/footer.tmpl")

		tmplInfo := hgTemplate.TmplInfo{}
		tmplInfo.Js = []string{
			"js/jquery.validate.js"}

		tmpl.ExecuteTemplate(rw, "people-regist", map[string]interface{}{"tmplInfo": tmplInfo})
	} else if req.Method == "POST" {
		req.ParseForm()
		var people model.People
		people.Name = req.FormValue("name")
		people.Email = req.FormValue("email")
		people.Password = req.FormValue("password")
		people.Avatar = "/assets/image/default.png"

		if checkRegistMess(people) {
			fmt.Println("start insert ...")
			people := peopleModel.Insert(people)
			if people != nil {
				session, _ := store.Get(req, "hellogolang.org-user")
				session.Values["name"] = people.Name
				session.Values["email"] = people.Email
				session.Values["idpeople"] = people.Idpeople

				session.Save(req, rw)
				http.Redirect(rw, req, "/", http.StatusFound)
			}
		}

	}
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:44,代碼來源:peopleHandler.go

示例5: PeopleMessageEdit

func PeopleMessageEdit(rw http.ResponseWriter, req *http.Request) {
	people := isLogin(req)

	if people == nil {
		errorMessage(rw, req)
		return
	}

	if req.Method == "GET" {
		tmpl := template.New("people-ucenter")
		tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
		tmpl.ParseFiles(
			"template/front/header.tmpl",
			"template/front/people-ucenter-edit.tmpl",
			"template/front/footer.tmpl",
			"template/front/people-ucenter-sidebar.tmpl")

		tmplInfo := hgTemplate.TmplInfo{}
		tmplInfo.AddData("people", people)
		tmplInfo.Js = []string{
			"js/jquery.validate.js"}

		tmpl.ExecuteTemplate(rw, "people-ucenter-edit", map[string]interface{}{"tmplInfo": tmplInfo})
	} else if req.Method == "POST" {
		req.ParseForm()

		people.Phone = req.FormValue("name")
		people.QQ = req.FormValue("qq")
		people.Homepage = req.FormValue("homepage")
		people.Company = req.FormValue("company")
		people.Signature = req.FormValue("signature")
		people.Resume = req.FormValue("resume")
		people.PubQQ = hgForm.GetInt(req, "pubqq", 0)
		people.PubEmail = hgForm.GetInt(req, "pubemail", 0)

		peopleModel.Update(*people)

		http.Redirect(rw, req, "/people/ucenter/", http.StatusFound)
	}
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:40,代碼來源:peopleHandler.go

示例6: PostPage

/*
 *	文章分頁列表
 */
func PostPage(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()
	people := isLogin(req)

	req.ParseForm()
	pageSize := 10
	page := hgForm.GetInt(req, "page", 1)

	conditions := make(map[string]string)
	pageHelper := hgPageination.Page{}

	//IdpostClass, err := strconv.ParseInt(req.FormValue("cat"), 10, 64)
	IdpostClass := hgForm.GetInt64(req, "cat", 0)

	if IdpostClass != 0 {
		conditions["post.idpost_class ="] = req.FormValue("cat")
		pageHelper.BaseUrl = "/post/?cat=" + req.FormValue("cat") + "&page="
	} else {
		pageHelper.BaseUrl = "/post/?page="
	}

	postClass := postClassModel.Find(IdpostClass)

	if postClass == nil {
		//出錯處理
	}

	posts, count := postModel.FindAll(page, pageSize, conditions)

	pageHelper.Count = count
	pageHelper.PageSize = pageSize
	pageHelper.PageNum = page
	pageHelper.Compute()

	tmpl := template.New("post-pageView")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal, "IntEqual": hgTemplate.IntEqual, "RemoveHtmlTag": hgTemplate.RemoveHtmlTag})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/post-list.tmpl",
		"template/front/footer.tmpl",
		"template/front/page.tmpl",
		"template/front/sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.Js = []string{
		"kindeditor/kindeditor-min.js",
		"kindeditor/lang/zh_CN.js"}
	tmplInfo.CurrentNav = "article"
	tmplInfo.Title = "Hello Golang -文章"
	tmplInfo.Description = "全新的go語言資訊!精選的go語言教程!經典的go語言代碼!"

	tmplInfo.AddData("people", people)
	tmplInfo.AddData("posts", posts)
	tmplInfo.AddData("pageHelper", pageHelper)
	tmplInfo.AddData("postClasses", postClasses)
	tmplInfo.AddData("postClass", postClass)

	tmpl.ExecuteTemplate(rw, "post-list", map[string]interface{}{"tmplInfo": tmplInfo})
	tmpl.Execute(rw, nil)

}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:64,代碼來源:postHandler.go

示例7: PostCreate

/*
 *	創建文章
 */
func PostCreate(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()

	people := isLogin(req)
	if req.Method == "GET" {
		postClass := postClassModel.FindAll()
		tmpl := template.New("post-createView")
		tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal})
		tmpl.ParseFiles(
			"template/front/header.tmpl",
			"template/front/post-create.tmpl",
			"template/front/footer.tmpl",
			"template/front/sidebar.tmpl")

		tmplInfo := hgTemplate.TmplInfo{}

		tmplInfo.Js = []string{
			"ckeditor/ckeditor.js"}
		tmplInfo.CurrentNav = "none"
		tmplInfo.Title = "Hello Golang -新建文章"
		tmplInfo.Description = "開源Go語言愛好者交流平台"

		tmplInfo.AddData("people", people)
		tmplInfo.AddData("postClass", postClass)
		tmplInfo.AddData("postClasses", postClasses)

		tmpl.ExecuteTemplate(rw, "post-create", map[string]interface{}{"tmplInfo": tmplInfo})
		tmpl.Execute(rw, nil)
	} else if req.Method == "POST" {
		req.ParseForm()
		people := isLogin(req)

		var err error
		var post model.Post

		post.Class.IdpostClass, err = strconv.ParseInt(req.FormValue("post_class"), 10, 64)

		post.Content = req.FormValue("content")
		post.ReprintFrom = req.FormValue("reprint_from")
		post.ReprintUrl = req.FormValue("reprint_url")
		post.Title = req.FormValue("title")
		post.Author.Idpeople = people.Idpeople

		post.ReadNum = 0
		post.ReplyNum = 0

		postModel.Insert(post)
		http.Redirect(rw, req, "/post/?cat="+req.FormValue("post_class"), http.StatusFound)

		if err != nil {
			fmt.Println(err)
		} else {
			people = peopleModel.Find(people.Idpeople)
			people.Postnum++
			peopleModel.Update(*people)
		}

	}
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:62,代碼來源:postHandler.go

示例8: Index

func Index(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()
	people := isLogin(req)
	req.ParseForm()

	pageSize := 10
	page := hgForm.GetInt(req, "page", 1)

	posts, count := postModel.FindAll(page, pageSize, map[string]string{})

	pageHelper := hgPageination.Page{}
	pageHelper.Count = count
	pageHelper.PageSize = pageSize
	pageHelper.PageNum = page
	pageHelper.BaseUrl = "/?page="
	pageHelper.Compute()

	tmpl := template.New("indexView")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal, "IntEqual": hgTemplate.IntEqual, "RemoveHtmlTag": hgTemplate.RemoveHtmlTag})

	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/index.tmpl",
		"template/front/footer.tmpl",
		"template/front/page.tmpl",
		"template/front/sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}

	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmplInfo.CurrentNav = "index"
	tmplInfo.Title = "Hello Golang -首頁"
	tmplInfo.Description = "開源Go語言愛好者交流平台"

	tmplInfo.AddData("people", people)
	tmplInfo.AddData("posts", posts)
	tmplInfo.AddData("pageHelper", pageHelper)
	tmplInfo.AddData("postClasses", postClasses)

	tmpl.ExecuteTemplate(rw, "index", map[string]interface{}{"tmplInfo": tmplInfo})
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:43,代碼來源:postHandler.go

示例9: PostItem

/*
 *	查看單個文章頁
 */
func PostItem(rw http.ResponseWriter, req *http.Request) {
	postClasses := postClassModel.FindAll()

	req.ParseForm()
	people := isLogin(req)

	page := hgForm.GetInt(req, "page", 1)

	postId := hgForm.GetInt64(req, "postId", 0)
	if postId == 0 {
		//出錯
	}

	pageSize := 10
	post := postModel.Find(postId)

	if post == nil {
		fmt.Println("post is nil...")
		//文章不存在
	}

	comments, count := commentModel.FindAllByPostID(postId, page, pageSize)

	pageHelper := hgPageination.Page{}

	pageHelper.BaseUrl = "/post/item/?postId=" + strconv.FormatInt(postId, 10) + "&page="
	pageHelper.Count = count
	pageHelper.PageSize = pageSize
	pageHelper.PageNum = page
	pageHelper.Compute()

	tmpl := template.New("post-itemView")
	tmpl.Funcs(template.FuncMap{"StringEqual": hgTemplate.StringEqual, "Int64Equal": hgTemplate.Int64Equal, "IntEqual": hgTemplate.IntEqual})
	tmpl.ParseFiles(
		"template/front/header.tmpl",
		"template/front/post-item.tmpl",
		"template/front/footer.tmpl",
		"template/front/page.tmpl",
		"template/front/sidebar.tmpl")

	tmplInfo := hgTemplate.TmplInfo{}
	tmplInfo.Js = []string{
		"js/jquery.validate.js"}

	tmplInfo.CurrentNav = "article"

	tmplInfo.Title = "Hello Golang -" + post.Title
	tmplInfo.Description = post.Title

	tmplInfo.AddData("people", people)
	tmplInfo.AddData("post", post)
	tmplInfo.AddData("pageHelper", pageHelper)
	tmplInfo.AddData("postClasses", postClasses)
	tmplInfo.AddData("comments", comments)

	tmpl.ExecuteTemplate(rw, "post-item", map[string]interface{}{"tmplInfo": tmplInfo})
	tmpl.Execute(rw, nil)

	//更新閱讀數
	postModel.UpdateReadNum(*post)
}
開發者ID:xulingjue,項目名稱:hellogolang,代碼行數:64,代碼來源:postHandler.go


注:本文中的hellogolang/HooGL/template.TmplInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。