Ubuntu Pastebin

Paste from rog at Fri, 16 Oct 2015 14:02:26 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"fmt"
	"log"
	"gopkg.in/yaml.v2"
)

func main() {
	t := T{99}
	data, err := yaml.Marshal(t)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", data)
}

type T struct {
	X int
}

func (t T) MarshalYAML() (interface{}, error) {
	log.Printf("in T.MarshalYAML %#v", t)
	return S{t.X}, nil
}

type S struct {
	Y int
}

func (s S) MarshalYAML() (interface{}, error) {
	log.Printf("in S.MarshalYAML %#v", s)
	return "something", nil
}
Download as text