The mechanism of runnable Go examples in pkg.go.dev

183 Views Asked by At

There have two examples:

  1. fun Marshal: You can see the example are not contain any button.

    source

    func ExampleMarshal() {
        type Item struct {
            Foo string
        }
    
        b, err := msgpack.Marshal(&Item{Foo: "bar"})
        if err != nil {
            panic(err)
        }
    
        var item Item
        err = msgpack.Unmarshal(b, &item)
        if err != nil {
            panic(err)
        }
        fmt.Println(item.Foo)
        // Output: bar
    }
    
  2. func Reverse well it has three buttons: Share, Format, Run

    source

    func ExampleReverse() {
        s := []int{5, 2, 6, 3, 1, 4} // unsorted
        sort.Sort(sort.Reverse(sort.IntSlice(s)))
        fmt.Println(s)
        // Output: [6 5 4 3 2 1]
    }
    

enter image description here

I don't understand why one has buttons, and the other doesn't? Does the content (godoc) rendered have anything to do with the version of Go used in the repository?

0

There are 0 best solutions below