mirror of
https://github.com/vbatts/talks.git
synced 2025-08-07 18:00:28 +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
24
2013/03-golang-learning-lunch/5-neats/main.go
Normal file
24
2013/03-golang-learning-lunch/5-neats/main.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
numbers := []int{1,7,3,8,2,4,5,4,9,0}
|
||||
|
||||
for i := range numbers {
|
||||
fmt.Printf("index: %d\n", i)
|
||||
}
|
||||
|
||||
for _, v := range numbers {
|
||||
fmt.Printf("value: %d\n", v)
|
||||
}
|
||||
|
||||
people := map[string]Person{}
|
||||
people["shawking"] = Person{ Name: "Stephen Hawking", State: LIVING}
|
||||
people["dritchie"] = Person{ Name: "Dennis Ritchie", State: DEAD}
|
||||
for k,v := range people {
|
||||
fmt.Printf("Key: %s; Object: %q\n", k, v)
|
||||
}
|
||||
|
||||
}
|
||||
|
34
2013/03-golang-learning-lunch/5-neats/person.go
Normal file
34
2013/03-golang-learning-lunch/5-neats/person.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"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
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue