mirror of
https://github.com/vbatts/talks.git
synced 2025-05-23 21:32:31 +00:00
2013-03: adding an old learning lunch
This commit is contained in:
parent
68f582d393
commit
24cea0199b
17 changed files with 718 additions and 0 deletions
46
2013/03-golang-learning-lunch/4-struct-func/main.go
Normal file
46
2013/03-golang-learning-lunch/4-struct-func/main.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
IN_UTERO = iota
|
||||
NEW_BORN
|
||||
GROWING
|
||||
LIVING
|
||||
DYING
|
||||
DEAD
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
Dob *time.Time
|
||||
State byte
|
||||
}
|
||||
|
||||
func (p *Person) DobString() string {
|
||||
if (p.Dob == nil) {
|
||||
return ""
|
||||
}
|
||||
return p.Dob.String()
|
||||
}
|
||||
|
||||
func (p *Person) ComeToLife() {
|
||||
t := time.Now()
|
||||
p.Dob = &t
|
||||
p.State = NEW_BORN
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
// START OMIT
|
||||
p := Person{Name: "John Doe", State: IN_UTERO}
|
||||
fmt.Printf("%s, %s\n", p.Name, p.DobString())
|
||||
|
||||
p.ComeToLife()
|
||||
fmt.Printf("%s, %s\n", p.Name, p.DobString())
|
||||
// STOP OMIT
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue