func Get(server Server, conn Conn, args []string) bool { if len(args) != 1 { return false } q, ok := storage.NewObject(args[0]) if !ok { return false } items, valid := server.Storage.Get(q) if !valid { conn.Write(response_error_no_index) return true } for _, item := range items { b, err := json.Marshal(item) if err != nil { continue } conn.Write(string(b)) } conn.Write(response_end) return true }
func Set(server Server, conn Conn, args []string) bool { if len(args) != 2 { return false } q, ok := storage.NewObject(args[0]) if !ok { return false } values, ok2 := storage.NewObject(args[1]) if !ok2 { return false } server.Storage.Set(q, values) return true }
func Add(server Server, conn Conn, args []string) bool { if len(args) != 1 { return false } object, ok := storage.NewObject(args[0]) if !ok { return false } server.Storage.Add(object) conn.Write(response_success) return true }
func Delete(server Server, conn Conn, args []string) bool { if len(args) != 1 { return false } q, ok := storage.NewObject(args[0]) if !ok { return false } c, valid := server.Storage.Delete(q) if !valid { conn.Write(response_error_no_index) return true } conn.Write(fmt.Sprintf(response_success_arg, strconv.Itoa(c))) return true }