A tiny mutex over the network
It might be useful when several distributed components
have to organise access around one shared resource.
Build
go build -o highlander main.go
Example
./highlander 127.0.0.1:9000 10
The first call to "take_lock" will receive the lock name.
$ curl -s http://127.0.0.1:9000/take_lock
hrcBMnQa
Further attempts within the maximum expiry time (given as the
second parameter, here: 10 seconds) will just give "busy".
$ curl -s http://127.0.0.1:9000/take_lock
busy
With the name, the lock can be released earlier.
$ curl -s http://127.0.0.1:9000/release_lock/hrcBMnQa
ok
So a new lock can be taken.
$ curl -s http://127.0.0.1:9000/take_lock
CLQxYaoc
A restart of the server process will also clear the lock,
as everything happens simply in the process memory.