Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sethvargo/go-gcslock
A Go library for acquiring a forward-looking lock in Google Cloud Storage.
https://github.com/sethvargo/go-gcslock
google-cloud google-cloud-storage
Last synced: 3 months ago
JSON representation
A Go library for acquiring a forward-looking lock in Google Cloud Storage.
- Host: GitHub
- URL: https://github.com/sethvargo/go-gcslock
- Owner: sethvargo
- License: apache-2.0
- Created: 2023-03-15T21:29:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-19T15:53:15.000Z (10 months ago)
- Last Synced: 2024-10-04T15:46:31.084Z (4 months ago)
- Topics: google-cloud, google-cloud-storage
- Language: Go
- Homepage:
- Size: 131 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
[![GoDoc](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godoc]
# go-gcslock
GCS Lock creates a forward-looking lock using Google Cloud Storage. The lock is
forward-looking because it is not actually "held" like a mutex. This is useful
in situations where you want something to occur at most once over a duration,
but multiple independent processes could trigger the event."Identity" is tied to the object itself; different locks should use different
object names.## Usage
```go
lock, err := gcslock.New(ctx, "my-bucket", "my-object")
if err != nil {
panic(err) // TODO: handle error
}
defer lock.Close(ctx)// Acquire the lock for 30 minutes. Upon successful return from this method,
// the lock is held.
if err := lock.Acquire(ctx, 30*time.Minute); err != nil {
var lockErr *ErrLockHeld
if errors.As(err, &lockErr) {
// Lock is already held
log.Printf("lock is held until %s", lockErr.NotBefore())
}panic(err) // TODO: handle error
}
```[godoc]: https://pkg.go.dev/github.com/sethvargo/go-gcslock