package fire import ( "errors" "git.mokkon.com/sainw/server_helper.git/util" ) // Payload defines the payload type Payload struct { // document data data map[string]interface{} } func NewPayload(data map[string]interface{}) *Payload { return &Payload{data: data} } func (p Payload) getID() (string, error) { id := p.String("id") if id == "" { return "", errors.New("ID not found") } return id, nil } // Add adds data to existing data func (p *Payload) Add(data map[string]interface{}) { for k, v := range data { p.data[k] = v } } // String returns string value of the field // if the value type is not string, return blank string func (pl *Payload) String(field string) string { value, ok := pl.data[field] if ok { str, isString := value.(string) if isString { return str } } return "" } // String returns string value of the field from payload func (pl *Payload) Strings(field string) []string { value, ok := pl.data[field] if ok { return util.ToStrings(value) } return []string{} } // Value returns interface value of the field from payload func (pl *Payload) Value(field string) interface{} { value, ok := pl.data[field] if ok { return value } return nil }