Methods 

Let's say we wrote these functions, and we have defined email as before:

 type email string  func check(a email) { ... } func send(a email, msg string) { ... }

Observe that email is always the first type in the function parameters.

Calling the functions look something like this:

e := "john@smith.com"check(e)send(e, "Hello World")

We may want to make that into a method of the email type. We can do so as follows:

type email string func (e email) check() { ... }func (e email) send(msg string) { ... }

(e email) is called the receiver of the method.

Having defined the methods thus, we may then proceed to call them:

e := "john@smith.com"e.check()e.send("Hello World")

Observe the difference between the functions and methods. check(e) becomes ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.