Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

golang interface function

type MathInterface interface {
	Added() int
	Subtract() int
}

type Math struct {
	x, y int
}

func (m *Math) Add() int {
	return m.x + m.y
}

func (m *Math) Subtract() int {
	return m.x - m.y
}

func main() {
	data := Math{}
	data.x = 5
	data.y = 3

	added := data.Add()
	subtract := data.Subtract()

	fmt.Println(added)
	fmt.Println(subtract)
}
Source by gowithgolang.com #
 
PREVIOUS NEXT
Tagged: #golang #interface #function
ADD COMMENT
Topic
Name
5+7 =