Golang API server » History » Version 5
Tom Clegg, 03/26/2019 03:33 PM
1 | 5 | Tom Clegg | {{>toc}} |
---|---|---|---|
2 | |||
3 | 1 | Peter Amstutz | h1. Golang API server |
4 | |||
5 | 5 | Tom Clegg | h2. Possible API changes |
6 | |||
7 | h3. limit=0 |
||
8 | |||
9 | Rails API implements limit=0 by returning zero items. It would simplify the Go client and server code to change the semantics so limit=0 means "no limit / let the server choose a limit". Using limit=0 to count records would still work, but responses would be bigger; it would be more efficient to use limit=1&select=[]. |
||
10 | |||
11 | h2. ActiveRecord-style callbacks/hooks |
||
12 | |||
13 | 2 | Peter Amstutz | Currently thinking about how to structure the callbacks that happen when updating and saving a record. |
14 | |||
15 | Types of callbacks: |
||
16 | |||
17 | * Fix-ups: modifying a column value, for example, stripping signatures from manifest_text |
||
18 | * Fill-ins: setting certain columns implies filling in another value (for example, setting portable_data_hash from manifest_text) |
||
19 | * 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) |
||
20 | * Permissions: check that the user making the request is allowed to make that modification |
||
21 | * Validations: check that a given record value is valid |
||
22 | 4 | Peter Amstutz | |
23 | 2 | Peter Amstutz | 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. |
24 | |||
25 | 1 | Peter Amstutz | Callback types have different contracts: |
26 | |||
27 | 3 | Peter Amstutz | 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. |
28 | 1 | Peter Amstutz | |
29 | 5 | Tom Clegg | h3. Existing code |
30 | 3 | Peter Amstutz | |
31 | Struct validation https://github.com/go-ozzo/ozzo-validation |
||
32 | |||
33 | Generate Golang structs from Rails ActiveRecord |
||
34 | |||
35 | https://github.com/t-k/ar2gostruct |