Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/creasty/defaults
/ functions
Functions
146 in github.com/creasty/defaults
⨍
Functions
146
◇
Types & classes
72
↓ 113 callers
Function
Set
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 callers
Function
CanUpdate
CanUpdate returns true when the given value is an initial value of its type
defaults.go:321
↓ 4 callers
Function
MustSet
MustSet function is a wrapper of Set function It will call Set and panic if err not equals nil.
defaults.go:67
↓ 2 callers
Function
callSetter
(v interface{})
setter.go:8
↓ 2 callers
Function
isInitialValue
(field reflect.Value)
defaults.go:296
↓ 1 callers
Method
SetDefaults
()
setter.go:5
↓ 1 callers
Method
UnexportedField
UnexportedField returns the field Set is expected to leave alone.
internal/fixture/test.go:16
↓ 1 callers
Method
UnmarshalJSON
([]byte)
set_unmarshaler_test.go:73
↓ 1 callers
Method
UnmarshalText
([]byte)
set_unmarshaler_test.go:68
↓ 1 callers
Function
setField
(field reflect.Value, tag fieldTag)
defaults.go:73
↓ 1 callers
Function
shouldInitializeField
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 callers
Function
unmarshalByInterface
(field reflect.Value, defaultVal string)
defaults.go:278
Function
ExampleCanUpdate
()
example_test.go:91
Function
ExampleSet
()
example_test.go:24
Function
ExampleSet_nested
()
example_test.go:47
Function
ExampleSetter
()
example_test.go:73
Method
SetDefaults
()
setter_test.go:20
Method
SetDefaults
()
setter_test.go:29
Method
SetDefaults
()
setter_test.go:40
Method
SetDefaults
()
setter_test.go:50
Method
SetDefaults
()
setter_test.go:63
Method
SetDefaults
()
setter_test.go:75
Method
SetDefaults
()
set_unmarshaler_test.go:59
Method
SetDefaults
SetDefaults derives a default that a tag cannot express, and CanUpdate keeps it from overriding what the caller already provided.
example_test.go:18
Method
SetDefaults
()
set_optout_test.go:19
Method
SetDefaults
()
set_optout_test.go:29
Method
SetDefaults
SetDefaults implements defaults.Setter interface
example/main.go:43
Function
TestCanUpdate
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
Function
TestCanUpdate_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
Function
TestMustSet_PanicsForInvalidTag
(t *testing.T)
mustset_test.go:43
Function
TestMustSet_PanicsForNonPointer
(t *testing.T)
mustset_test.go:25
Function
TestMustSet_PanicsForPointerToNonStruct
(t *testing.T)
mustset_test.go:35
Function
TestMustSet_SetsDefaults
(t *testing.T)
mustset_test.go:12
Function
TestSet_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
Function
TestSet_Bool
(t *testing.T)
set_scalar_test.go:57
Function
TestSet_ByteSlice
TestSet_ByteSlice covers []byte, where encoding/json accepts two spellings and rejects bare text.
set_slice_test.go:166
Function
TestSet_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
Function
TestSet_DeepContainersFromTag
TestSet_DeepContainersFromTag covers nesting created entirely by a tag, rather than by the caller.
set_nesting_test.go:85
Function
TestSet_DeepSliceOfStructs
(t *testing.T)
set_nesting_test.go:28
Function
TestSet_Duration
(t *testing.T)
set_duration_test.go:13
Function
TestSet_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
Function
TestSet_DurationStringOnANarrowerIntegerIsRejected
TestSet_DurationStringOnANarrowerIntegerIsRejected pins that the duration fallback is int64-only. A narrower width rejects a duration string outright,
set_duration_test.go:58
Function
TestSet_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
Function
TestSet_EmbeddedPointerStruct
(t *testing.T)
set_struct_test.go:95
Function
TestSet_EmbeddedPointerStructWithoutTagStaysNil
(t *testing.T)
set_struct_test.go:110
Function
TestSet_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
Function
TestSet_EmptyContainerTagsAndJSONUnmarshaler
TestSet_EmptyContainerTagsAndJSONUnmarshaler pins which empty-container tags reach a custom UnmarshalJSON. The interface path withholds both `{}` and
set_unmarshaler_test.go:190
Function
TestSet_EmptyMapTagCreatesEmptyMap
(t *testing.T)
set_map_test.go:12
Function
TestSet_EmptySliceTagCreatesEmptySlice
(t *testing.T)
set_slice_test.go:12
Function
TestSet_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
Function
TestSet_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
Function
TestSet_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
Function
TestSet_Floats
(t *testing.T)
set_scalar_test.go:45
Function
TestSet_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
Function
TestSet_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
Function
TestSet_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
Function
TestSet_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
Function
TestSet_InvalidJSONInTag
(t *testing.T)
set_error_test.go:69
Function
TestSet_JSONUnmarshaler
(t *testing.T)
set_unmarshaler_test.go:115
Function
TestSet_MapOfMapOfStructs
(t *testing.T)
set_nesting_test.go:39
Function
TestSet_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
Function
TestSet_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
Function
TestSet_MapOfPointerStructsGetsDefaults
(t *testing.T)
set_map_test.go:84
Function
TestSet_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
Function
TestSet_MapOfSliceOfPointerStructs
(t *testing.T)
set_nesting_test.go:69
Function
TestSet_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
Function
TestSet_MapTagCreatesPointerStructElements
(t *testing.T)
set_map_test.go:157
Function
TestSet_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
Function
TestSet_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
Function
TestSet_MapTagJSON
(t *testing.T)
set_map_test.go:24
Function
TestSet_NamedMapType
(t *testing.T)
set_map_test.go:35
Function
TestSet_NamedScalarTypes
(t *testing.T)
set_scalar_test.go:232
Function
TestSet_NamedSliceType
(t *testing.T)
set_slice_test.go:52
Function
TestSet_NestedPointersAreAllocated
TestSet_NestedPointersAreAllocated covers arbitrary pointer depth: every level is allocated and the value lands at the bottom.
set_pointer_test.go:164
Function
TestSet_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
Function
TestSet_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
Function
TestSet_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
Function
TestSet_OptOutPreservesCallerValue
(t *testing.T)
set_optout_test.go:100
Function
TestSet_OptOutSkipsContainers
(t *testing.T)
set_optout_test.go:47
Function
TestSet_OptOutSkipsPointer
(t *testing.T)
set_optout_test.go:60
Function
TestSet_OptOutSkipsScalar
(t *testing.T)
set_optout_test.go:35
Function
TestSet_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
Function
TestSet_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
Function
TestSet_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
Function
TestSet_PointerToMap
(t *testing.T)
set_pointer_test.go:73
Function
TestSet_PointerToSlice
(t *testing.T)
set_pointer_test.go:89
Function
TestSet_PointerToStruct
(t *testing.T)
set_pointer_test.go:41
Function
TestSet_PointerToStructWithJSONTag
(t *testing.T)
set_pointer_test.go:57
Function
TestSet_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
Function
TestSet_PointersToScalars
(t *testing.T)
set_pointer_test.go:12
Function
TestSet_PreservesNonInitialMap
(t *testing.T)
set_preserve_test.go:49
Function
TestSet_PreservesNonInitialScalar
(t *testing.T)
set_preserve_test.go:12
Function
TestSet_PreservesNonInitialScalarPointer
(t *testing.T)
set_preserve_test.go:25
Function
TestSet_PreservesNonInitialSlice
(t *testing.T)
set_preserve_test.go:38
Function
TestSet_PreservesNonInitialStruct
(t *testing.T)
set_preserve_test.go:60
Function
TestSet_PreservesNonInitialStructPointer
(t *testing.T)
set_preserve_test.go:76
Function
TestSet_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
Function
TestSet_RejectsNonStructPointer
(t *testing.T)
set_error_test.go:13
Function
TestSet_SignedIntegers
(t *testing.T)
set_scalar_test.go:14
Function
TestSet_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