func main() { in := " fauns sakjdkl sakd " out := util.TrimSpace(in) fmt.Println(out) mydb := db.NewMyDB() mapobj := object.NewMapObj() errs := mapobj.Set(" z , zzz , r, rrr,c,mmm ") if errs != nil { panic(errs) } mydb.SetValue("zrc", mapobj) strobj := object.NewStringObj() strobj.Set("make you feel my love!") mydb.SetValue("qiqi", strobj) listobj := object.NewListObj() listobj.Set("all,out,of,love") listobj.Sort() mydb.SetValue("shanghai", listobj) value1, err := mydb.GetValue("zrc") if err != nil { fmt.Println(err) } else { fmt.Println(value1.String()) fmt.Println(value1.(*object.MapObj).GetElem("c")) } value2, err := mydb.GetValue("qiqi") if err != nil { fmt.Println(err) } else { fmt.Println(value2.String()) } mydb.DelKey("shanghai") value3, err := mydb.GetValue("shanghai") if err != nil { fmt.Println(err) } else { fmt.Println(value3.String()) fmt.Println(value3.(*object.ListObj).Vals(4)) } return }
func Cmap(conn *Connection) { fmt.Println("Cmap") conn.DB.Lock() value, err := conn.DB.GetValue(conn.ReqData.Key) if err == nil { if reflect.TypeOf(value).String() != "*object.MapObj" { conn.RespData = conn.ReqData.Key + " is not a map key" conn.DB.Unlock() return } } mapobj := object.NewMapObj() mapobj.Set(conn.ReqData.Data) ret := conn.DB.SetValue(conn.ReqData.Key, mapobj) conn.DB.Unlock() switch ret { case db.UPDATE: conn.RespData = conn.ReqData.Command + " Update " + conn.ReqData.Key case db.CREATE: conn.RespData = conn.ReqData.Command + " Create " + conn.ReqData.Key } }