render

command module
v0.0.0-...-ac3dbcd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

render

自制微型模板渲染工具,一次性解析所有的模板,提高访问性能,并简化Web页面的开发。

package main

import (
	"fmt"
	"github.com/xieyicai/render/render"
	"log"
	"net/http"
	"time"
)

func main() {
	fileHandler := http.FileServer(http.Dir("static"))
	http.Handle("/static/", http.StripPrefix("/static/", fileHandler)) // 启动静态文件服务
	http.HandleFunc("/", func(writer http.ResponseWriter, req *http.Request) {
		if req.URL.Path=="/favicon.ico" {
			fileHandler.ServeHTTP(writer, req)
		}else{
			render.Out(writer, req, nil)
		}
	})
	render.DefaultData = struct {
		Title string
	}{
		Title: "Untitled Document",
	}
	render.SetData("/index.html", &struct {
		Title string
	}{
		Title: "品牌街-上天猫,就够了",
	})
	render.SetData("/test2.html", func() interface{} {
		map1 := make(map[string]string)
		map1["Title"]=fmt.Sprintf("当前时间是:%s", time.Now().Format("2006-01-02 15:04:05"))
		return &map1
	})
	defer render.TurnOff()
	render.TurnOn()
	log.Println("http://localhost:8080/")
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL