MCPcopy Create free account

hub / github.com/creasty/defaults / functions

Functions250 in github.com/creasty/defaults

↓ 136 callersFunctionSet
Set fills the fields of the struct ptr points to from their `default` tags, and descends into structs, pointers, slices and maps to do the same below.
set.go:56
↓ 11 callersFunctionCanUpdate
CanUpdate returns true when the given value is an initial value of its type
canupdate.go:15
↓ 8 callersMethodadd
add adds an entry for k below the deepest x holds, and reports true, or reports false and adds nothing if x already holds k.
path.go:154
↓ 6 callersFunctionMustSet
MustSet function is a wrapper of Set function It will call Set and panic if err not equals nil.
mustset.go:5
↓ 5 callersMethodhash
hash mixes k into an int whose low bits pick a bucket.
path.go:123
↓ 5 callersMethodkey
key is w as the path's index holds it. A reflect.Type points to the one descriptor of its type, so the descriptor's address names the type, as == on T
path.go:109
↓ 5 callersFunctionpathEntries
This test is in package defaults rather than defaults_test: it takes walking and pathIndex on their own, which Set reaches only through a walk deeper
path_test.go:21
↓ 5 callersFunctionpathKeys
pathKeys returns n keys, no two alike, and keeps the values they name alive for the test.
path_test.go:57
↓ 5 callersFunctionpathSmallIndex
pathSmallIndex returns an index with room for size entries, which grow doubles. The walk makes a larger one; a small one reaches grow in a handful of
path_test.go:52
↓ 5 callersMethodpop
pop takes the deepest entry out of x.
path.go:171
↓ 5 callersMethodrepeatsFar
repeatsFar is repeatsNear for a w more than scanDepth down.
path.go:68
↓ 5 callersFunctionunmarshalTag
unmarshalTag offers value to target's own unmarshalers, UnmarshalText first and UnmarshalJSON second, and reports whether one took it. An empty value
unmarshal.go:22
↓ 4 callersFunctionpathBelow
pathBelow returns an entry naming a value of its own, below outer.
path_test.go:38
↓ 4 callersMethodrepeatsNear
repeatsNear reports whether the value w names is already being walked above it, on w.outer's path, if w is no more than scanDepth down. For a deeper w
path.go:55
↓ 3 callersMethodleave
leave takes w out of the path's index, if the index holds it, as w's walk returns. It is called on every return, a failed walk's too: a failure ends t
path.go:100
↓ 2 callersMethodSetDefaults
()
setter.go:14
↓ 2 callersFunctionbenchFillValue
benchFillValue is benchFill for a type built at run time.
benchmark_test.go:556
↓ 2 callersFunctionbenchStruct
benchStruct builds a struct of n fields of typ, F0 to Fn-1, each tagged tag: a field count or a tag chosen at run time, where a literal struct would t
benchmark_test.go:621
↓ 2 callersFunctionisInitialValue
(field reflect.Value)
canupdate.go:5
↓ 2 callersFunctionisPromotedMethod
isPromotedMethod reports whether the method called name is promoted from an embedded field rather than declared by t itself. reflect lists the two al
method.go:23
↓ 2 callersFunctionpathKeyInBucket
pathKeyInBucket returns a key other than k that an index of that many buckets puts in k's bucket, to test a chain of them.
path_test.go:70
↓ 2 callersFunctionset
set is Set, for a struct that may be reached by recursion and so carries the tags still being applied above it and the values being walked on the path
set.go:62
↓ 2 callersFunctionsetField
setField fills field from its tag and descends into it. It reports whether an UnmarshalText or UnmarshalJSON took the tag, the field's own or, behind
set.go:118
↓ 1 callersMethodPing
()
method_test.go:48
↓ 1 callersMethodUnmarshalJSON
([]byte)
set_unmarshaler_test.go:108
↓ 1 callersMethodUnmarshalJSON
(data []byte)
benchmark_test.go:666
↓ 1 callersMethodUnmarshalText
([]byte)
set_unmarshaler_test.go:103
↓ 1 callersMethodUnmarshalText
(text []byte)
benchmark_test.go:658
↓ 1 callersMethodaddTo
addTo adds w to x, after every entry above it that x does not hold yet. Each entry below scanDepth adds itself as it is checked, so the entries x lack
path.go:90
↓ 1 callersFunctionbenchFill
benchFill measures filling a zero T. The value is allocated once and reset in place before each Set, so allocs/op counts Set's allocations and not the
benchmark_test.go:533
↓ 1 callersFunctionbenchNestedValues
benchNestedValues builds depth structs nested by value, each holding the next as its first field. Only the innermost has a default. A []string at ever
benchmark_test.go:632
↓ 1 callersFunctionbenchRepeat
benchRepeat measures Set on a value it leaves as it is. The first Set fills ptr, and ready checks that the value is in the state the case measures.
benchmark_test.go:580
↓ 1 callersFunctionbenchTaggedChain
benchTaggedChain builds depth structs linked by pointers tagged `default:"{}"`, ending in a struct whose int has a default. Every level is a type of i
benchmark_test.go:647
↓ 1 callersFunctioncallSetter
(v interface{})
setter.go:17
↓ 1 callersFunctioncanHoldDefaults
canHoldDefaults reports whether a slice element or map value of type t is of a kind the walk descends into. Such a value has no tag of its own, so des
set.go:426
↓ 1 callersFunctionfillField
fillField is setField for a field it does not leave alone: it applies the tag if isInitial, which reports whether the field is zero, and descends into
set.go:143
↓ 1 callersMethodgrow
grow doubles x's room for entries and its buckets, as many of each and a power of two, and chains every entry again from the top down, so that each ch
path.go:179
↓ 1 callersFunctionhasPromotedSetter
hasPromotedSetter reports whether the SetDefaults of t, a struct type whose pointer implements Setter, is promoted from an embedded field rather than
setter.go:26
↓ 1 callersMethodrepeatsInIndex
repeatsInIndex is repeatsFar's check. It makes the path's index if the walk has none yet, adds to it every entry above w that it does not hold, and th
path.go:74
↓ 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
set.go:438
FunctionBenchmarkCanUpdate
BenchmarkCanUpdate measures the zero check on its own, which is what Set spends per field.
benchmark_test.go:78
FunctionBenchmarkFail
BenchmarkFail measures a Set that fails. The first error is checked, so each case measures the failure it names.
benchmark_test.go:492
FunctionBenchmarkParse
BenchmarkParse applies one tag to one zero field. unparsed_kind is the cost every other row includes: a tagged zero field with nothing parsed and noth
benchmark_test.go:129
FunctionBenchmarkSet
Every case calls b.ReportAllocs. A case that calls Set does its setup and checks the value it measures once before b.ResetTimer, and then does the sam
benchmark_test.go:25
FunctionBenchmarkWalk
BenchmarkWalk measures going through a value with little or nothing left to fill. Unless a case says otherwise, it runs Set again on a value the first
benchmark_test.go:260
FunctionExample
This example fills a tree of structs, pointers, slices and maps in one call. Every Endpoint the call reaches gets the same treatment wherever it sits:
example_test.go:42
FunctionExampleCanUpdate
()
example_test.go:142
FunctionExampleSet
()
example_test.go:75
FunctionExampleSet_nested
()
example_test.go:98
FunctionExampleSetter
()
example_test.go:124
MethodPing
()
method_test.go:21
MethodPing
()
method_test.go:26
MethodPing
()
method_test.go:45
MethodSetDefaults
()
set_cycle_test.go:18
MethodSetDefaults
()
set_unexported_test.go:17
MethodSetDefaults
()
setter_test.go:20
MethodSetDefaults
()
setter_test.go:29
MethodSetDefaults
()
setter_test.go:41
MethodSetDefaults
()
setter_test.go:51
MethodSetDefaults
()
setter_test.go:64
MethodSetDefaults
()
setter_test.go:76
MethodSetDefaults
()
setter_test.go:86
MethodSetDefaults
()
setter_test.go:96
MethodSetDefaults
()
set_unmarshaler_test.go:62
MethodSetDefaults
()
set_unmarshaler_test.go:76
MethodSetDefaults
SetDefaults derives a default that a tag cannot express, and CanUpdate keeps it from overriding what the caller already provided.
example_test.go:20
MethodSetDefaults
SetDefaults derives Addr from Host and Port, which the tags have filled by the time it is called.
example_test.go:34
MethodSetDefaults
()
set_shared_test.go:19
MethodSetDefaults
()
set_optout_test.go:20
MethodSetDefaults
()
set_optout_test.go:30
MethodSetDefaults
()
set_map_test.go:222
MethodSetDefaults
()
benchmark_test.go:692
FunctionTestCanUpdate
TestCanUpdate covers what "can update" means: the value still holds the zero value of its own type. Note that an allocated-but-empty slice or map is t
canupdate_test.go:15
FunctionTestCanUpdate_FloatEdges
TestCanUpdate_FloatEdges pins the two floats where a per-kind zero check and a comparison against the zero value could plausibly disagree: a negative
canupdate_test.go:62
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:82
FunctionTestIsPromotedMethod
TestIsPromotedMethod covers where the code behind a method comes from, which reflect reports alike for a method a type declares and one it takes from
method_test.go:54
FunctionTestMustSet_PanicsForInvalidTag
(t *testing.T)
mustset_test.go:64
FunctionTestMustSet_PanicsForNil
TestMustSet_PanicsForNil pins that a nil panics with Set's error. It used to panic too, but from inside Set, before there was an error to panic with.
mustset_test.go:46
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
FunctionTestPathIndex_AddHoldsEachKeyOnce
TestPathIndex_AddHoldsEachKeyOnce covers add's answer, which is the repeat: a key the index holds is not added again.
path_test.go:183
FunctionTestPathIndex_GrowingKeepsEachBucketDeepestFirst
TestPathIndex_GrowingKeepsEachBucketDeepestFirst covers the chains grow builds again. The deepest key of a bucket heads its chain, so taking it out mo
path_test.go:262
FunctionTestPathIndex_GrowsAndKeepsEveryKey
TestPathIndex_GrowsAndKeepsEveryKey covers growing past the room the index was made with, which a walk does a few hundred values down: every key is st
path_test.go:221
FunctionTestPathIndex_HoldsKeysThatShareABucket
TestPathIndex_HoldsKeysThatShareABucket covers the chain a bucket holds: keys that hash together are told apart, and taking one out leaves the others
path_test.go:244
FunctionTestPathIndex_PopTakesTheDeepestKeyOut
TestPathIndex_PopTakesTheDeepestKeyOut covers pop, which leave calls: the keys join and leave the index as their values do the path, so the one taken
path_test.go:200
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:148
FunctionTestSet_Bool
(t *testing.T)
set_scalar_test.go:58
FunctionTestSet_ByteSlice
TestSet_ByteSlice covers []byte, where encoding/json accepts two spellings and rejects bare text.
set_slice_test.go:167
FunctionTestSet_CallerPointerToContainerIsSkipped
TestSet_CallerPointerToContainerIsSkipped covers a pointer the caller allocated to a slice, a map or a pointer, as a field, a slice element and a map
set_pointer_test.go:152
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_CyclesEnd
TestSet_CyclesEnd covers data the caller built with a way back to itself. Where the walk comes back to a value it is still walking, Set goes no furthe
set_cycle_test.go:29
FunctionTestSet_CyclesEndAtAnyDepth
TestSet_CyclesEndAtAnyDepth covers cycles that close far down a long path. Set scans the path for a value near its top, but looks up a value further d
set_cycle_test.go:152
FunctionTestSet_Duration
(t *testing.T)
set_duration_test.go:14
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:44
FunctionTestSet_DurationEmptyTagReportsNothing
TestSet_DurationEmptyTagReportsNothing covers `default:""` on an int64-kinded field. Both parsers reject an empty tag, as they reject "1d", but it ask
set_duration_test.go:80
FunctionTestSet_DurationErrorNamesBothParsers
TestSet_DurationErrorNamesBothParsers covers an int64-kinded tag that neither parser takes. The error carries both rejections, the duration parser's f
set_duration_test.go:63
FunctionTestSet_DurationStringOnANarrowerIntegerIsRejected
TestSet_DurationStringOnANarrowerIntegerIsRejected pins that the duration fallback is int64-only. A narrower width rejects a duration string outright,
set_duration_test.go:95
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:117
FunctionTestSet_EmbeddedPointerStruct
(t *testing.T)
set_struct_test.go:94
next →1–100 of 250, ranked by callers