Moge-Row commited on
Commit
19d46ca
·
verified ·
1 Parent(s): 68d3540

Update internal/handler/keys.go

Browse files
Files changed (1) hide show
  1. internal/handler/keys.go +22 -19
internal/handler/keys.go CHANGED
@@ -71,25 +71,28 @@ func GenerateKey(n string) string {
71
  }
72
 
73
  func HandleGenKey(w http.ResponseWriter, r *http.Request) {
74
- n := r.FormValue("name")
75
- if n == "" { n = "User" }
76
- existingKey := r.FormValue("key")
77
- var k string
78
-
79
- if existingKey != "" {
80
- s.mu.Lock()
81
- s.Keys[n+":"+existingKey] = &KeyData{Name: n, Key: existingKey}
82
- save()
83
- s.mu.Unlock()
84
- go BackupKeyToSheet(n, existingKey)
85
- k = existingKey
86
- } else {
87
- k = GenerateKey(n)
88
- }
89
-
90
- w.Header().Set("Content-Type", "application/json")
91
- resp := map[string]string{"key": k, "name": n}
92
- json.NewEncoder(w).Encode(resp)
 
 
 
93
  }
94
 
95
  func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {
 
71
  }
72
 
73
  func HandleGenKey(w http.ResponseWriter, r *http.Request) {
74
+ n := r.FormValue("name")
75
+ if n == "" { n = "User" }
76
+ existingKey := r.FormValue("key")
77
+ var k string
78
+
79
+ if existingKey != "" {
80
+ s.mu.Lock()
81
+ s.Keys[n+":"+existingKey] = &KeyData{Name: n, Key: existingKey}
82
+ save()
83
+ s.mu.Unlock()
84
+ go func(name, key string) {
85
+ BackupKeyToSheet(name, key)
86
+ }(n, existingKey)
87
+
88
+ k = existingKey
89
+ } else {
90
+ k = GenerateKey(n)
91
+ }
92
+
93
+ w.Header().Set("Content-Type", "application/json")
94
+ resp := map[string]string{"key": k, "name": n}
95
+ json.NewEncoder(w).Encode(resp)
96
  }
97
 
98
  func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {