Browse Source

set longer expiry on redis keys, and more useful id and key lengths

master
Craig Stewart 3 months ago
parent
commit
f0445ee4dd
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      location-finder.go

+ 6
- 6
location-finder.go View File

@@ -136,13 +136,13 @@ func api_location(w http.ResponseWriter, r *http.Request){
func api_createid(w http.ResponseWriter, r *http.Request){
switch r.Method {
case "GET":
id, id_err := genrandomstring(4)
id, id_err := genrandomstring(10)
if id_err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(http.StatusText(http.StatusInternalServerError) + "\n"))
return
}
key, key_err := genrandomstring(10)
key, key_err := genrandomstring(32)
if key_err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(http.StatusText(http.StatusInternalServerError) + "\n"))
@@ -159,7 +159,7 @@ func api_createid(w http.ResponseWriter, r *http.Request){
w.Write([]byte(http.StatusText(http.StatusInternalServerError) + "\n"))
return
}
writekey_err := client.Set("key-" + id, key, 30 * time.Second).Err()
writekey_err := client.Set("key-" + id, key, 30 * time.Minute).Err()
if writekey_err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(http.StatusText(http.StatusInternalServerError) + "\n"))
@@ -181,11 +181,11 @@ func api_createid(w http.ResponseWriter, r *http.Request){
}

func check_item_key(id string, key string) bool {
id_safe, _ := regexp.MatchString(`^[a-zA-Z0-9]{0,10}$`, id)
id_safe, _ := regexp.MatchString(`^[a-zA-Z0-9]{10}$`, id)
if id_safe != true {
return false
}
key_safe, _ := regexp.MatchString(`^[a-zA-Z0-9]{0,10}$`, key)
key_safe, _ := regexp.MatchString(`^[a-zA-Z0-9]{32}$`, key)
if key_safe != true {
return false
}
@@ -210,7 +210,7 @@ func write_key(id string, item float64) bool {
Password: "", // no password set
DB: 0, // use default DB
})
err := client.Set(id, item, 30 * time.Second).Err()
err := client.Set(id, item, 30 * time.Minute).Err()
if err != nil {
return false
}

Loading…
Cancel
Save