Пример #1
0
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)
}