-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplater.go
51 lines (39 loc) · 952 Bytes
/
templater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"bytes"
"html/template"
"io/ioutil"
)
func embedImage(id string, username string, filename string) ([]byte, error) {
//open templates/embed.html
file, err := ioutil.ReadFile("templates/embed.html")
//println(string(file))
tmpl, err := template.New("template").Parse(string(file))
if err != nil {
//println(err.Error())
return nil, err
}
var config, _ = readConfigFile()
var URL = config["URL"].(string)
data := map[string]interface{}{
"id": id,
"username": username,
"filename": filename,
"URL": URL,
}
var buf bytes.Buffer
err = tmpl.Execute(&buf, data)
if err != nil {
//println(err.Error())
return nil, err
}
//println(buf.String())
return buf.Bytes(), nil
}
func renderIndexHTML() []byte {
file, _ := ioutil.ReadFile("templates/index.html")
tmpl, _ := template.New("template").Parse(string(file))
var buf bytes.Buffer
tmpl.Execute(&buf, nil)
return buf.Bytes()
}