// Function for parsing of storage group of commands. // Receives array of string tokens. // Returns pointer to Ascii_protocol_enum with bound fields. func parseStorageCommands(args []string /*, data_block string*/) *Ascii_protocol_enum { protocol := new(Ascii_protocol_enum) if len(args) < 5 || /*len(data_block) == 0 ||*/ tools.In("", args) { return &Ascii_protocol_enum{error: ERROR_TEMP} } var err error //protocol.data_string = []byte(data_block) protocol.command = args[0] protocol.key = []string{args[1]} protocol.flags, err = tools.StringToInt32(args[2]) protocol.exptime, err = tools.StringToInt64(args[3]) protocol.exptime = tools.ToTimeStampFromNow(protocol.exptime) protocol.bytes, err = tools.StringToInt32(args[4]) if args[0] == "cas" { if len(args) < 6 { err = errors.New("invalid arguments number") } protocol.cas_unique, err = tools.StringToInt64(args[5]) if len(args) == 7 { protocol.noreply = (args[6] == "noreply") } } else { if len(args) == 6 { protocol.noreply = (args[5] == "noreply") } } if err != nil { return &Ascii_protocol_enum{error: ERROR_TEMP} } return protocol }
func (enum *Ascii_protocol_enum) lru_crawler(storage *cache.LRUCache) string { switch enum.key[0] { case "enable": err := storage.EnableCrawler() if err != nil { return strings.Replace(CLIENT_ERROR_TEMP, "%s", err.Error(), 1) } return "OK\r\n" case "disable": storage.DisableCrawler() return "OK\r\n" case "tocrawl": if len(enum.key) < 2 { return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Wrong parameters number.", 1) } amount, err := tools.StringToInt32(enum.key[1]) if amount <= 0 || err != nil { return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Invalid value of passed param.", 1) } storage.Crawler.ItemsPerRun = uint(amount) return "OK\r\n" case "sleep": if len(enum.key) < 2 { return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Wrong parameters number.", 1) } amount, err := tools.StringToInt32(enum.key[1]) if err != nil { return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Invalid value of passed param.", 1) } err = storage.Crawler.SetSleep(amount) if err != nil { return strings.Replace(CLIENT_ERROR_TEMP, "%s", err.Error(), 1) } return "OK\r\n" default: return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Command is not implemented.", 1) } }