| 1 | package respjsonscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/ |
| 2 | |
| 3 | // A Field provides metadata to indicate the presence of a value. |
| 4 | // |
| 5 | // Use [Field.Valid] to check if an optional value was null or omitted. |
| 6 | // |
| 7 | // A Field will always occur in the following structure, where it |
| 8 | // mirrors the original field in its parent struct: |
| 9 | // |
| 10 | // type ExampleObject struct { |
| 11 | // Foo bool `json:"foo"` |
| 12 | // Bar int `json:"bar"` |
| 13 | // // ... |
| 14 | // |
| 15 | // // JSON provides metadata about the object. |
| 16 | // JSON struct { |
| 17 | // Foo Field |
| 18 | // Bar Field |
| 19 | // // ... |
| 20 | // } `json:"-"` |
| 21 | // } |
| 22 | // |
| 23 | // To differentiate a "nullish" value from the zero value, |
| 24 | // use the [Field.Valid] method. |
| 25 | // |
| 26 | // if !example.JSON.Foo.Valid() { |
| 27 | // println("Foo is null or omitted") |
| 28 | // } |
| 29 | // |
| 30 | // if example.Foo { |
| 31 | // println("Foo is true") |
| 32 | // } else { |
| 33 | // println("Foo is false") |
| 34 | // } |
| 35 | // |
| 36 | // To differentiate if a field was omitted or the JSON value "null", |
| 37 | // use the [Field.Raw] method. |
| 38 | // |
| 39 | // if example.JSON.Foo.Raw() == "null" { |
| 40 | // println("Foo is null") |
| 41 | // } |
| 42 | // |
| 43 | // if example.JSON.Foo.Raw() == "" { |
| 44 | // println("Foo was omitted") |
| 45 | // } |
| 46 | // |
| 47 | // Otherwise, if the field was invalid and couldn't be marshalled successfully, |
| 48 | // [Field.Valid] will be false and [Field.Raw] will not be empty. |
| 49 | type Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field# struct { |
| 50 | statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status. |
| 51 | rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#raw. string |
| 52 | } |
| 53 | |
| 54 | const ( |
| 55 | omittedscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/omitted. statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/status# = iota |
| 56 | nullscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/null. |
| 57 | invalidscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/invalid. |
| 58 | validscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/valid. |
| 59 | ) |
| 60 | |
| 61 | type statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/status# int8 |
| 62 | |
| 63 | // Valid returns true if the parent field was set. |
| 64 | // Valid returns false if the value doesn't exist, is JSON null, or |
| 65 | // is an unexpected type. |
| 66 | func (j Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#) Validscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#Valid().() bool { return j.statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status. > invalidscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/invalid. } |
| 67 | |
| 68 | const Nullscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Null. string = "null" |
| 69 | const Omittedscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Omitted. string = "" |
| 70 | |
| 71 | // Returns the raw JSON value of the field. |
| 72 | func (j Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#) Rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#Raw().() string { |
| 73 | if j.statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status. == omittedscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/omitted. { |
| 74 | return "" |
| 75 | } |
| 76 | return j.rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#raw. |
| 77 | } |
| 78 | |
| 79 | func NewFieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/NewField().(raw string) Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field# { |
| 80 | if raw == "null" { |
| 81 | return Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#{statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status.: nullscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/null., rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#raw.: Nullscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Null.} |
| 82 | } |
| 83 | return Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#{statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status.: validscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/valid., rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#raw.: raw} |
| 84 | } |
| 85 | |
| 86 | func NewInvalidFieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/NewInvalidField().(raw string) Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field# { |
| 87 | return Fieldscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#{statusscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#status.: invalidscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/invalid., rawscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/packages/respjson`/Field#raw.: raw} |
| 88 | } |