Project

General

Profile

Actions

Golang API server » History » Revision 4

« Previous | Revision 4/5 (diff) | Next »
Peter Amstutz, 08/09/2018 06:16 PM


Golang API server

Currently thinking about how to structure the callbacks that happen when updating and saving a record.

Types of callbacks:

  • Fix-ups: modifying a column value, for example, stripping signatures from manifest_text
  • Fill-ins: setting certain columns implies filling in another value (for example, setting portable_data_hash from manifest_text)
  • Transitions: check that it semantically valid to go to record state Y from record state X (eg X and Y may both be valid, but going (X → Y) may not be valid)
  • Permissions: check that the user making the request is allowed to make that modification
  • Validations: check that a given record value is valid

Callbacks are very sensitive to ordering. For example, a record may not pass Validation until a Fix-up has been applied. Transition checks may occur before or after Fill-ins or Fix-ups. It is desirable to perform permission checks as early as possible to avoid doing unnecessary work on a request that will be rejected.

Callback types have different contracts:

Fix-up and Fill-in operations potentially modify the update operation. Transition and Permission validations rely on both the before and after state. Plain Validation checks only look at the current state, but may apply to both create and update requests.

Existing code

Struct validation https://github.com/go-ozzo/ozzo-validation

Generate Golang structs from Rails ActiveRecord

https://github.com/t-k/ar2gostruct

Updated by Peter Amstutz over 5 years ago · 4 revisions