func (s *ZStoreStub) handleCreate(req *zc.ZMsg, resp *zc.ZMsg) { payload, _ := req.GetPayload() if !req.CheckString("zc-class") || !req.CheckObject("zc-object") { resp.SetErr("invalid create request") log.Infof("invalid create request: %s", string(payload)) return } className := req.GetString("zc-class") if !s.checkClass(className) { resp.SetErr("invalid class name") log.Infof("invalid create request: %s", string(payload)) return } classStore := s.store[className] if classStore == nil { s.store[className] = make(map[string]zc.ZObject, 10) classStore = s.store[className] } zo := req.GetObject("zc-object") primaryKey := s.getPrimaryKey(className, zo) classStore[primaryKey] = zo resp.SetAck() resp.Put("zc-object", zo) }
func (s *ZStoreStub) handleFind(req *zc.ZMsg, resp *zc.ZMsg) { payload, _ := req.GetPayload() if !req.CheckExists("zc-class", "zc-find") { resp.SetErr("invalid find request") log.Infof("invalid find request: %s", string(payload)) return } className := req.GetString("zc-class") if !s.checkClass(className) { resp.SetErr("invalid class name") log.Infof("invalid find request: %s", string(payload)) return } classStore := s.store[className] if classStore == nil { resp.SetAck() return } find := req.GetObject("zc-find") zo := find.GetObject("zc-object") selectKeys := find.GetStrings("zc-select") primaryKey := s.getPrimaryKey(className, zo) dataZO := classStore[primaryKey] if dataZO == nil { resp.SetAck() return } if len(selectKeys) <= 0 { resp.SetAck() resp.Put("zc-object", dataZO) return } selectZO := zc.NewObject() for _, key := range selectKeys { selectZO.Put(key, dataZO.Get(key)) } resp.SetAck() resp.Put("zc-object", selectZO) return }