| 1 | package yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.21.0 context/" |
| 5 | "ioscip-go gomod github.com/golang/go/src go1.21.0 io/" |
| 6 | "reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/" |
| 7 | |
| 8 | "github.com/goccy/go-yaml/astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/" |
| 9 | ) |
| 10 | |
| 11 | // DecodeOption functional option type for Decoder |
| 12 | type DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error |
| 13 | |
| 14 | // ReferenceReaders pass to Decoder that reference to anchor defined by passed readers |
| 15 | func ReferenceReadersscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceReaders().(readers ...ioscip-go gomod github.com/golang/go/src go1.21.0 io/.Readerscip-go gomod github.com/golang/go/src go1.21.0 io/Reader#) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 16 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 17 | d.referenceReadersscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#referenceReaders. = append(d.referenceReadersscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#referenceReaders., readers...) |
| 18 | return nil |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | // ReferenceFiles pass to Decoder that reference to anchor defined by passed files |
| 23 | func ReferenceFilesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceFiles().(files ...string) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 24 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 25 | d.referenceFilesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#referenceFiles. = files |
| 26 | return nil |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // ReferenceDirs pass to Decoder that reference to anchor defined by files under the passed dirs |
| 31 | func ReferenceDirsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceDirs().(dirs ...string) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 32 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 33 | d.referenceDirsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#referenceDirs. = dirs |
| 34 | return nil |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // RecursiveDir search yaml file recursively from passed dirs by ReferenceDirs option |
| 39 | func RecursiveDirscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/RecursiveDir().(isRecursive bool) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 40 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 41 | d.isRecursiveDirscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#isRecursiveDir. = isRecursive |
| 42 | return nil |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // Validator set StructValidator instance to Decoder |
| 47 | func Validatorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Validator().(v StructValidatorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/StructValidator#) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 48 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 49 | d.validatorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#validator. = v |
| 50 | return nil |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Strict enable DisallowUnknownField |
| 55 | func Strictscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Strict().() DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 56 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 57 | d.disallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#disallowUnknownField. = true |
| 58 | return nil |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // DisallowUnknownField causes the Decoder to return an error when the destination |
| 63 | // is a struct and the input contains object keys which do not match any |
| 64 | // non-ignored, exported fields in the destination. |
| 65 | func DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DisallowUnknownField().() DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 66 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 67 | d.disallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#disallowUnknownField. = true |
| 68 | return nil |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // AllowDuplicateMapKey ignore syntax error when mapping keys that are duplicates. |
| 73 | func AllowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/AllowDuplicateMapKey().() DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 74 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 75 | d.allowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#allowDuplicateMapKey. = true |
| 76 | return nil |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // UseOrderedMap can be interpreted as a map, |
| 81 | // and uses MapSlice ( ordered map ) aggressively if there is no type specification |
| 82 | func UseOrderedMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseOrderedMap().() DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 83 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 84 | d.useOrderedMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#useOrderedMap. = true |
| 85 | return nil |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // UseJSONUnmarshaler if neither `BytesUnmarshaler` nor `InterfaceUnmarshaler` is implemented |
| 90 | // and `UnmashalJSON([]byte)error` is implemented, convert the argument from `YAML` to `JSON` and then call it. |
| 91 | func UseJSONUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseJSONUnmarshaler().() DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 92 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 93 | d.useJSONUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#useJSONUnmarshaler. = true |
| 94 | return nil |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // CustomUnmarshaler overrides any decoding process for the type specified in generics. |
| 99 | // |
| 100 | // NOTE: If RegisterCustomUnmarshaler and CustomUnmarshaler of DecodeOption are specified for the same type, |
| 101 | // the CustomUnmarshaler specified in DecodeOption takes precedence. |
| 102 | func CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[T any](unmarshaler func(*T, []byte) error) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 103 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 104 | var typ *T |
| 105 | d.customUnmarshalerMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#customUnmarshalerMap.[reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/TypeOf().(typ)] = func(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, v interface{}, b []byte) error { |
| 106 | return unmarshaler(v.(*T), b) |
| 107 | } |
| 108 | return nil |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // CustomUnmarshalerContext overrides any decoding process for the type specified in generics. |
| 113 | // Similar to CustomUnmarshaler, but allows passing a context to the unmarshaler function. |
| 114 | func CustomUnmarshalerContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshalerContext().[T any](unmarshaler func(contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, *T, []byte) error) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 115 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 116 | var typ *T |
| 117 | d.customUnmarshalerMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#customUnmarshalerMap.[reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/TypeOf().(typ)] = func(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, v interface{}, b []byte) error { |
| 118 | return unmarshaler(ctx, v.(*T), b) |
| 119 | } |
| 120 | return nil |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // EncodeOption functional option type for Encoder |
| 125 | type EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error |
| 126 | |
| 127 | // Indent change indent number |
| 128 | func Indentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Indent().(spaces int) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 129 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 130 | e.indentNumscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#indentNum. = spaces |
| 131 | return nil |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // IndentSequence causes sequence values to be indented the same value as Indent |
| 136 | func IndentSequencescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/IndentSequence().(indent bool) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 137 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 138 | e.indentSequencescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#indentSequence. = indent |
| 139 | return nil |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // UseSingleQuote determines if single or double quotes should be preferred for strings. |
| 144 | func UseSingleQuotescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseSingleQuote().(sq bool) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 145 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 146 | e.singleQuotescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#singleQuote. = sq |
| 147 | return nil |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Flow encoding by flow style |
| 152 | func Flowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Flow().(isFlowStyle bool) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 153 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 154 | e.isFlowStylescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#isFlowStyle. = isFlowStyle |
| 155 | return nil |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // WithSmartAnchor when multiple map values share the same pointer, |
| 160 | // an anchor is automatically assigned to the first occurrence, and aliases are used for subsequent elements. |
| 161 | // The map key name is used as the anchor name by default. |
| 162 | // If key names conflict, a suffix is automatically added to avoid collisions. |
| 163 | // This is an experimental feature and cannot be used simultaneously with anchor tags. |
| 164 | func WithSmartAnchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/WithSmartAnchor().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 165 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 166 | e.enableSmartAnchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#enableSmartAnchor. = true |
| 167 | return nil |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // UseLiteralStyleIfMultiline causes encoding multiline strings with a literal syntax, |
| 172 | // no matter what characters they include |
| 173 | func UseLiteralStyleIfMultilinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseLiteralStyleIfMultiline().(useLiteralStyleIfMultiline bool) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 174 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 175 | e.useLiteralStyleIfMultilinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#useLiteralStyleIfMultiline. = useLiteralStyleIfMultiline |
| 176 | return nil |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // JSON encode in JSON format |
| 181 | func JSONscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/JSON().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 182 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 183 | e.isJSONStylescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#isJSONStyle. = true |
| 184 | e.isFlowStylescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#isFlowStyle. = true |
| 185 | return nil |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // MarshalAnchor call back if encoder find an anchor during encoding |
| 190 | func MarshalAnchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MarshalAnchor().(callback func(*astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.AnchorNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/AnchorNode#, interface{}) error) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 191 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 192 | e.anchorCallbackscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#anchorCallback. = callback |
| 193 | return nil |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // UseJSONMarshaler if neither `BytesMarshaler` nor `InterfaceMarshaler` |
| 198 | // nor `encoding.TextMarshaler` is implemented and `MarshalJSON()([]byte, error)` is implemented, |
| 199 | // call `MarshalJSON` to convert the returned `JSON` to `YAML` for processing. |
| 200 | func UseJSONMarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseJSONMarshaler().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 201 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 202 | e.useJSONMarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#useJSONMarshaler. = true |
| 203 | return nil |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // CustomMarshaler overrides any encoding process for the type specified in generics. |
| 208 | // |
| 209 | // NOTE: If type T implements MarshalYAML for pointer receiver, the type specified in CustomMarshaler must be *T. |
| 210 | // If RegisterCustomMarshaler and CustomMarshaler of EncodeOption are specified for the same type, |
| 211 | // the CustomMarshaler specified in EncodeOption takes precedence. |
| 212 | func CustomMarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomMarshaler().[T any](marshaler func(T) ([]byte, error)) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 213 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 214 | var typ T |
| 215 | e.customMarshalerMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#customMarshalerMap.[reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/TypeOf().(typ)] = func(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, v interface{}) ([]byte, error) { |
| 216 | return marshaler(v.(T)) |
| 217 | } |
| 218 | return nil |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // CustomMarshalerContext overrides any encoding process for the type specified in generics. |
| 223 | // Similar to CustomMarshaler, but allows passing a context to the marshaler function. |
| 224 | func CustomMarshalerContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomMarshalerContext().[T any](marshaler func(contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, T) ([]byte, error)) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 225 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 226 | var typ T |
| 227 | e.customMarshalerMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#customMarshalerMap.[reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/TypeOf().(typ)] = func(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, v interface{}) ([]byte, error) { |
| 228 | return marshaler(ctx, v.(T)) |
| 229 | } |
| 230 | return nil |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // AutoInt automatically converts floating-point numbers to integers when the fractional part is zero. |
| 235 | // For example, a value of 1.0 will be encoded as 1. |
| 236 | func AutoIntscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/AutoInt().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 237 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 238 | e.autoIntscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#autoInt. = true |
| 239 | return nil |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // OmitEmpty behaves in the same way as the interpretation of the omitempty tag in the encoding/json library. |
| 244 | // set on all the fields. |
| 245 | // In the current implementation, the omitempty tag is not implemented in the same way as encoding/json, |
| 246 | // so please specify this option if you expect the same behavior. |
| 247 | func OmitEmptyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/OmitEmpty().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 248 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 249 | e.omitEmptyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#omitEmpty. = true |
| 250 | return nil |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // OmitZero forces the encoder to assume an `omitzero` struct tag is |
| 255 | // set on all the fields. See `Marshal` commentary for the `omitzero` tag logic. |
| 256 | func OmitZeroscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/OmitZero().() EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 257 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 258 | e.omitZeroscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#omitZero. = true |
| 259 | return nil |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // CommentPosition type of the position for comment. |
| 264 | type CommentPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition# int |
| 265 | |
| 266 | const ( |
| 267 | CommentHeadPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentHeadPosition. CommentPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition# = CommentPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition#(iota) |
| 268 | CommentLinePositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentLinePosition. |
| 269 | CommentFootPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentFootPosition. |
| 270 | ) |
| 271 | |
| 272 | func (p CommentPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition#) Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition#String().() string { |
| 273 | switch p { |
| 274 | case CommentHeadPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentHeadPosition.: |
| 275 | return "Head" |
| 276 | case CommentLinePositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentLinePosition.: |
| 277 | return "Line" |
| 278 | case CommentFootPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentFootPosition.: |
| 279 | return "Foot" |
| 280 | default: |
| 281 | return "" |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // LineComment create a one-line comment for CommentMap. |
| 286 | func LineCommentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/LineComment().(text string) *Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment# { |
| 287 | return &Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#{ |
| 288 | Textsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Texts.: []string{text}, |
| 289 | Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Position.: CommentLinePositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentLinePosition., |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // HeadComment create a multiline comment for CommentMap. |
| 294 | func HeadCommentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/HeadComment().(texts ...string) *Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment# { |
| 295 | return &Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#{ |
| 296 | Textsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Texts.: texts, |
| 297 | Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Position.: CommentHeadPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentHeadPosition., |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // FootComment create a multiline comment for CommentMap. |
| 302 | func FootCommentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FootComment().(texts ...string) *Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment# { |
| 303 | return &Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#{ |
| 304 | Textsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Texts.: texts, |
| 305 | Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Position.: CommentFootPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentFootPosition., |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // Comment raw data for comment. |
| 310 | type Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment# struct { |
| 311 | Textsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Texts. []string |
| 312 | Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#Position. CommentPositionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentPosition# |
| 313 | } |
| 314 | |
| 315 | // CommentMap map of the position of the comment and the comment information. |
| 316 | type CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap# map[string][]*Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment# |
| 317 | |
| 318 | // WithComment add a comment using the location and text information given in the CommentMap. |
| 319 | func WithCommentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/WithComment().(cm CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap#) EncodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/EncodeOption# { |
| 320 | return func(e *Encoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#) error { |
| 321 | commentMap := map[*Pathscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Path#][]*Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Comment#{} |
| 322 | for k, v := range cm { |
| 323 | path, err := PathStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/PathString().(k) |
| 324 | if err != nil { |
| 325 | return err |
| 326 | } |
| 327 | commentMap[path] = v |
| 328 | } |
| 329 | e.commentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Encoder#commentMap. = commentMap |
| 330 | return nil |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // CommentToMap apply the position and content of comments in a YAML document to a CommentMap. |
| 335 | func CommentToMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentToMap().(cm CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap#) DecodeOptionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DecodeOption# { |
| 336 | return func(d *Decoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#) error { |
| 337 | if cm == nil { |
| 338 | return ErrInvalidCommentMapValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ErrInvalidCommentMapValue. |
| 339 | } |
| 340 | d.toCommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#toCommentMap. = cm |
| 341 | return nil |
| 342 | } |
| 343 | } |