示例#1
0
// Render parses and executes a template, returning the results in string format.
func Render(template string, payload interface{}) (s string, err error) {
	u, err := url.Parse(template)
	if err == nil {
		switch u.Scheme {
		case "http", "https":
			res, err := http.Get(template)
			if err != nil {
				return s, err
			}
			defer res.Body.Close()
			out, err := ioutil.ReadAll(res.Body)
			if err != nil {
				return s, err
			}
			template = string(out)

		case "file":
			out, err := ioutil.ReadFile(u.Path)
			if err != nil {
				return s, err
			}
			template = string(out)
		}
	}

	return raymond.Render(template, payload)
}
示例#2
0
func Render(raw string, item map[string]interface{}) string {
	res, err := raymond.Render(raw, item)
	if err != nil {
		log.Fatal(err)
	}
	return res
}
示例#3
0
文件: template.go 项目: curx/drone-go
// Render parses and executes a template, returning the results
// in string format.
func Render(template string, playload *drone.Payload) (string, error) {
	return raymond.Render(template, normalize(playload))
}