pkg/api: Check errors (#19657)

* pkg/api: Check errors
* pkg/api: Remove unused function HashEmail
This commit is contained in:
Arve Knudsen
2019-10-08 18:57:53 +02:00
committed by GitHub
parent dabc848e11
commit 0a2d5e16dd
12 changed files with 86 additions and 45 deletions
+3 -15
View File
@@ -9,8 +9,6 @@ package avatar
import (
"bufio"
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
@@ -43,18 +41,6 @@ func UpdateGravatarSource() {
}
}
// hash email to md5 string
// keep this func in order to make this package independent
func HashEmail(email string) string {
// https://en.gravatar.com/site/implement/hash/
email = strings.TrimSpace(email)
email = strings.ToLower(email)
h := md5.New()
h.Write([]byte(email))
return hex.EncodeToString(h.Sum(nil))
}
// Avatar represents the avatar object.
type Avatar struct {
hash string
@@ -119,7 +105,9 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
if avatar.notFound {
avatar = this.notFound
} else {
this.cache.Add(hash, avatar, gocache.DefaultExpiration)
if err := this.cache.Add(hash, avatar, gocache.DefaultExpiration); err != nil {
log.Warn("Error adding avatar to cache: %s", err)
}
}
ctx.Resp.Header().Add("Content-Type", "image/jpeg")