Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e191e0904 | |||
990670fdfd | |||
12538decee |
38
data.go
38
data.go
@ -2,6 +2,7 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (obj *PluginObject) Get(k string) any {
|
func (obj *PluginObject) Get(k string) any {
|
||||||
@ -16,6 +17,33 @@ func (obj *PluginObject) Set(k string, v any) {
|
|||||||
obj.taskData[k] = v
|
obj.taskData[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (obj *PluginObject) GetAll(prefix *string) any {
|
||||||
|
obj.taskDataLock.RLock()
|
||||||
|
defer obj.taskDataLock.RUnlock()
|
||||||
|
if prefix == nil {
|
||||||
|
return obj.taskData
|
||||||
|
}
|
||||||
|
m := make(map[string]any)
|
||||||
|
for k := range obj.taskData {
|
||||||
|
if strings.HasPrefix(k, *prefix) {
|
||||||
|
m[k] = obj.taskData[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *PluginObject) Keys(prefix *string) []string {
|
||||||
|
obj.taskDataLock.Lock()
|
||||||
|
defer obj.taskDataLock.Unlock()
|
||||||
|
keys := make([]string, 0)
|
||||||
|
for k := range obj.taskData {
|
||||||
|
if prefix == nil || strings.HasPrefix(k, *prefix) {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
func (obj *PluginObject) GetSet(k string, fn func(old any) any) {
|
func (obj *PluginObject) GetSet(k string, fn func(old any) any) {
|
||||||
obj.taskDataLock.Lock()
|
obj.taskDataLock.Lock()
|
||||||
defer obj.taskDataLock.Unlock()
|
defer obj.taskDataLock.Unlock()
|
||||||
@ -28,6 +56,16 @@ func (obj *PluginObject) Remove(k string) {
|
|||||||
delete(obj.taskData, k)
|
delete(obj.taskData, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (obj *PluginObject) RemoveAll(prefix *string) {
|
||||||
|
obj.taskDataLock.Lock()
|
||||||
|
defer obj.taskDataLock.Unlock()
|
||||||
|
for k := range obj.taskData {
|
||||||
|
if prefix == nil || strings.HasPrefix(k, *prefix) {
|
||||||
|
delete(obj.taskData, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (obj *PluginObject) Push(k string, v any) {
|
func (obj *PluginObject) Push(k string, v any) {
|
||||||
obj.taskListLock.Lock()
|
obj.taskListLock.Lock()
|
||||||
defer obj.taskListLock.Unlock()
|
defer obj.taskListLock.Unlock()
|
||||||
|
10
go.mod
10
go.mod
@ -1,13 +1,13 @@
|
|||||||
module apigo.cc/gojs/task
|
module apigo.cc/gojs/task
|
||||||
|
|
||||||
go 1.23.0
|
go 1.24
|
||||||
|
|
||||||
require (
|
require (
|
||||||
apigo.cc/gojs v0.0.23
|
apigo.cc/gojs v0.0.25
|
||||||
apigo.cc/gojs/console v0.0.2
|
apigo.cc/gojs/console v0.0.2
|
||||||
apigo.cc/gojs/file v0.0.4
|
apigo.cc/gojs/file v0.0.5
|
||||||
apigo.cc/gojs/runtime v0.0.3
|
apigo.cc/gojs/runtime v0.0.3
|
||||||
apigo.cc/gojs/util v0.0.12
|
apigo.cc/gojs/util v0.0.13
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/ssgo/config v1.7.9
|
github.com/ssgo/config v1.7.9
|
||||||
github.com/ssgo/u v1.7.21
|
github.com/ssgo/u v1.7.21
|
||||||
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
|
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/obscuren/ecies v0.0.0-20150213224233-7c0f4a9b18d9 // indirect
|
github.com/obscuren/ecies v0.0.0-20150213224233-7c0f4a9b18d9 // indirect
|
||||||
github.com/ssgo/log v1.7.7 // indirect
|
github.com/ssgo/log v1.7.9 // indirect
|
||||||
github.com/ssgo/standard v1.7.7 // indirect
|
github.com/ssgo/standard v1.7.7 // indirect
|
||||||
github.com/ssgo/tool v0.4.29 // indirect
|
github.com/ssgo/tool v0.4.29 // indirect
|
||||||
golang.org/x/crypto v0.40.0 // indirect
|
golang.org/x/crypto v0.40.0 // indirect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user