summaryrefslogtreecommitdiff
path: root/utilities.go
diff options
context:
space:
mode:
authorHorus32015-02-19 02:38:34 +0100
committerHorus32015-02-19 02:38:34 +0100
commitf53fa2f2f9eb445527e0a1b29b9e37c224499233 (patch)
tree229cc07cb4713a01393d4775f98ec733baa2afe7 /utilities.go
parent58e63343703e0c3f3c12934e62fc0f4575761869 (diff)
downloadstatuspage-f53fa2f2f9eb445527e0a1b29b9e37c224499233.tar.gz
Reorder files and parses templates.
Diffstat (limited to 'utilities.go')
-rw-r--r--utilities.go96
1 files changed, 0 insertions, 96 deletions
diff --git a/utilities.go b/utilities.go
deleted file mode 100644
index 75f153f..0000000
--- a/utilities.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package main
-
-import (
- "crypto/md5"
- "fmt"
- // "github.com/garyburd/redigo/redis"
- "golang.org/x/crypto/bcrypt"
- "io"
- "io/ioutil"
- "math/rand"
- "net/http"
- // "time"
-)
-
-// Returns headers as map and the content of a webpage as string
-func HttpGet(url string) (http.Header, string, error) {
- response, err := http.Get(url)
- if err != nil {
- return nil, "Get request failed.", err
- }
-
- defer response.Body.Close()
- contents, err := ioutil.ReadAll(response.Body)
- if err != nil {
- return nil, "Reading body failed.", err
- }
-
- return response.Header, string(contents), nil
-}
-
-// Hashs and returns a string (md5)
-func Hash(content string) string {
- h := md5.New()
- io.WriteString(h, content)
- hash := fmt.Sprintf("%x", h.Sum(nil))
-
- return hash
-}
-
-// Creates a random string
-func RandomKey() string {
- letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
- key := make([]rune, 40)
- for i := range key {
- key[i] = letters[rand.Intn(len(letters))]
- }
-
- return string(key)
-}
-
-//var pool = newPool()
-
-/*
-// Creates a pool with connections to Redis
-func newPool() *redis.Pool {
- return &redis.Pool{
- MaxIdle: 3,
- IdleTimeout: 240 * time.Second,
- Dial: func() (redis.Conn, error) {
- //c, err := redis.Dial("tcp", ":6379")
- c, err := redis.Dial("tcp", revel.Config.StringDefault("redis.server", "127.0.0.1")+":"+revel.Config.StringDefault("redis.port", "6379"))
- if err != nil {
- return nil, err
- }
- return c, err
- },
- TestOnBorrow: func(c redis.Conn, t time.Time) error {
- _, err := c.Do("PING")
- return err
- },
- }
-}
-*/
-
-// Hashs password with bcrypt and returns the string
-func HashPassword(password string) (string, error) {
- if password == "" {
- return "", nil
- }
- p := []byte(password)
- hash, err := bcrypt.GenerateFromPassword(p, 10)
- if err != nil {
- return "", err
- }
- return string(hash), nil
-}
-
-// Verify password and hash
-func VerifyPassword(password, hash string) bool {
- err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
- if err != nil {
- revel.ERROR.Printf("%s \n", err)
- return false
- }
- return true
-}