Go type assertion with interface 不明白它是怎么做到的

Go type assertion with interface don't understand how does it

我正在阅读 "Go Bootcamp",第 3 章第 20 页中有一个示例我无法理解。在此示例中,在 printString(s) 行中,s 是 fakeString 类型的变量,但在 switch 中,进入 "Stringer" 情况。我试图了解这怎么可能。任何帮助,将不胜感激。

密码是:

package main
import "fmt"

type Stringer interface {
   String() string
}
type fakeString struct {
   content string
}
// function used to implement the Stringer interface
func (s *fakeString) String() string {
    return s.content
}
func printString(value interface{}) {
    switch str := value.(type) {
        case string:
            fmt.Println(str)
        case Stringer:
            fmt.Println(str.String())
    }
}
func main() {
    s := &fakeString{"Ceci n'est pas un string"}
    printString(s)
    printString("Hello, Gophers")
}

因为fakeString与string是不同的类型,但是它实现了Stringer接口。每个具有给定功能的类型都实现了该类型。 fakeString 包含 String() 函数,因此它也实现了 Stringer 接口。这是围棋的某种基石。

查看Reader接口的内建库,一般都是作为例子给出的。