github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/internal/cli/yaml.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package cli 10 11 import ( 12 "io/ioutil" 13 14 "gopkg.in/yaml.v2" 15 ) 16 17 // WriteYAML writes _in_ data to a YAML file named by _filename_. 18 func WriteYAML(in interface{}, filename string) error { 19 out, err := yaml.Marshal(in) 20 if err != nil { 21 return err 22 } 23 return ioutil.WriteFile(filename, out, 0644) 24 } 25 26 // ReadYAML reads the file named by _filename and assigns the decoded YAML content into the _out_ value. 27 func ReadYAML(out interface{}, filename string) error { 28 b, err := ioutil.ReadFile(filename) 29 if err != nil { 30 return err 31 } 32 33 return yaml.Unmarshal(b, out) 34 }