|
@@ -5,15 +5,18 @@ import (
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"math"
|
|
|
+ "sync"
|
|
|
)
|
|
|
|
|
|
type Context struct {
|
|
|
- Id int64
|
|
|
- seq uint16
|
|
|
- ctx context.Context
|
|
|
- wc io.WriteCloser
|
|
|
- params map[string]string
|
|
|
- args []string
|
|
|
+ Id int64
|
|
|
+ seq uint16
|
|
|
+ ctx context.Context
|
|
|
+ wc io.WriteCloser
|
|
|
+ params map[string]string
|
|
|
+ locker sync.RWMutex
|
|
|
+ variables map[string]any
|
|
|
+ args []string
|
|
|
}
|
|
|
|
|
|
func (ctx *Context) reset(id int64, wc io.WriteCloser) {
|
|
@@ -23,6 +26,7 @@ func (ctx *Context) reset(id int64, wc io.WriteCloser) {
|
|
|
ctx.ctx = context.Background()
|
|
|
ctx.args = make([]string, 0)
|
|
|
ctx.params = make(map[string]string)
|
|
|
+ ctx.variables = make(map[string]any)
|
|
|
}
|
|
|
|
|
|
func (ctx *Context) setArgs(args []string) {
|
|
@@ -42,7 +46,7 @@ func (ctx *Context) setContext(c context.Context) {
|
|
|
}
|
|
|
|
|
|
func (ctx *Context) Context() context.Context {
|
|
|
- return ctx.Context()
|
|
|
+ return ctx.ctx
|
|
|
}
|
|
|
|
|
|
func (ctx *Context) Argument(index int) string {
|
|
@@ -59,6 +63,22 @@ func (ctx *Context) Param(s string) string {
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
+func (ctx *Context) SetValue(name string, value any) {
|
|
|
+ ctx.locker.Lock()
|
|
|
+ if ctx.variables == nil {
|
|
|
+ ctx.variables = make(map[string]any)
|
|
|
+ }
|
|
|
+ ctx.variables[name] = value
|
|
|
+ ctx.locker.Unlock()
|
|
|
+}
|
|
|
+
|
|
|
+func (ctx *Context) GetValue(name string) (val any, ok bool) {
|
|
|
+ ctx.locker.RLock()
|
|
|
+ defer ctx.locker.RUnlock()
|
|
|
+ val, ok = ctx.variables[name]
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func (ctx *Context) Success(v any) (err error) {
|
|
|
return ctx.send(responsePayload{Type: PacketTypeCommand, Data: v})
|
|
|
}
|