diff options
author | Julien Dessaux | 2024-12-30 23:07:00 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-12-30 23:07:00 +0100 |
commit | 36e3d473f2126e920061218996cfa5cfecade7d6 (patch) | |
tree | c77078316db50cd5da7e68ddb3a8cb830ba5c612 /pkg/backend/unlock.go | |
parent | chore(tfstated): refactor setting last login date time on successful HTTP bas... (diff) | |
download | tfstated-36e3d473f2126e920061218996cfa5cfecade7d6.tar.gz tfstated-36e3d473f2126e920061218996cfa5cfecade7d6.tar.bz2 tfstated-36e3d473f2126e920061218996cfa5cfecade7d6.zip |
chore(tfstated): refactor backend code to a dedicated package
Diffstat (limited to 'pkg/backend/unlock.go')
-rw-r--r-- | pkg/backend/unlock.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/backend/unlock.go b/pkg/backend/unlock.go new file mode 100644 index 0000000..bc601f0 --- /dev/null +++ b/pkg/backend/unlock.go @@ -0,0 +1,32 @@ +package backend + +import ( + "fmt" + "net/http" + + "git.adyxax.org/adyxax/tfstated/pkg/database" + "git.adyxax.org/adyxax/tfstated/pkg/helpers" +) + +func handleUnlock(db *database.DB) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" { + _ = helpers.Encode(w, http.StatusBadRequest, + fmt.Errorf("no state path provided, cannot LOCK /")) + return + } + + var lock lockRequest + if err := helpers.Decode(r, &lock); err != nil { + _ = helpers.Encode(w, http.StatusBadRequest, err) + return + } + if success, err := db.Unlock(r.URL.Path, &lock); err != nil { + helpers.ErrorResponse(w, http.StatusInternalServerError, err) + } else if success { + w.WriteHeader(http.StatusOK) + } else { + _ = helpers.Encode(w, http.StatusConflict, lock) + } + }) +} |