Keyword

Go interface keyword

Describes a type set. Basic interfaces can be used as value types and are satisfied implicitly; interfaces with non-method type restrictions generally serve as constraints only. Example assigns a concrete value to an interface and calls its method.

Formal Syntax & Structure

go syntaxgo
interface { methodSpecs; embeddedElements }

Working Example

Example Snippetgo
package main
import "fmt"
type Labeler interface{ Label() string }type Item struct{}
func (Item) Label() string { return "item" }func main() {  var r Labeler = Item{}  fmt.Println(r.Label())}
Go Reference