# Methods

{% hint style="warning" %}
This page is under active revision, content may be updated without notice
{% endhint %}

In Go, Methods are similar to `func` except that they have a receiver to operate on. To get full\_name of a person we would love to define a method to `Person` struct like

```go
func(p Person) full_name() {
  fmt.Println(p.first_name, p.last_name)
}
p.full_name()
//=> "John Lego"
```

Well done Jack! But problem with this method is, it is printing `full_name` to standard output. But in real world we would need our `full_name` to return full name of a person. Here is how

```go
func(p Person) full_name() string {
  s := p.first_name + " " + p.last_name
  return s
}
fmt.Println(p.full_name())
//=> "John Lego"
```

Just FYI Jack, struct can also have embedded types, not just legacy types. Here is an example of struct `Employee`

```go
type Employee struct{
  Person
  employee_id string
}
```

Now to initilize it we need to follow same way, but first argument should be of type person, like

```go
e :=  Employee{Person{"Pankaj", "Bagwan", 26}, "emp101"}
fmt.Println(e.Person.full_name())
fmt.Println(e.full_name())
fmt.Println(e.employee_id)
```

Note that method defined on struct `Person` is alo available directly and indirectly to employee.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://golang.bagwanpankaj.com/methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
