renew_handler.go 757 B

123456789101112131415161718192021222324252627282930
  1. package v2
  2. import (
  3. "path"
  4. "net/http"
  5. "strconv"
  6. "github.com/gorilla/mux"
  7. )
  8. // renewLockHandler attempts to update the TTL on an existing lock.
  9. // Returns a 200 OK if successful. Returns non-200 on error.
  10. func (h *handler) renewLockHandler(w http.ResponseWriter, req *http.Request) {
  11. h.client.SyncCluster()
  12. vars := mux.Vars(req)
  13. keypath := path.Join(prefix, vars["key_with_index"])
  14. ttl, err := strconv.Atoi(req.FormValue("ttl"))
  15. if err != nil {
  16. http.Error(w, "invalid ttl: " + err.Error(), http.StatusInternalServerError)
  17. return
  18. }
  19. // Renew the lock, if it exists.
  20. _, err = h.client.Update(keypath, "-", uint64(ttl))
  21. if err != nil {
  22. http.Error(w, "renew lock index error: " + err.Error(), http.StatusInternalServerError)
  23. return
  24. }
  25. }