mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
Unlock admin (#240)
* add mutex http endpoints * remove mutex by id * remove mutex by id Co-authored-by: lngohumble <lngohumble@gmail.com>
This commit is contained in:
parent
2ef798e56a
commit
07ccc6cc28
2 changed files with 8 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ package mutex
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
|
|
@ -21,13 +22,14 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func UnlockHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
var i []string
|
||||
for k, m := range mutexMap.Items() {
|
||||
i = append(i, k)
|
||||
vars := mux.Vars(r)
|
||||
if m, ok := mutexMap.Get(vars["id"]); ok {
|
||||
m.(*sync.Mutex).Unlock()
|
||||
w.Write([]byte(fmt.Sprintf("Unlocked %s mutexe.\nCurrent number of locks: %d\nLocks: %+v",
|
||||
vars["id"], len(mutexMap.Keys()), mutexMap.Keys())))
|
||||
return
|
||||
}
|
||||
w.Write([]byte(fmt.Sprintf("Unlocked %d mutexes. \n%+v\nCurrent number of locks: %d\nLocks: %+v",
|
||||
len(i), i, len(mutexMap.Keys()), mutexMap.Keys())))
|
||||
w.Write([]byte(fmt.Sprintf("Mutex %s not found!", vars["id"])))
|
||||
}
|
||||
|
||||
// checkSoftLock checks in mutexMap how often an existing mutex was already SoftLocked.
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -29,7 +29,7 @@ func main() {
|
|||
router := mux.NewRouter()
|
||||
router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
|
||||
router.Handle("/mutex", http.HandlerFunc(mutex.ServeHTTP))
|
||||
router.Handle("/mutex/unlock", http.HandlerFunc(mutex.UnlockHTTP))
|
||||
router.Handle("/mutex/unlock/{id}", http.HandlerFunc(mutex.UnlockHTTP))
|
||||
go http.ListenAndServe("0.0.0.0:6060", router)
|
||||
defer withRecovery()
|
||||
bot := telegram.NewBot()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue