openai/openai-go
Publicmirrored fromhttps://github.com/openai/openai-goAvailable
packages/param/null.go
19lines · modecode
| 1 | package param |
| 2 | |
| 3 | import "github.com/openai/openai-go/v3/internal/encoding/json/sentinel" |
| 4 | |
| 5 | // NullMap returns a non-nil map with a length of 0. |
| 6 | // When used with [MarshalObject] or [MarshalUnion], it will be marshaled as null. |
| 7 | // |
| 8 | // It is unspecified behavior to mutate the map returned by [NullMap]. |
| 9 | func NullMap[MapT ~map[string]T, T any]() MapT { |
| 10 | return sentinel.NewNullSentinel(func() MapT { return make(MapT, 1) }) |
| 11 | } |
| 12 | |
| 13 | // NullSlice returns a non-nil slice with a length of 0. |
| 14 | // When used with [MarshalObject] or [MarshalUnion], it will be marshaled as null. |
| 15 | // |
| 16 | // It is unspecified behavior to mutate the slice returned by [NullSlice]. |
| 17 | func NullSlice[SliceT ~[]T, T any]() SliceT { |
| 18 | return sentinel.NewNullSentinel(func() SliceT { return make(SliceT, 0, 1) }) |
| 19 | } |
| 20 | |