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


Golang Context.HTML方法代码示例

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


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

示例1: renderInstall

func renderInstall(ctx echo.Context, filename string, data map[string]interface{}) error {
	objLog := getLogger(ctx)

	if data == nil {
		data = make(map[string]interface{})
	}

	filename = config.TemplateDir + filename

	requestURI := ctx.Request().URI()
	tpl, err := template.ParseFiles(filename)
	if err != nil {
		objLog.Errorf("解析模板出错(ParseFiles):[%q] %s\n", requestURI, err)
		return err
	}

	buf := new(bytes.Buffer)
	err = tpl.Execute(buf, data)
	if err != nil {
		objLog.Errorf("执行模板出错(Execute):[%q] %s\n", requestURI, err)
		return err
	}

	return ctx.HTML(http.StatusOK, buf.String())
}
开发者ID:studygolang,项目名称:studygolang,代码行数:25,代码来源:install.go

示例2: RenderQuery

// 后台 query 查询返回结果
func RenderQuery(ctx echo.Context, contentTpl string, data map[string]interface{}) error {
	objLog := logic.GetLogger(ctx)

	contentTpl = "common_query.html," + contentTpl
	contentTpls := strings.Split(contentTpl, ",")
	for i, contentTpl := range contentTpls {
		contentTpls[i] = config.TemplateDir + "admin/" + strings.TrimSpace(contentTpl)
	}

	requestURI := Request(ctx).RequestURI
	tpl, err := template.New("common_query.html").Funcs(funcMap).ParseFiles(contentTpls...)
	if err != nil {
		objLog.Errorf("解析模板出错(ParseFiles):[%q] %s\n", requestURI, err)
		return err
	}

	buf := new(bytes.Buffer)
	err = tpl.Execute(buf, data)
	if err != nil {
		objLog.Errorf("执行模板出错(Execute):[%q] %s\n", requestURI, err)
		return err
	}

	return ctx.HTML(http.StatusOK, buf.String())
}
开发者ID:studygolang,项目名称:studygolang,代码行数:26,代码来源:http.go

示例3: upload

func upload(c echo.Context) error {
	// Read form fields
	name := c.FormValue("name")
	email := c.FormValue("email")

	//-----------
	// Read file
	//-----------

	// Source
	file, err := c.FormFile("file")
	if err != nil {
		return err
	}
	src, err := file.Open()
	if err != nil {
		return err
	}
	defer src.Close()

	// Destination
	dst, err := os.Create(file.Filename)
	if err != nil {
		return err
	}
	defer dst.Close()

	// Copy
	if _, err = io.Copy(dst, src); err != nil {
		return err
	}

	return c.HTML(http.StatusOK, fmt.Sprintf("<p>File %s uploaded successfully with fields name=%s and email=%s.</p>", file.Filename, name, email))
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:34,代码来源:server.go

示例4: hello

// Handler
func hello(c *echo.Context) error {
	var text, temp string

	posts := data.GetPostList(con, 0, 10)

	for _, post := range posts {
		temp = fmt.Sprintf("%v", post)
		text = text + "<br />" + temp
	}

	return c.HTML(http.StatusOK, "<html><body><h1>Blog posts:</h1>"+text+"</body></html>")
}
开发者ID:resetreboot,项目名称:echo_test,代码行数:13,代码来源:server.go

示例5: ArticleList

// ArticleList 所有文章(分页)
func (ArticleController) ArticleList(ctx echo.Context) error {
	curPage, limit := parsePage(ctx)
	articles, total := logic.DefaultArticle.FindArticleByPage(ctx, nil, curPage, limit)

	if articles == nil {
		return ctx.HTML(http.StatusInternalServerError, "500")
	}

	data := map[string]interface{}{
		"datalist":   articles,
		"total":      total,
		"totalPages": (total + limit - 1) / limit,
		"page":       curPage,
		"limit":      limit,
	}

	return render(ctx, "article/list.html,article/query.html", data)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:19,代码来源:article.go

示例6: requestAddRsvp

func requestAddRsvp(c echo.Context) error {
	name := c.Form("name")
	email := c.Form("email")
	res := c.Form("response")
	if name == "" || email == "" {
		c.String(http.StatusBadRequest, "Name and Email must be given. Please go back and try again.")
		return nil
	}

	rsvp := Rsvp{0, name, email, res, time.Now()}
	if err := addRsvp(rsvp); err != nil {
		c.String(http.StatusInternalServerError,
			"Failed to add RSVP at this time. Please try again later")
	}

	c.HTML(http.StatusOK, saveSuccess)
	return nil
}
开发者ID:zacheryph,项目名称:gocode,代码行数:18,代码来源:server.go

示例7: ReadingList

// ReadingList 所有晨读(分页)
func (ReadingController) ReadingList(ctx echo.Context) error {
	curPage, limit := parsePage(ctx)

	readings, total := logic.DefaultReading.FindReadingByPage(ctx, nil, curPage, limit)
	if readings == nil {
		return ctx.HTML(http.StatusInternalServerError, "500")
	}

	data := map[string]interface{}{
		"datalist":   readings,
		"total":      total,
		"totalPages": (total + limit - 1) / limit,
		"page":       curPage,
		"limit":      limit,
	}

	return render(ctx, "reading/list.html,reading/query.html", data)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:19,代码来源:reading.go

示例8: Query

// Query
func (RuleController) Query(ctx echo.Context) error {
	curPage, limit := parsePage(ctx)
	conds := parseConds(ctx, []string{"domain"})

	rules, total := logic.DefaultRule.FindBy(ctx, conds, curPage, limit)

	if rules == nil {
		return ctx.HTML(http.StatusInternalServerError, "500")
	}

	data := map[string]interface{}{
		"datalist":   rules,
		"total":      total,
		"totalPages": (total + limit - 1) / limit,
		"page":       curPage,
		"limit":      limit,
	}
	return render(ctx, "rule/query.html", data)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:20,代码来源:rule.go

示例9: ProjectQuery

// ProjectQuery
func (ProjectController) ProjectQuery(ctx echo.Context) error {
	curPage, limit := parsePage(ctx)
	conds := parseConds(ctx, []string{"id", "domain", "title"})

	articles, total := logic.DefaultArticle.FindArticleByPage(ctx, conds, curPage, limit)

	if articles == nil {
		return ctx.HTML(http.StatusInternalServerError, "500")
	}

	data := map[string]interface{}{
		"datalist":   articles,
		"total":      total,
		"totalPages": (total + limit - 1) / limit,
		"page":       curPage,
		"limit":      limit,
	}

	return renderQuery(ctx, "article/query.html", data)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:21,代码来源:project.go

示例10: executeTpl

func executeTpl(ctx echo.Context, tpl *template.Template, data map[string]interface{}) error {
	objLog := logic.GetLogger(ctx)

	// 如果没有定义css和js模板,则定义之
	if jsTpl := tpl.Lookup("js"); jsTpl == nil {
		tpl.Parse(`{{define "js"}}{{end}}`)
	}
	if jsTpl := tpl.Lookup("css"); jsTpl == nil {
		tpl.Parse(`{{define "css"}}{{end}}`)
	}

	// 当前用户信息
	curUser, ok := ctx.Get("user").(*model.Me)
	if ok {
		data["me"] = curUser
	} else {
		data["me"] = map[string]interface{}{}
	}

	// websocket主机
	if global.OnlineEnv() {
		data["wshost"] = config.ConfigFile.MustValue("global", "domain")
	} else {
		data["wshost"] = global.App.Host + ":" + global.App.Port
	}
	global.App.SetUptime()
	data["app"] = global.App

	data["online_users"] = map[string]int{"online": logic.Book.Len(), "maxonline": logic.MaxOnlineNum()}

	buf := new(bytes.Buffer)
	err := tpl.Execute(buf, data)
	if err != nil {
		objLog.Errorln("excute template error:", err)
		return err
	}

	return ctx.HTML(http.StatusOK, buf.String())
}
开发者ID:studygolang,项目名称:studygolang,代码行数:39,代码来源:http.go

示例11: request

func request(c echo.Context) error {
	req := c.Request().(*standard.Request).Request
	format := "<pre><strong>Request Information</strong>\n\n<code>Protocol: %s\nHost: %s\nRemote Address: %s\nMethod: %s\nPath: %s\n</code></pre>"
	return c.HTML(http.StatusOK, fmt.Sprintf(format, req.Proto, req.Host, req.RemoteAddr, req.Method, req.URL.Path))
}
开发者ID:AlekSi,项目名称:echo,代码行数:5,代码来源:server.go

示例12: Change


//.........这里部分代码省略.........
	if err != nil {
		return err
	}
	log.Println("Received changes", changes)
	domain := c.Get("domain").(Domain)

	// serialize map file rewrites
	rewrite_lock.Lock()
	defer func() {
		rewrite_lock.Unlock()
	}()
	// find all existing local addresses, but exclude command delivery
	a := readMapFile(domain.MapFile, nil)
	local := make(map[string]bool)
	for i := 0; i < len(a); i++ {
		if strings.Contains(a[i].Email, "@"+domain.Name) && !strings.ContainsAny(a[i].Target, "@|") {
			local[a[i].Target] = true
		}
	}
	// dedupe and normalize changes
	remap := make(map[string]string)
	for _, change := range changes {
		address, err := mail.ParseAddress(change.Alias)
		if err != nil || !strings.HasSuffix(address.Address, "@"+domain.Name) {
			log.Println("invalid alias:", change.Alias)
			return c.Render(http.StatusBadRequest, "error", struct {
				Error string
			}{"invalid alias: " + change.Alias})
		}
		switch change.Op {
		case "remove":
			remap[address.Address] = ""
		case "add":
			if validate(change.Target, local) {
				remap[address.Address] = change.Target
			} else {
				return c.Render(http.StatusBadRequest, "error", struct {
					Error string
				}{"invalid email address list for " + address.Address + ": " + change.Target})
			}
		default:
			log.Fatal("unexpected change request: ", change)
		}
	}
	// rewrite the map file atomically
	tmp_file := domain.MapFile + ".web.new"
	f, err := os.OpenFile(tmp_file, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		log.Fatal("could not rewrite map file ", tmp_file, " due to ", err)
	}
	fw := bufio.NewWriter(f)
	readMapFile(domain.MapFile, func(line string, email string) {
		if email == "" {
			fw.WriteString(line + "\n")
		} else {
			dest, ok := remap[email]
			if ok {
				if dest != "" {
					new_line(fw, email, dest)
					// remove any further references
					remap[email] = ""
				}
			} else {
				fw.WriteString(line + "\n")
			}
		}
	})
	for email, dest := range remap {
		if dest != "" {
			new_line(fw, email, dest)
		}
	}
	fw.Flush()
	f.Close()
	err = os.Rename(domain.MapFile, domain.MapFile+".old")
	if err != nil {
		return err
	}
	err = os.Rename(tmp_file, domain.MapFile)
	if err != nil {
		os.Rename(domain.MapFile+".old", domain.MapFile)
		return err
	}
	cmd := exec.Command("postmap", domain.MapFile)
	err = cmd.Run()
	if err != nil {
		os.Rename(domain.MapFile+".old", domain.MapFile)
		return err
	}
	cmd = exec.Command("postfix", "reload")
	err = cmd.Run()
	if err != nil {
		log.Println("postfix reload failed:", err)
	}

	// HTTP 303 is specifically for POST/Redirect/GET
	// see: https://en.wikipedia.org/wiki/Post/Redirect/Get
	c.Response().Header().Set("Location", "/")
	return c.HTML(303, "<script>document.location.href = \"/\";</script>")
}
开发者ID:fazalmajid,项目名称:postmapweb,代码行数:101,代码来源:postmapweb.go

示例13: htmlSqliteFile

// path /set/sqlitefile/:DeviceID
// example /set/sqlitefile/18333
func htmlSqliteFile(c *echo.Context) error {
	return c.HTML(http.StatusOK, fmt.Sprintf(g_html_str, c.Param("DeviceID")))
}
开发者ID:trandt01,项目名称:acs560_course_project,代码行数:5,代码来源:method.go


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