forked from zenazn/goji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
49 lines (42 loc) · 1.31 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"io"
"time"
)
// A Greet is a 140-character micro-blogpost that has no resemblance whatsoever
// to the noise a bird makes.
type Greet struct {
User string `param:"user"`
Message string `param:"message"`
Time time.Time `param:"time"`
}
// Store all our greets in a big list in memory, because, let's be honest, who's
// actually going to use a service that only allows you to post 140-character
// messages?
var Greets = []Greet{
{"carl", "Welcome to Gritter!", time.Now()},
{"alice", "Wanna know a secret?", time.Now()},
{"bob", "Okay!", time.Now()},
{"eve", "I'm listening...", time.Now()},
}
// Write out a representation of the greet
func (g Greet) Write(w io.Writer) {
fmt.Fprintf(w, "%s\n@%s at %s\n---\n", g.Message, g.User,
g.Time.Format(time.UnixDate))
}
// A User is a person. It may even be someone you know. Or a rabbit. Hard to say
// from here.
type User struct {
Name, Bio string
}
// All the users we know about! There aren't very many...
var Users = map[string]User{
"alice": {"Alice in Wonderland", "Eating mushrooms"},
"bob": {"Bob the Builder", "Making children dumber"},
"carl": {"Carl Jackson", "Duct tape aficionado"},
}
// Write out the user
func (u User) Write(w io.Writer, handle string) {
fmt.Fprintf(w, "%s (@%s)\n%s\n", u.Name, handle, u.Bio)
}