diff options
| author | Horus3 | 2015-02-05 02:55:30 +0100 |
|---|---|---|
| committer | Horus3 | 2015-02-05 02:55:30 +0100 |
| commit | af1f4677c685e8a2c4967ffa0350d314a6543db7 (patch) | |
| tree | 7b749014441c732b75789eec4b93dc885f4a1f8f /app/controllers/url.go | |
| download | webmon-af1f4677c685e8a2c4967ffa0350d314a6543db7.tar.gz | |
Init
Diffstat (limited to 'app/controllers/url.go')
| -rw-r--r-- | app/controllers/url.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/url.go b/app/controllers/url.go new file mode 100644 index 0000000..516f6a6 --- /dev/null +++ b/app/controllers/url.go @@ -0,0 +1,28 @@ +package controllers + +import ( + "crypto/md5" + "fmt" + "io" + "io/ioutil" + "net/http" +) + +func HashUrl(url string) (string, error) { + response, err := http.Get(url) + if err != nil { + return "Get request failed.", err + } + + defer response.Body.Close() + contents, err := ioutil.ReadAll(response.Body) + if er != nil { + return "Reading body failed.", err + } + + h := md5.New() + io.WriteString(h, string(contents)) + hash := fmt.Sprintf("%x", h.Sum(nil)) + + return hash, nil +} |
