package seq import ( "fmt" "reflect" ) type Context struct { vars map[string]interface{} params []interface{} ret [][]interface{} rep []string } func NewContext() *Context { return &Context{ vars: map[string]interface{}{}, ret: [][]interface{}{}, rep: []string{}, } } func (sc *Context) Log(param ...interface{}) { sc.rep = append(sc.rep, fmt.Sprint(param...)) } func (sc *Context) LogRep() { log.Println("Report:") for _, r := range sc.rep { log.Println(r) } } // Context func (sc *Context) Set(name string, value interface{}) { sc.vars[name] = value } func (sc *Context) Get(name string, valPtr ...interface{}) interface{} { if len(valPtr) > 0 { pv := reflect.ValueOf(valPtr[0]) pv.Elem().Set(reflect.ValueOf(sc.vars[name])) } return sc.vars[name] } func (sc *Context) Param(n uint, valPtr ...interface{}) interface{} { if n > uint(len(sc.params)) { return nil } if len(valPtr) > 0 { pv := reflect.ValueOf(valPtr[0]) pv.Elem().Set(reflect.ValueOf(sc.params[n])) } return sc.params[n] } //Ret return the value from previous returns func (sc *Context) Ret(n, i int) interface{} { return sc.ret[n][i] }