LoginSignup
4
4

More than 5 years have passed since last update.

go でmapや配列等を pretty print (var_dumpみたいな何か)と yaml の読み込み

Posted at

yamlは、https://godoc.org/launchpad.net/goyaml を、
pretty printは http://godoc.org/github.com/kr/pretty を使えばいい感じです。

config
mail_from: masahide.y@gmail.com
to: [masahide.y@gmail.com]
var:
  c: 2
  d: [3, 4]
example.go
    m := make(map[interface{}]interface{})
    err = goyaml.Unmarshal([]byte(config), &m)
    if err != nil {
        panic(err)
    }
    //fmt.Printf("--- m:\n%# v\n\n", m)
    pretty.Printf("--- m:\n%# v\n\n", m)
$ go run main.go
--- m:
map[interface {}]interface {}{
    "mail_from": "masahide.y@gmail.com",
    "to":        []interface {}{
        "masahide.y@gmail.com",
    },
    "var": map[interface {}]interface {}{
        "c": int(2),
        "d": []interface {}{
            int(3),
            int(4),
        },
    },
}
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4