-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
38 lines (32 loc) · 847 Bytes
/
util.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
package main
import (
"bytes"
"io/ioutil"
"net/http"
"strings"
"text/template"
)
// MakeURL creates a URL out of a template.
func MakeURL(urlTemplate string, data interface{}) (urlString string) {
var urlBuf = new(bytes.Buffer)
var t = template.New("URL template")
t, _ = t.Parse(urlTemplate)
t.Execute(urlBuf, data)
urlString = urlBuf.String()
return urlString
}
// Download retrieves data from the specified HTTP address.
func Download(url string) (data string, err error) {
var resp *http.Response
resp, err = http.Get(url)
if err == nil {
defer resp.Body.Close()
readallContents, _ := ioutil.ReadAll(resp.Body)
data = string(readallContents)
}
return data, err
}
// MakeSlug creates a slug out of specified title.
func MakeSlug(title string) string {
return strings.ToLower(strings.Replace(title, " ", "_", -1))
}