summaryrefslogtreecommitdiff
path: root/app/controllers/utilities.go
diff options
context:
space:
mode:
authorHorus_Arch2015-03-02 15:31:39 +0100
committerHorus_Arch2015-03-02 15:31:39 +0100
commite31b06b7b56aaf1cf5510d4bb0261f73bc0e8893 (patch)
tree0651cdd688659b845f3605e09384161b3c0334db /app/controllers/utilities.go
parentcf66deeeba38263feef0ca4123a983cb78ce5cac (diff)
downloadwebmon-master.tar.gz
Migrating from revel.HEADmaster
Diffstat (limited to 'app/controllers/utilities.go')
-rw-r--r--app/controllers/utilities.go94
1 files changed, 0 insertions, 94 deletions
diff --git a/app/controllers/utilities.go b/app/controllers/utilities.go
deleted file mode 100644
index 1aa5d6d..0000000
--- a/app/controllers/utilities.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package controllers
-
-import (
- "crypto/md5"
- "fmt"
- "github.com/garyburd/redigo/redis"
- "github.com/revel/revel"
- "golang.org/x/crypto/bcrypt"
- "io"
- "io/ioutil"
- "math/rand"
- "net/http"
- "time"
-)
-
-// Returns the content of a webpage as string
-func Get(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 err != nil {
- return "Reading body failed.", err
- }
-
- return 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, error) {
- err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
- if err != nil {
- return false, err
- }
- return true, nil
-}