Debian Codegraph @

yaml.go

raw symbols SCIP
1 // Package yaml implements YAML support for the Go language.
2 //
3 // Source code and other details for the project are available at GitHub:
4 //
5 // https://github.com/yaml/go-yaml
6 //
7 package yamlscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/
8
9 import (
10 "errorsscip-go gomod github.com/golang/go/src go1.15 errors/"
11 "fmtscip-go gomod github.com/golang/go/src go1.15 fmt/"
12 "ioscip-go gomod github.com/golang/go/src go1.15 io/"
13 "reflectscip-go gomod github.com/golang/go/src go1.15 reflect/"
14 "stringsscip-go gomod github.com/golang/go/src go1.15 strings/"
15 "syncscip-go gomod github.com/golang/go/src go1.15 sync/"
16 )
17
18 // MapSlice encodes and decodes as a YAML map.
19 // The order of keys is preserved when encoding and decoding.
20 type MapSlicescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/MapSlice# []MapItemscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/MapItem#
21
22 // MapItem is an item in a MapSlice.
23 type MapItemscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/MapItem# struct {
24 Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/MapItem#Key., Valuescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/MapItem#Value. interface{}
25 }
26
27 // The Unmarshaler interface may be implemented by types to customize their
28 // behavior when being unmarshaled from a YAML document. The UnmarshalYAML
29 // method receives a function that may be called to unmarshal the original
30 // YAML value into a field or variable. It is safe to call the unmarshal
31 // function parameter more than once if necessary.
32 type Unmarshalerscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Unmarshaler# interface {
33 UnmarshalYAMLscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Unmarshaler#UnmarshalYAML.(unmarshal func(interface{}) error) error
34 }
35
36 // The Marshaler interface may be implemented by types to customize their
37 // behavior when being marshaled into a YAML document. The returned value
38 // is marshaled in place of the original value implementing Marshaler.
39 //
40 // If an error is returned by MarshalYAML, the marshaling procedure stops
41 // and returns with the provided error.
42 type Marshalerscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Marshaler# interface {
43 MarshalYAMLscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Marshaler#MarshalYAML.() (interface{}, error)
44 }
45
46 // Unmarshal decodes the first document found within the in byte slice
47 // and assigns decoded values into the out value.
48 //
49 // Maps and pointers (to a struct, string, int, etc) are accepted as out
50 // values. If an internal pointer within a struct is not initialized,
51 // the yaml package will initialize it if necessary for unmarshalling
52 // the provided data. The out parameter must not be nil.
53 //
54 // The type of the decoded values should be compatible with the respective
55 // values in out. If one or more values cannot be decoded due to a type
56 // mismatches, decoding continues partially until the end of the YAML
57 // content, and a *yaml.TypeError is returned with details for all
58 // missed values.
59 //
60 // Struct fields are only unmarshalled if they are exported (have an
61 // upper case first letter), and are unmarshalled using the field name
62 // lowercased as the default key. Custom keys may be defined via the
63 // "yaml" name in the field tag: the content preceding the first comma
64 // is used as the key, and the following comma-separated options are
65 // used to tweak the marshalling process (see Marshal).
66 // Conflicting names result in a runtime error.
67 //
68 // For example:
69 //
70 // type T struct {
71 // F int `yaml:"a,omitempty"`
72 // B int
73 // }
74 // var t T
75 // yaml.Unmarshal([]byte("a: 1\nb: 2"), &t)
76 //
77 // See the documentation of Marshal for the format of tags and a list of
78 // supported tag options.
79 //
80 func Unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Unmarshal().(in []byte, out interface{}) (err error) {
81 return unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/unmarshal().(in, out, false)
82 }
83
84 // UnmarshalStrict is like Unmarshal except that any fields that are found
85 // in the data that do not have corresponding struct members, or mapping
86 // keys that are duplicates, will result in
87 // an error.
88 func UnmarshalStrictscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/UnmarshalStrict().(in []byte, out interface{}) (err error) {
89 return unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/unmarshal().(in, out, true)
90 }
91
92 // A Decoder reads and decodes YAML values from an input stream.
93 type Decoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder# struct {
94 strictscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#strict. bool
95 parserscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#parser. *parserscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parser#
96 }
97
98 // NewDecoder returns a new decoder that reads from r.
99 //
100 // The decoder introduces its own buffering and may read
101 // data from r beyond the YAML values requested.
102 func NewDecoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/NewDecoder().(r ioscip-go gomod github.com/golang/go/src go1.15 io/.Readerscip-go gomod github.com/golang/go/src go1.15 io/Reader#) *Decoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder# {
103 return &Decoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#{
104 parserscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#parser.: newParserFromReaderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newParserFromReader().(r),
105 }
106 }
107
108 // SetStrict sets whether strict decoding behaviour is enabled when
109 // decoding items in the data (see UnmarshalStrict). By default, decoding is not strict.
110 func (dec *Decoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#) SetStrictscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#SetStrict().(strict bool) {
111 dec.strictscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#strict. = strict
112 }
113
114 // Decode reads the next YAML-encoded value from its input
115 // and stores it in the value pointed to by v.
116 //
117 // See the documentation for Unmarshal for details about the
118 // conversion of YAML into a Go value.
119 func (dec *Decoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#) Decodescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#Decode().(v interface{}) (err error) {
120 d := newDecoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newDecoder().(dec.strictscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#strict.)
121 defer handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(&err)
122 node := dec.parserscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Decoder#parser..parsescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parser#parse().()
123 if node == nil {
124 return ioscip-go gomod github.com/golang/go/src go1.15 io/.EOFscip-go gomod github.com/golang/go/src go1.15 io/EOF.
125 }
126 out := reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(v)
127 if out.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. && !out.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() {
128 out = out.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().()
129 }
130 d.unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#unmarshal().(node, out)
131 if len(d.terrorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#terrors.) > 0 {
132 return &TypeErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#{d.terrorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#terrors.}
133 }
134 return nil
135 }
136
137 func unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/unmarshal().(in []byte, out interface{}, strict bool) (err error) {
138 defer handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(&err)
139 d := newDecoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newDecoder().(strict)
140 p := newParserscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newParser().(in)
141 defer p.destroyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parser#destroy().()
142 node := p.parsescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/parser#parse().()
143 if node != nil {
144 v := reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(out)
145 if v.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. && !v.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() {
146 v = v.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().()
147 }
148 d.unmarshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#unmarshal().(node, v)
149 }
150 if len(d.terrorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#terrors.) > 0 {
151 return &TypeErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#{d.terrorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/decoder#terrors.}
152 }
153 return nil
154 }
155
156 // Marshal serializes the value provided into a YAML document. The structure
157 // of the generated document will reflect the structure of the value itself.
158 // Maps and pointers (to struct, string, int, etc) are accepted as the in value.
159 //
160 // Struct fields are only marshalled if they are exported (have an upper case
161 // first letter), and are marshalled using the field name lowercased as the
162 // default key. Custom keys may be defined via the "yaml" name in the field
163 // tag: the content preceding the first comma is used as the key, and the
164 // following comma-separated options are used to tweak the marshalling process.
165 // Conflicting names result in a runtime error.
166 //
167 // The field tag format accepted is:
168 //
169 // `(...) yaml:"[<key>][,<flag1>[,<flag2>]]" (...)`
170 //
171 // The following flags are currently supported:
172 //
173 // omitempty Only include the field if it's not set to the zero
174 // value for the type or to empty slices or maps.
175 // Zero valued structs will be omitted if all their public
176 // fields are zero, unless they implement an IsZero
177 // method (see the IsZeroer interface type), in which
178 // case the field will be excluded if IsZero returns true.
179 //
180 // flow Marshal using a flow style (useful for structs,
181 // sequences and maps).
182 //
183 // inline Inline the field, which must be a struct or a map,
184 // causing all of its fields or keys to be processed as if
185 // they were part of the outer struct. For maps, keys must
186 // not conflict with the yaml keys of other struct fields.
187 //
188 // In addition, if the key is "-", the field is ignored.
189 //
190 // For example:
191 //
192 // type T struct {
193 // F int `yaml:"a,omitempty"`
194 // B int
195 // }
196 // yaml.Marshal(&T{B: 2}) // Returns "b: 2\n"
197 // yaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n"
198 //
199 func Marshalscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Marshal().(in interface{}) (out []byte, err error) {
200 defer handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(&err)
201 e := newEncoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newEncoder().()
202 defer e.destroyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#destroy().()
203 e.marshalDocscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#marshalDoc().("", reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(in))
204 e.finishscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#finish().()
205 out = e.outscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#out.
206 return
207 }
208
209 // An Encoder writes YAML values to an output stream.
210 type Encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder# struct {
211 encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#encoder. *encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#
212 }
213
214 // NewEncoder returns a new encoder that writes to w.
215 // The Encoder should be closed after use to flush all data
216 // to w.
217 func NewEncoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/NewEncoder().(w ioscip-go gomod github.com/golang/go/src go1.15 io/.Writerscip-go gomod github.com/golang/go/src go1.15 io/Writer#) *Encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder# {
218 return &Encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#{
219 encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#encoder.: newEncoderWithWriterscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/newEncoderWithWriter().(w),
220 }
221 }
222
223 // Encode writes the YAML encoding of v to the stream.
224 // If multiple items are encoded to the stream, the
225 // second and subsequent document will be preceded
226 // with a "---" document separator, but the first will not.
227 //
228 // See the documentation for Marshal for details about the conversion of Go
229 // values to YAML.
230 func (e *Encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#) Encodescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#Encode().(v interface{}) (err error) {
231 defer handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(&err)
232 e.encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#encoder..marshalDocscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#marshalDoc().("", reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(v))
233 return nil
234 }
235
236 // Close closes the encoder by writing any remaining data.
237 // It does not write a stream terminating string "...".
238 func (e *Encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#) Closescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#Close().() (err error) {
239 defer handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(&err)
240 e.encoderscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/Encoder#encoder..finishscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/encoder#finish().()
241 return nil
242 }
243
244 func handleErrscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/handleErr().(err *error) {
245 if v := recover(); v != nil {
246 if e, ok := v.(yamlErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError#); ok {
247 *err = e.errscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError#err.
248 } else {
249 panic(v)
250 }
251 }
252 }
253
254 type yamlErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError# struct {
255 errscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError#err. error
256 }
257
258 func failscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fail().(err error) {
259 panic(yamlErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError#{err})
260 }
261
262 func failfscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/failf().(format string, args ...interface{}) {
263 panic(yamlErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/yamlError#{fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.15 fmt/Errorf().("yaml: "+format, args...)})
264 }
265
266 // A TypeError is returned by Unmarshal when one or more fields in
267 // the YAML document cannot be properly decoded into the requested
268 // types. When this error is returned, the value is still
269 // unmarshaled partially.
270 type TypeErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError# struct {
271 Errorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#Errors. []string
272 }
273
274 func (e *TypeErrorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#) Errorscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#Error().() string {
275 return fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("yaml: unmarshal errors:\n %s", stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Joinscip-go gomod github.com/golang/go/src go1.15 strings/Join().(e.Errorsscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/TypeError#Errors., "\n "))
276 }
277
278 // --------------------------------------------------------------------------
279 // Maintain a mapping of keys to structure field indexes
280
281 // The code in this section was copied from mgo/bson.
282
283 // structInfo holds details for the serialization of fields of
284 // a given struct.
285 type structInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo# struct {
286 FieldsMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#FieldsMap. map[string]fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#
287 FieldsListscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#FieldsList. []fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#
288
289 // InlineMap is the number of the field in the struct that
290 // contains an ,inline map, or -1 if there's none.
291 InlineMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#InlineMap. int
292 }
293
294 type fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo# struct {
295 Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key. string
296 Numscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Num. int
297 OmitEmptyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#OmitEmpty. bool
298 Flowscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Flow. bool
299 // Id holds the unique field identifier, so we can cheaply
300 // check for field duplicates without maintaining an extra map.
301 Idscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Id. int
302
303 // Inline holds the field index if the field is part of an inlined struct.
304 Inlinescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Inline. []int
305 }
306
307 var structMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structMap. = make(map[reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Type#]*structInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#)
308 var fieldMapMutexscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldMapMutex. syncscip-go gomod github.com/golang/go/src go1.15 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#
309
310 func getStructInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/getStructInfo().(st reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Type#) (*structInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#, error) {
311 fieldMapMutexscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldMapMutex..RLockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RLock().()
312 sinfo, found := structMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structMap.[st]
313 fieldMapMutexscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldMapMutex..RUnlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#RUnlock().()
314 if found {
315 return sinfo, nil
316 }
317
318 n := st.NumFieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#NumField().()
319 fieldsMap := make(map[string]fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#)
320 fieldsList := make([]fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#, 0, n)
321 inlineMap := -1
322 for i := 0; i != n; i++ {
323 field := st.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Field().(i)
324 if field.PkgPathscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#PkgPath. != "" && !field.Anonymousscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Anonymous. {
325 continue // Private field
326 }
327
328 info := fieldInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#{Numscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Num.: i}
329
330 tag := field.Tagscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Tag..Getscip-go gomod github.com/golang/go/src go1.15 reflect/StructTag#Get().("yaml")
331 if tag == "" && stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Indexscip-go gomod github.com/golang/go/src go1.15 strings/Index().(string(field.Tagscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Tag.), ":") < 0 {
332 tag = string(field.Tagscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Tag.)
333 }
334 if tag == "-" {
335 continue
336 }
337
338 inline := false
339 fields := stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Splitscip-go gomod github.com/golang/go/src go1.15 strings/Split().(tag, ",")
340 if len(fields) > 1 {
341 for _, flag := range fields[1:] {
342 switch flag {
343 case "omitempty":
344 info.OmitEmptyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#OmitEmpty. = true
345 case "flow":
346 info.Flowscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Flow. = true
347 case "inline":
348 inline = true
349 default:
350 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().(fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("Unsupported flag %q in tag %q of type %s", flag, tag, st))
351 }
352 }
353 tag = fields[0]
354 }
355
356 if inline {
357 switch field.Typescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Type..Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Kind().() {
358 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Mapscip-go gomod github.com/golang/go/src go1.15 reflect/Map.:
359 if inlineMap >= 0 {
360 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().("Multiple ,inline maps in struct " + st.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/Type#String().())
361 }
362 if field.Typescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Type..Keyscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Key().() != reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.15 reflect/TypeOf().("") {
363 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().("Option ,inline needs a map with string keys in struct " + st.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/Type#String().())
364 }
365 inlineMap = info.Numscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Num.
366 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct.:
367 sinfo, err := getStructInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/getStructInfo().(field.Typescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Type.)
368 if err != nil {
369 return nil, err
370 }
371 for _, finfo := range sinfo.FieldsListscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#FieldsList. {
372 if _, found := fieldsMap[finfo.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key.]; found {
373 msg := "Duplicated key '" + finfo.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key. + "' in struct " + st.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/Type#String().()
374 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().(msg)
375 }
376 if finfo.Inlinescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Inline. == nil {
377 finfo.Inlinescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Inline. = []int{i, finfo.Numscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Num.}
378 } else {
379 finfo.Inlinescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Inline. = append([]int{i}, finfo.Inlinescip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Inline....)
380 }
381 finfo.Idscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Id. = len(fieldsList)
382 fieldsMap[finfo.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key.] = finfo
383 fieldsList = append(fieldsList, finfo)
384 }
385 default:
386 //return nil, errors.New("Option ,inline needs a struct value or map field")
387 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().("Option ,inline needs a struct value field")
388 }
389 continue
390 }
391
392 if tag != "" {
393 info.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key. = tag
394 } else {
395 info.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key. = stringsscip-go gomod github.com/golang/go/src go1.15 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.15 strings/ToLower().(field.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name.)
396 }
397
398 if _, found = fieldsMap[info.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key.]; found {
399 msg := "Duplicated key '" + info.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key. + "' in struct " + st.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/Type#String().()
400 return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().(msg)
401 }
402
403 info.Idscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Id. = len(fieldsList)
404 fieldsList = append(fieldsList, info)
405 fieldsMap[info.Keyscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldInfo#Key.] = info
406 }
407
408 sinfo = &structInfoscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#{
409 FieldsMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#FieldsMap.: fieldsMap,
410 FieldsListscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#FieldsList.: fieldsList,
411 InlineMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structInfo#InlineMap.: inlineMap,
412 }
413
414 fieldMapMutexscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldMapMutex..Lockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Lock().()
415 structMapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/structMap.[st] = sinfo
416 fieldMapMutexscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/fieldMapMutex..Unlockscip-go gomod github.com/golang/go/src go1.15 sync/RWMutex#Unlock().()
417 return sinfo, nil
418 }
419
420 // IsZeroer is used to check whether an object is zero to
421 // determine whether it should be omitted when marshaling
422 // with the omitempty flag. One notable implementation
423 // is time.Time.
424 type IsZeroerscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/IsZeroer# interface {
425 IsZeroscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/IsZeroer#IsZero.() bool
426 }
427
428 func isZeroscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/isZero().(v reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#) bool {
429 kind := v.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().()
430 if z, ok := v.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().().(IsZeroerscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/IsZeroer#); ok {
431 if (kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. || kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Interface.) && v.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() {
432 return true
433 }
434 return z.IsZeroscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/IsZeroer#IsZero.()
435 }
436 switch kind {
437 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/String.:
438 return len(v.Stringscip-go gomod github.com/golang/go/src go1.15 reflect/Value#String().()) == 0
439 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Interface., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr.:
440 return v.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().()
441 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Slicescip-go gomod github.com/golang/go/src go1.15 reflect/Slice.:
442 return v.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() == 0
443 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Mapscip-go gomod github.com/golang/go/src go1.15 reflect/Map.:
444 return v.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() == 0
445 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Intscip-go gomod github.com/golang/go/src go1.15 reflect/Int., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Int8scip-go gomod github.com/golang/go/src go1.15 reflect/Int8., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Int16scip-go gomod github.com/golang/go/src go1.15 reflect/Int16., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Int32scip-go gomod github.com/golang/go/src go1.15 reflect/Int32., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Int64scip-go gomod github.com/golang/go/src go1.15 reflect/Int64.:
446 return v.Intscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Int().() == 0
447 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Float32scip-go gomod github.com/golang/go/src go1.15 reflect/Float32., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Float64scip-go gomod github.com/golang/go/src go1.15 reflect/Float64.:
448 return v.Floatscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Float().() == 0
449 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uintscip-go gomod github.com/golang/go/src go1.15 reflect/Uint., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uint8scip-go gomod github.com/golang/go/src go1.15 reflect/Uint8., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uint16scip-go gomod github.com/golang/go/src go1.15 reflect/Uint16., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uint32scip-go gomod github.com/golang/go/src go1.15 reflect/Uint32., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uint64scip-go gomod github.com/golang/go/src go1.15 reflect/Uint64., reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Uintptrscip-go gomod github.com/golang/go/src go1.15 reflect/Uintptr.:
450 return v.Uintscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Uint().() == 0
451 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Boolscip-go gomod github.com/golang/go/src go1.15 reflect/Bool.:
452 return !v.Boolscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Bool().()
453 case reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct.:
454 vt := v.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().()
455 for i := v.NumFieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#NumField().() - 1; i >= 0; i-- {
456 if vt.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Field().(i).PkgPathscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#PkgPath. != "" {
457 continue // Private field
458 }
459 if !isZeroscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/isZero().(v.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i)) {
460 return false
461 }
462 }
463 return true
464 }
465 return false
466 }
467
468 // FutureLineWrap globally disables line wrapping when encoding long strings.
469 // This is a temporary and thus deprecated method introduced to faciliate
470 // migration towards v3, which offers more control of line lengths on
471 // individual encodings, and has a default matching the behavior introduced
472 // by this function.
473 //
474 // The default formatting of v2 was erroneously changed in v2.3.0 and reverted
475 // in v2.4.0, at which point this function was introduced to help migration.
476 func FutureLineWrapscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/FutureLineWrap().() {
477 disableLineWrappingscip-go gomod go.yaml.in/yaml/v2 . `go.yaml.in/yaml/v2`/disableLineWrapping. = true
478 }