Source File: ex16/main.go

package main

import (
    "fmt"
)

type Animal struct {
    Name string
    Age int
    Species string
    Weight float64
}

func PrintAnimal(who Animal) {
    // you can pass your structs directly to Println
    fmt.Println("Your Pet:", who)
}

func main() {
    frankie := Animal{"Fankie", 5, "Dog", 20.5};

    // access a field in a struct with .
    fmt.Println("Name:", frankie.Name);

    PrintAnimal(frankie)

    // change a field by assigning to it
    frankie.Weight = 25.6
    fmt.Println("Your Pet Gained Weight:", frankie)

    // make a copy of a struct
    miss_snuffles := frankie

    // test if they're equal
    if(miss_snuffles == frankie) {
        // change it with the . and =
        miss_snuffles.Name = "Miss Snuffles"
        miss_snuffles.Species = "Cat"
        miss_snuffles.Weight = 4.0
    }

    // pass structs to functions
    PrintAnimal(frankie)
    PrintAnimal(miss_snuffles)
}