()
| 109 | } |
| 110 | |
| 111 | func (l *Link) check() error { |
| 112 | selfIsEmpty, err := checkLinkValue(l.Self) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | |
| 117 | relatedIsEmpty, err := checkLinkValue(l.Related) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | // if both are empty then fail, and if one is empty, it must be set to nil to satisfy omitempty |
| 123 | switch { |
| 124 | case selfIsEmpty && relatedIsEmpty: |
| 125 | return ErrMissingLinkFields |
| 126 | case selfIsEmpty: |
| 127 | l.Self = nil |
| 128 | case relatedIsEmpty: |
| 129 | l.Related = nil |
| 130 | } |
| 131 | |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | // Document is a JSON:API document as defined by https://jsonapi.org/format/1.0/#document-top-level |
| 136 | type document struct { |
no test coverage detected