package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	backed()
	empty()
}

// section: content

// section: type
type Stream struct {
	io.Writer
}

// section: type

func backed() {
	// section: backed
	s := Stream{
		Writer: os.Stdout,
	}
	fmt.Fprintf(s, "Hello Gophers!")

	// section: backed
}

func empty() {
	// section: empty
	s := Stream{}
	fmt.Fprintf(s, "Hello Gophers!")

	// section: empty
}

/*
// section: panic
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x109e92e]

goroutine 1 [running]:
main.(*Stream).Write(0xc00008e1f0, 0xc0000b2010, 0xe, 0x10, 0x0, 0x0, 0xc00008e1f0)
        <autogenerated>:1 +0x2e
fmt.Fprintf(0x10ebd20, 0xc00008e1f0, 0x10cf8da, 0xe, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0)
        /usr/local/Cellar/go/1.14.1/libexec/src/fmt/print.go:205 +0xa5
main.empty(...)
        /Users/corylanou/projects/gopherguides/learn/_training/fundamentals/interfaces/src/zero-backed.go:36
main.main()
        /Users/corylanou/projects/gopherguides/learn/_training/fundamentals/interfaces/src/zero-backed.go:11 +0xf1
exit status 2
// section: panic
*/
