Syntax

Go Define an Interface Syntax

In Go, define an interface: describes behavior a type must have — type Shape interface { Area() float64 }

Quick Answer

Syntax
type Shape interface { Area() float64 }
GoSyntax

Define an Interface

Code example
type Shape interface { Area() float64 }

Describes behavior a type must have.

Learn More

How to define an interface in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Define an Interface Syntax

Use type Shape interface { Area() float64 }.

Related Syntax References

Frequently asked questions

What is the Go syntax for define an interface?

Use this pattern: type Shape interface { Area() float64 }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify