Commit 631aea93 authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

A more random randomId

parent 0f267d2a
......@@ -13,6 +13,7 @@ import (
"net/http"
"os"
"regexp"
"time"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
......@@ -150,7 +151,7 @@ func (s *server) uploadImage(w http.ResponseWriter, r *http.Request) {
http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest)
return
}
uid := randID(12)
uid := randID(6)
fileEndings, err := mime.ExtensionsByType(filetype)
if err != nil {
http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest)
......@@ -224,9 +225,10 @@ func (s *server) deleteImage(w http.ResponseWriter, r *http.Request) {
}
func randID(l int) string {
t := time.Now().UTC().UnixNano()
b := make([]byte, l)
rand.Read(b)
return fmt.Sprintf("%x", b)
return fmt.Sprintf("%d%x", t, b)
}
func isValidBucketName(b string) error {
......@@ -243,6 +245,7 @@ func main() {
listen = flag.String("l", ":1666", "server listeing address")
)
flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
m, err := minio.New(*minioURL, os.Getenv("MINIO_ACCESS_KEY"), os.Getenv("MINIO_SECRET_KEY"), *minioSsl)
if err != nil {
log.Fatal(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment