this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/encoding: use encoding/yaml rather than pkg/encoding/yaml

The latter is meant to provide builtins for CUE packages, and not
really to be used to encode and decode between CUE and YAML in Go code.

Right now both behave the same, so this change does not alter behavior
in any way for cmd/cue or cue/load users.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia9a15f336679e7d46353819d6a59e4f49f4c3607
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199701
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+11 -8
+1
cmd/cue/cmd/import.go
··· 596 596 return nil, "" 597 597 } 598 598 599 + // TODO(mvdan): move from pkg/encoding/yaml to encoding/yaml. 599 600 if expr, err := pkgyaml.Unmarshal(b); err == nil { 600 601 switch expr.(type) { 601 602 case *ast.StructLit, *ast.ListLit:
+5 -5
cue/testdata/gen.go
··· 33 33 cueast "cuelang.org/go/cue/ast" 34 34 cueformat "cuelang.org/go/cue/format" 35 35 "cuelang.org/go/cue/parser" 36 + "cuelang.org/go/encoding/yaml" 36 37 "cuelang.org/go/internal" 37 38 internaljson "cuelang.org/go/internal/encoding/json" 38 - "cuelang.org/go/pkg/encoding/yaml" 39 39 "cuelang.org/go/tools/fix" 40 40 ) 41 41 ··· 298 298 cue.Docs(true), 299 299 cue.Attributes(true))) 300 300 301 - s, err := yaml.Marshal(v) 301 + encYAML, err := yaml.Encode(v) 302 302 if err != nil { 303 303 fmt.Fprintln(e.header, "#bug: true") 304 304 e.warnf("Could not encode as YAML: %v", err) 305 305 } 306 306 e.a.Files = append(e.a.Files, 307 - txtar.File{Name: "out/yaml", Data: []byte(s)}) 307 + txtar.File{Name: "out/yaml", Data: encYAML}) 308 308 309 - b, err := internaljson.Marshal(v) 309 + encJSON, err := internaljson.Marshal(v) 310 310 if err != nil { 311 311 fmt.Fprintln(e.header, "#bug: true") 312 312 e.warnf("Could not encode as JSON: %v", err) 313 313 } 314 314 e.a.Files = append(e.a.Files, 315 - txtar.File{Name: "out/json", Data: b}) 315 + txtar.File{Name: "out/json", Data: encJSON}) 316 316 } 317 317 } 318 318
+1
encoding/yaml/yaml.go
··· 109 109 // Validate validates the YAML and confirms it matches the constraints 110 110 // specified by v. For YAML streams, all values must match v. 111 111 func Validate(b []byte, v cue.Value) error { 112 + // TODO(mvdan): encoding/yaml should not import pkg/encoding/yaml. 112 113 _, err := pkgyaml.Validate(b, v) 113 114 return err 114 115 }
+4 -3
internal/encoding/encoder.go
··· 33 33 "cuelang.org/go/encoding/protobuf/jsonpb" 34 34 "cuelang.org/go/encoding/protobuf/textproto" 35 35 "cuelang.org/go/encoding/toml" 36 + "cuelang.org/go/encoding/yaml" 36 37 "cuelang.org/go/internal" 37 38 "cuelang.org/go/internal/filetypes" 38 - "cuelang.org/go/pkg/encoding/yaml" 39 39 ) 40 40 41 41 // An Encoder converts CUE to various file formats, including CUE itself. ··· 182 182 case build.YAML: 183 183 e.concrete = true 184 184 streamed := false 185 + // TODO(mvdan): use a NewEncoder API like in TOML below. 185 186 e.encValue = func(v cue.Value) error { 186 187 if streamed { 187 188 fmt.Fprintln(w, "---") 188 189 } 189 190 streamed = true 190 191 191 - str, err := yaml.Marshal(v) 192 + b, err := yaml.Encode(v) 192 193 if err != nil { 193 194 return err 194 195 } 195 - _, err = fmt.Fprint(w, str) 196 + _, err = w.Write(b) 196 197 return err 197 198 } 198 199