// GenerateGlobalSecret generates and records the global secret key. func (r *Redis) GenerateGlobalSecret() error { key, keyErr := util.RandomString(16) if keyErr != nil { return keyErr } setErr := r.client.Set("secret", key, 0).Err() if setErr != nil { return setErr } return nil }
func (s *Server) regHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") uID, uIDErr := util.RandomString(16) if uIDErr != nil { returnError(uIDErr.Error(), http.StatusInternalServerError, w) return } uKey, uKeyErr := util.RandomString(16) if uKeyErr != nil { returnError(uKeyErr.Error(), http.StatusInternalServerError, w) return } respB, respBErr := json.Marshal(RegResp{ UserID: uID, UserKey: uKey, }) if respBErr != nil { returnError(respBErr.Error(), http.StatusInternalServerError, w) return } addErr := s.r.AddUser(uID, uKey) if addErr != nil { returnError(addErr.Error(), http.StatusInternalServerError, w) return } log.Printf("registering new user: %s\n", uID) w.WriteHeader(http.StatusOK) w.Write(respB) }