|
@@ -24,12 +24,26 @@ type Context struct {
|
|
|
response *Response
|
|
|
}
|
|
|
|
|
|
+//HasArgument 是否有指定的参数
|
|
|
+func (ctx *Context) HasArgument(i int) bool {
|
|
|
+ return len(ctx.Args) > i
|
|
|
+}
|
|
|
+
|
|
|
+//Argument 获取指定参数
|
|
|
+func (ctx *Context) Argument(i int) string {
|
|
|
+ if ctx.HasArgument(i) {
|
|
|
+ return ctx.Args[i]
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
func (ctx *Context) reset(s string) {
|
|
|
ctx.response = &Response{}
|
|
|
ctx.Args = nil
|
|
|
ctx.CmdStr = s
|
|
|
}
|
|
|
|
|
|
+//Get 获取一个session变量
|
|
|
func (ctx *Context) Get(s string) interface{} {
|
|
|
ctx.locker.RLock()
|
|
|
defer ctx.locker.RUnlock()
|
|
@@ -39,6 +53,7 @@ func (ctx *Context) Get(s string) interface{} {
|
|
|
return ctx.Values[s]
|
|
|
}
|
|
|
|
|
|
+//Set 设置一个session变量
|
|
|
func (ctx *Context) Set(key string, value interface{}) {
|
|
|
ctx.locker.Lock()
|
|
|
defer ctx.locker.Unlock()
|
|
@@ -48,6 +63,7 @@ func (ctx *Context) Set(key string, value interface{}) {
|
|
|
ctx.Values[key] = value
|
|
|
}
|
|
|
|
|
|
+//Bind 绑定一个变量
|
|
|
func (ctx *Context) Bind(i interface{}) (err error) {
|
|
|
refVal := reflect.Indirect(reflect.ValueOf(i))
|
|
|
refType := refVal.Type()
|