structs

structs are a collection of named elements which contain name and a data type

keyword struct is used

syntax:

struct {

	fields
	
}

example:

type Rectangle struct {
	Width  float64
	Height float64
}

types

type keyword is used to create our own types or new types

syntax: type TypeName underlyingType

in the struct example given above we are creating a new type named Rectangle whose underlying type is struct with width and height fields

Methods

methods are functions that are associated with a specific type

When we call t.Errorf we are calling the method Errorf on the instance of our t (testing.T)

syntax:

func (Receiver receiverType) methodName(parameters) returnType {
    // method implementation
}