« Back to Index

Go: call method directly via method expressions

View original Gist on GitHub

Tags: #go #expressions

main.go

// https://play.golang.com/p/iPOOcSzZCe7

package main

import (
	"fmt"
)

type Foo struct {
	Bar string
}

func (f Foo) String() string {
	return f.Bar + " stuff happens"
}

func main() {
	f := Foo{Bar: "Baz"}
	fmt.Println(Foo.String(f))
}