SetFunc is the function meant to be passed to SetByID.
(f func(context.Context, *ttnpb.EndDevice) error)
| 271 | |
| 272 | // SetFunc is the function meant to be passed to SetByID. |
| 273 | func (st *setDeviceState) SetFunc(f func(context.Context, *ttnpb.EndDevice) error) func(context.Context, *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error) { // nolint: lll |
| 274 | return func(ctx context.Context, stored *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error) { |
| 275 | for p, shouldBeZero := range st.zeroPaths { |
| 276 | if stored.FieldIsZero(p) != shouldBeZero { |
| 277 | return nil, nil, newInvalidFieldValueError(p) |
| 278 | } |
| 279 | } |
| 280 | for _, g := range st.onGet { |
| 281 | if err := g(stored); err != nil { |
| 282 | return nil, nil, err |
| 283 | } |
| 284 | } |
| 285 | if err := f(ctx, stored); err != nil { |
| 286 | return nil, nil, err |
| 287 | } |
| 288 | return st.Device, st.SetFields(), nil |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | func newSetDeviceState(dev *ttnpb.EndDevice, paths ...string) *setDeviceState { |
| 293 | return &setDeviceState{ |