Sorry, I thought I can send code with proper line breaks.
I will write code again with showing error. Also, I tried to make 
code simpler.
 
invalid.yaml
 namespace: aaaa
name: bbb
  description: ccccc
format::
  type: sample
  file: foo.sh

main.go
package main

import (
"fmt"
"io/ioutil"
"os"

yaml "gopkg.in/yaml.v2"
)

type Sample struct {
Namespace   string `yaml:"namespace"`
Name        string `yaml:"name"`
Description string `yaml:"description"`
Format      struct {
Type string `yaml:"type"`
File string `yaml:"file"`
} `yaml:"format"`
}

const (
invalidYaml = "./invalid.yaml"
)

func main() {
data, err := ioutil.ReadFile(invalidYaml)
if err != nil {
os.Exit(1)
}
sample := &Sample{}
err = yaml.Unmarshal(data, sample)
fmt.Printf("%v", err)
}


Expect to see
  osX
    <nil>

  linux
    <nil>

 or

  osX

    yaml: line 1: did not find expected <document start>

  linux

    yaml: line 1: did not find expected <document start>

See instead

osX yaml: line 1: did not find expected <document start>

  linux

    <nil>


Sorry Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to