MCPcopy Create free account

hub / github.com/creasty/defaults / functions

Functions146 in github.com/creasty/defaults

↓ 113 callersFunctionSet
Set initializes members in a struct referenced by a pointer. Maps and slices are initialized by `make` and other primitive types are set with default
defaults.go:35
↓ 9 callersFunctionCanUpdate
CanUpdate returns true when the given value is an initial value of its type
defaults.go:321
↓ 4 callersFunctionMustSet
MustSet function is a wrapper of Set function It will call Set and panic if err not equals nil.
defaults.go:67
↓ 2 callersFunctioncallSetter
(v interface{})
setter.go:8
↓ 2 callersFunctionisInitialValue
(field reflect.Value)
defaults.go:296
↓ 1 callersMethodSetDefaults
()
setter.go:5
↓ 1 callersMethodUnexportedField
UnexportedField returns the field Set is expected to leave alone.
internal/fixture/test.go:16
↓ 1 callersMethodUnmarshalJSON
([]byte)
set_unmarshaler_test.go:73
↓ 1 callersMethodUnmarshalText
([]byte)
set_unmarshaler_test.go:68
↓ 1 callersFunctionsetField
(field reflect.Value, tag fieldTag)
defaults.go:73
↓ 1 callersFunctionshouldInitializeField
shouldInitializeField reports whether the field's own state warrants visiting it, regardless of any tag: a struct is always descended into, as is a po
defaults.go:307
↓ 1 callersFunctionunmarshalByInterface
(field reflect.Value, defaultVal string)
defaults.go:278
FunctionExampleCanUpdate
()
example_test.go:91
FunctionExampleSet
()
example_test.go:24
FunctionExampleSet_nested
()
example_test.go:47
FunctionExampleSetter
()
example_test.go:73
MethodSetDefaults
()
setter_test.go:20
MethodSetDefaults
()
setter_test.go:29
MethodSetDefaults
()
setter_test.go:40
MethodSetDefaults
()
setter_test.go:50
MethodSetDefaults
()
setter_test.go:63
MethodSetDefaults
()
setter_test.go:75
MethodSetDefaults
()
set_unmarshaler_test.go:59
MethodSetDefaults
SetDefaults derives a default that a tag cannot express, and CanUpdate keeps it from overriding what the caller already provided.
example_test.go:18
MethodSetDefaults
()
set_optout_test.go:19
MethodSetDefaults
()
set_optout_test.go:29
MethodSetDefaults
SetDefaults implements defaults.Setter interface
example/main.go:43
FunctionTestCanUpdate
TestCanUpdate covers what "can update" means: deep-equal to the zero value of its own type. Note that an allocated-but-empty slice or map is therefore
canupdate_test.go:14
FunctionTestCanUpdate_Nil
TestCanUpdate_Nil covers a nil, which carries no type to compare against: there is nothing there to preserve, so it is updatable. It used to panic ins
canupdate_test.go:63
FunctionTestMustSet_PanicsForInvalidTag
(t *testing.T)
mustset_test.go:43
FunctionTestMustSet_PanicsForNonPointer
(t *testing.T)
mustset_test.go:25
FunctionTestMustSet_PanicsForPointerToNonStruct
(t *testing.T)
mustset_test.go:35
FunctionTestMustSet_SetsDefaults
(t *testing.T)
mustset_test.go:12
FunctionTestSet_ArraysAreLeftAlone
TestSet_ArraysAreLeftAlone pins that reflect.Array has no case in setField, which makes an array behave unlike the slice of the same element type: its
set_slice_test.go:147
FunctionTestSet_Bool
(t *testing.T)
set_scalar_test.go:57
FunctionTestSet_ByteSlice
TestSet_ByteSlice covers []byte, where encoding/json accepts two spellings and rejects bare text.
set_slice_test.go:166
FunctionTestSet_CannotPreserveFalseBool
TestSet_CannotPreserveFalseBool pins the one type whose caller-provided value is indistinguishable from "unset": a bool. An explicit false is overwrit
set_preserve_test.go:98
FunctionTestSet_DeepContainersFromTag
TestSet_DeepContainersFromTag covers nesting created entirely by a tag, rather than by the caller.
set_nesting_test.go:85
FunctionTestSet_DeepSliceOfStructs
(t *testing.T)
set_nesting_test.go:28
FunctionTestSet_Duration
(t *testing.T)
set_duration_test.go:13
FunctionTestSet_DurationAndIntegerShareOneParser
TestSet_DurationAndIntegerShareOneParser pins the outcomes of int64-kinded fields being handed to both time.ParseDuration and strconv.ParseInt: a bare
set_duration_test.go:40
FunctionTestSet_DurationStringOnANarrowerIntegerIsRejected
TestSet_DurationStringOnANarrowerIntegerIsRejected pins that the duration fallback is int64-only. A narrower width rejects a duration string outright,
set_duration_test.go:58
FunctionTestSet_DurationTagIsTrimmed
TestSet_DurationTagIsTrimmed covers a duration tag carrying surrounding whitespace, which used to leave the field at zero. The trim happens where Pars
set_duration_test.go:80
FunctionTestSet_EmbeddedPointerStruct
(t *testing.T)
set_struct_test.go:95
FunctionTestSet_EmbeddedPointerStructWithoutTagStaysNil
(t *testing.T)
set_struct_test.go:110
FunctionTestSet_EmbeddedStruct
TestSet_EmbeddedStruct covers promoted fields. The embedded types are named with an initial capital on purpose: the embedded field takes the type's na
set_struct_test.go:76
FunctionTestSet_EmptyContainerTagsAndJSONUnmarshaler
TestSet_EmptyContainerTagsAndJSONUnmarshaler pins which empty-container tags reach a custom UnmarshalJSON. The interface path withholds both `{}` and
set_unmarshaler_test.go:190
FunctionTestSet_EmptyMapTagCreatesEmptyMap
(t *testing.T)
set_map_test.go:12
FunctionTestSet_EmptySliceTagCreatesEmptySlice
(t *testing.T)
set_slice_test.go:12
FunctionTestSet_EmptyTag
TestSet_EmptyTag covers `default:""`, which is a request for the zero value rather than an absence: Set reads the tag with Tag.Lookup, so an empty tag
set_scalar_test.go:368
FunctionTestSet_ErrorStopsAtTheFirstField
TestSet_ErrorStopsAtTheFirstField pins that Set gives up on the first failing field rather than collecting errors, so later fields keep their zero val
set_error_test.go:156
FunctionTestSet_FailingUnmarshalerFallsBackToKind
TestSet_FailingUnmarshalerFallsBackToKind covers what happens when the type's own unmarshaler rejects the value: the error is not reported, and the va
set_unmarshaler_test.go:169
FunctionTestSet_Floats
(t *testing.T)
set_scalar_test.go:45
FunctionTestSet_ForeignPackageUnexportedField
TestSet_ForeignPackageUnexportedField covers a struct declared in another package: the exported field is set, the unexported one is out of reflect's r
set_struct_test.go:126
FunctionTestSet_IntegerLiteralBases
TestSet_IntegerLiteralBases covers every width against every base, because the base is a parameter of the strconv call made per width: a `ParseInt(v,
set_scalar_test.go:86
FunctionTestSet_InterfaceFieldsAreNotFollowed
TestSet_InterfaceFieldsAreNotFollowed pins that a non-nil interface is not descended into, even when it holds a pointer to a struct carrying tags. The
set_scalar_test.go:428
FunctionTestSet_InvalidDefaultErrorShape
TestSet_InvalidDefaultErrorShape pins what the error carries: the field it came from, the tag that failed, and the underlying cause still reachable —
set_scalar_test.go:344
FunctionTestSet_InvalidJSONInTag
(t *testing.T)
set_error_test.go:69
FunctionTestSet_JSONUnmarshaler
(t *testing.T)
set_unmarshaler_test.go:115
FunctionTestSet_MapOfMapOfStructs
(t *testing.T)
set_nesting_test.go:39
FunctionTestSet_MapOfNilPointersIsLeftAlone
TestSet_MapOfNilPointersIsLeftAlone covers a nil pointer as a map value: there is nothing behind it to recurse into. A pointer map value is written th
set_map_test.go:110
FunctionTestSet_MapOfPointerContainers
TestSet_MapOfPointerContainers covers map values that point at a container rather than a struct. The element loop handles all three of struct, slice a
set_map_test.go:189
FunctionTestSet_MapOfPointerStructsGetsDefaults
(t *testing.T)
set_map_test.go:84
FunctionTestSet_MapOfScalarsIsLeftAlone
TestSet_MapOfScalarsIsLeftAlone pins that scalar map values are never rewritten: a zero value is not a field with a tag.
set_map_test.go:176
FunctionTestSet_MapOfSliceOfPointerStructs
(t *testing.T)
set_nesting_test.go:69
FunctionTestSet_MapOfStructsGetsDefaults
TestSet_MapOfStructsGetsDefaults covers a map of struct values the caller filled in. Values are not addressable, so each element is copied, defaulted,
set_map_test.go:63
FunctionTestSet_MapTagCreatesPointerStructElements
(t *testing.T)
set_map_test.go:157
FunctionTestSet_MapTagCreatesStructElements
TestSet_MapTagCreatesStructElements covers elements the tag itself creates: they are defaulted like any other element, and no other key appears.
set_map_test.go:140
FunctionTestSet_MapTagIsNotReappliedToElements
TestSet_MapTagIsNotReappliedToElements pins that the element recursion is handed an empty tag: the parent's JSON builds the map once and is not decode
set_map_test.go:217
FunctionTestSet_MapTagJSON
(t *testing.T)
set_map_test.go:24
FunctionTestSet_NamedMapType
(t *testing.T)
set_map_test.go:35
FunctionTestSet_NamedScalarTypes
(t *testing.T)
set_scalar_test.go:232
FunctionTestSet_NamedSliceType
(t *testing.T)
set_slice_test.go:52
FunctionTestSet_NestedPointersAreAllocated
TestSet_NestedPointersAreAllocated covers arbitrary pointer depth: every level is allocated and the value lands at the bottom.
set_pointer_test.go:164
FunctionTestSet_NumberTagIsNotTrimmed
TestSet_NumberTagIsNotTrimmed pins the other side of that trim: it belongs to the duration attempt alone, so a padded number reaches the numeric parse
set_duration_test.go:102
FunctionTestSet_NumericWidthBoundaries
TestSet_NumericWidthBoundaries pins the bit size each numeric case parses with. Every case passes that width to strconv as a literal, and a wrong one
set_scalar_test.go:157
FunctionTestSet_OptOutDoesNotAffectOwnSetter
TestSet_OptOutDoesNotAffectOwnSetter covers the other side: opting a field out does not opt its own struct out of having its setter called.
set_optout_test.go:92
FunctionTestSet_OptOutPreservesCallerValue
(t *testing.T)
set_optout_test.go:100
FunctionTestSet_OptOutSkipsContainers
(t *testing.T)
set_optout_test.go:47
FunctionTestSet_OptOutSkipsPointer
(t *testing.T)
set_optout_test.go:60
FunctionTestSet_OptOutSkipsScalar
(t *testing.T)
set_optout_test.go:35
FunctionTestSet_OptOutSkipsStructRecursionAndSetter
TestSet_OptOutSkipsStructRecursionAndSetter covers the reach of `-` on a struct field: it is not descended into, so neither the nested tags nor the ne
set_optout_test.go:78
FunctionTestSet_PanicsOnNil
TestSet_PanicsOnNil pins that a nil argument is not rejected but fatal: the type switch happens before any validation. QUIRK: arguably these should r
set_error_test.go:51
FunctionTestSet_PointerFieldErrorIsReported
TestSet_PointerFieldErrorIsReported covers a *struct field whose nested tag is invalid. That error used to be discarded, alone among the recursions, s
set_error_test.go:132
FunctionTestSet_PointerToMap
(t *testing.T)
set_pointer_test.go:73
FunctionTestSet_PointerToSlice
(t *testing.T)
set_pointer_test.go:89
FunctionTestSet_PointerToStruct
(t *testing.T)
set_pointer_test.go:41
FunctionTestSet_PointerToStructWithJSONTag
(t *testing.T)
set_pointer_test.go:57
FunctionTestSet_PointerWithEmptyTag
TestSet_PointerWithEmptyTag covers `default:""` on a pointer. The tag is present, so the pointer is allocated and points at the zero value — it used t
set_pointer_test.go:147
FunctionTestSet_PointersToScalars
(t *testing.T)
set_pointer_test.go:12
FunctionTestSet_PreservesNonInitialMap
(t *testing.T)
set_preserve_test.go:49
FunctionTestSet_PreservesNonInitialScalar
(t *testing.T)
set_preserve_test.go:12
FunctionTestSet_PreservesNonInitialScalarPointer
(t *testing.T)
set_preserve_test.go:25
FunctionTestSet_PreservesNonInitialSlice
(t *testing.T)
set_preserve_test.go:38
FunctionTestSet_PreservesNonInitialStruct
(t *testing.T)
set_preserve_test.go:60
FunctionTestSet_PreservesNonInitialStructPointer
(t *testing.T)
set_preserve_test.go:76
FunctionTestSet_PreservesNonInitialZeroLengthContainers
TestSet_PreservesNonInitialZeroLengthContainers pins that "non-initial" means "not deep-equal to the zero value", so an allocated but empty slice or m
set_preserve_test.go:116
FunctionTestSet_RejectsNonStructPointer
(t *testing.T)
set_error_test.go:13
FunctionTestSet_SignedIntegers
(t *testing.T)
set_scalar_test.go:14
FunctionTestSet_SliceElementsGetDefaults
TestSet_SliceElementsGetDefaults covers a slice the caller filled in: Set descends into each element even though the field carries no tag.
set_slice_test.go:113
next →1–100 of 146, ranked by callers