SetField sets the value of a field with the given name. It returns an error if the field is not defined in the schema, or if the type mismatched the field type.
(name string, value ent.Value)
| 8173 | // the field is not defined in the schema, or if the type mismatched the field |
| 8174 | // type. |
| 8175 | func (m *EventMutation) SetField(name string, value ent.Value) error { |
| 8176 | switch name { |
| 8177 | case event.FieldCreatedAt: |
| 8178 | v, ok := value.(time.Time) |
| 8179 | if !ok { |
| 8180 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 8181 | } |
| 8182 | m.SetCreatedAt(v) |
| 8183 | return nil |
| 8184 | case event.FieldUpdatedAt: |
| 8185 | v, ok := value.(time.Time) |
| 8186 | if !ok { |
| 8187 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 8188 | } |
| 8189 | m.SetUpdatedAt(v) |
| 8190 | return nil |
| 8191 | case event.FieldTime: |
| 8192 | v, ok := value.(time.Time) |
| 8193 | if !ok { |
| 8194 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 8195 | } |
| 8196 | m.SetTime(v) |
| 8197 | return nil |
| 8198 | case event.FieldSerialized: |
| 8199 | v, ok := value.(string) |
| 8200 | if !ok { |
| 8201 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 8202 | } |
| 8203 | m.SetSerialized(v) |
| 8204 | return nil |
| 8205 | case event.FieldAlertEvents: |
| 8206 | v, ok := value.(int) |
| 8207 | if !ok { |
| 8208 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 8209 | } |
| 8210 | m.SetAlertEvents(v) |
| 8211 | return nil |
| 8212 | } |
| 8213 | return fmt.Errorf("unknown Event field %s", name) |
| 8214 | } |
| 8215 | |
| 8216 | // AddedFields returns all numeric fields that were incremented/decremented during |
| 8217 | // this mutation. |
nothing calls this directly
no test coverage detected