Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / Structs

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:09:37Z

Updated

2019-03-26T10:09:37Z

package main

import (
	"fmt"
)

// Person describes a person
type Person struct {
	FirstName string
	LastName  string
}

// FullName returns full name of a person
func (p *Person) FullName() string {
	return fmt.Sprintf("%s %s", p.FirstName, p.LastName)
}

func main() {
	// zero value of struct
	var p Person
	fmt.Printf("p: %v\n\n", p)

	p = Person{
		FirstName: "John",
		LastName:  "Doe",
	}
	fmt.Printf("p: %v\n\n", p)

	// call a method on a struct
	fmt.Printf("p.FullName(): %s\n", p.FullName())
}
INFO