diff --git a/adormit/adormit.go b/adormit/adormit.go index fd869f3c9a44f8caa16318bed3dcde32ddfa8efb..11eb3e58d7696f14a911fe2d71274a4a7b372f64 100644 --- a/adormit/adormit.go +++ b/adormit/adormit.go @@ -11,6 +11,7 @@ import ( func Version() string { return "0.0.1a4" } + var CurrentTimers []Timer var CurrentAlarms map[string]Alarm @@ -18,18 +19,21 @@ func Init() { CurrentAlarms = make(map[string]Alarm) CurrentTimers = make([]Timer, 0) } + type Alarm struct { - Name string - Early bool - Time time.Time - Active bool - Id string - Uuid uuid.UUID + Name string + Early bool + Time time.Time + Active bool + Id string + Uuid uuid.UUID Creator string } -func (a *Alarm) String () string { - return fmt.Sprintf("%v by %v" , a.Name, a.Creator) + +func (a *Alarm) String() string { + return fmt.Sprintf("%v by %v", a.Name, a.Creator) } + type Timer struct { Name string Start time.Time @@ -63,7 +67,6 @@ func DemoTimer() { t.Countdown() } - func debug(ty interface{}) { fooType := reflect.TypeOf(ty) fmt.Println(fooType) @@ -72,4 +75,3 @@ func debug(ty interface{}) { fmt.Println(method.Name) } } - diff --git a/cmd/http.go b/cmd/http.go index 52d6f5053c289fe20db510e9a2e70fb89be7f907..4a90f29c575b0af3418e82589361d430a86c5eea 100644 --- a/cmd/http.go +++ b/cmd/http.go @@ -2,10 +2,12 @@ package cmd import ( "0xacab.org/jrabbit/adormit/adormit" + "github.com/satori/go.uuid" "github.com/spf13/cobra" "gopkg.in/macaron.v1" "log" "net/http" + "slices" "strconv" "time" ) @@ -47,6 +49,16 @@ func newTimer(req *http.Request) string { } func delTimer(req *http.Request) string { + i := req.FormValue("uuid") + myuuid, _ := uuid.FromString(i) + idxChecker := func(e adormit.Timer) bool { + if e.Uuid == myuuid { + return true + } else { + return false + } + } + slices.DeleteFunc(adormit.CurrentTimers, idxChecker) return "OK" }