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)
| 1891 | // the field is not defined in the schema, or if the type mismatched the field |
| 1892 | // type. |
| 1893 | func (m *AlertMutation) SetField(name string, value ent.Value) error { |
| 1894 | switch name { |
| 1895 | case alert.FieldCreatedAt: |
| 1896 | v, ok := value.(time.Time) |
| 1897 | if !ok { |
| 1898 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1899 | } |
| 1900 | m.SetCreatedAt(v) |
| 1901 | return nil |
| 1902 | case alert.FieldUpdatedAt: |
| 1903 | v, ok := value.(time.Time) |
| 1904 | if !ok { |
| 1905 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1906 | } |
| 1907 | m.SetUpdatedAt(v) |
| 1908 | return nil |
| 1909 | case alert.FieldScenario: |
| 1910 | v, ok := value.(string) |
| 1911 | if !ok { |
| 1912 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1913 | } |
| 1914 | m.SetScenario(v) |
| 1915 | return nil |
| 1916 | case alert.FieldBucketId: |
| 1917 | v, ok := value.(string) |
| 1918 | if !ok { |
| 1919 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1920 | } |
| 1921 | m.SetBucketId(v) |
| 1922 | return nil |
| 1923 | case alert.FieldMessage: |
| 1924 | v, ok := value.(string) |
| 1925 | if !ok { |
| 1926 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1927 | } |
| 1928 | m.SetMessage(v) |
| 1929 | return nil |
| 1930 | case alert.FieldEventsCount: |
| 1931 | v, ok := value.(int32) |
| 1932 | if !ok { |
| 1933 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1934 | } |
| 1935 | m.SetEventsCount(v) |
| 1936 | return nil |
| 1937 | case alert.FieldStartedAt: |
| 1938 | v, ok := value.(time.Time) |
| 1939 | if !ok { |
| 1940 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1941 | } |
| 1942 | m.SetStartedAt(v) |
| 1943 | return nil |
| 1944 | case alert.FieldStoppedAt: |
| 1945 | v, ok := value.(time.Time) |
| 1946 | if !ok { |
| 1947 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 1948 | } |
| 1949 | m.SetStoppedAt(v) |
| 1950 | return nil |
nothing calls this directly
no test coverage detected