til 10

structs in go

type person struct {
    first string
    last string
    age int
    }

it’s possible to embed structs into other structs

type employee struct {
    person
    employee_id int
    salary int
}

we instantiate the employee type like

 var e := employee {
     person: person{
        first: "Ali",
        last: "Yeşil",
        age: 33, },
    employee_id: 001,
    salary: 4500,
    }

and we can access fields of embedded structs as if they are fields of the outer struct

e.first = e.person.first

One can also use anonymous structs without defining a type

var z := struct {
    a string
    b int }
    {a : "aaa",
    b: 123}

if these won’t be used otherwise, we simply keep the code clean

/struct/ /anonymous struct/ /embedded struct/ /golang/