-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21f1eee
commit 29cdd93
Showing
2 changed files
with
15 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,30 @@ | ||
package imgcache | ||
|
||
import ( | ||
"bytes" | ||
"crypto/md5" | ||
"encoding/hex" | ||
"io" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func strToMD5(str string) string { | ||
md5Hasher := md5.New() | ||
md5Hasher.Write([]byte(str)) | ||
return hex.EncodeToString(md5Hasher.Sum(nil)) | ||
} | ||
|
||
func indexOfString(str string, slice []string) int { | ||
|
||
for i, v := range slice { | ||
if str == v { | ||
return i | ||
} | ||
} | ||
|
||
return -1 | ||
} | ||
|
||
func removeStringFromSlice(str string, slice []string) []string { | ||
|
||
var i = indexOfString(str, slice) | ||
|
||
if i != -1 { | ||
slice = append(slice[:i], slice[i+1:]...) | ||
} | ||
|
||
return slice | ||
} | ||
|
||
// createIndexFromUrl will calculate the URLs md5 and will pick then only the digits within the string too create a key | ||
func createKeyFromUrl(url string) (string) { | ||
// Berechne den MD5-Hash der URL | ||
hasher := md5.New() | ||
io.WriteString(hasher, url) | ||
return hex.EncodeToString(hasher.Sum(nil)) | ||
} | ||
|
||
// Faster creation of file names | ||
func createFileNameFromURL(url string, key string) (string) { | ||
url_stripped := strings.Split(url, "?")[0] | ||
ext := filepath.Ext(url_stripped) | ||
|
||
var buf bytes.Buffer | ||
buf.WriteString(key) | ||
buf.WriteString(ext) | ||
|
||
return buf.String() | ||
} |