-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
50 lines (40 loc) · 850 Bytes
/
example.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
50
package main
import (
"net/http"
"tastyroot/api"
"tastyroot/resources"
)
type Cat struct {
Name string
Age int
Alive bool
}
func SimpleResourceExample() {
cats := []Cat{
{"Batman", 13, true},
{"Banana", 3, true},
{"Pong", 22, false},
}
cat := Cat{"Batman", 13, true}
cat_resource := &resources.SimpleResource{cat, "/cat"}
cats_resource := &resources.SimpleResource{cats, "/cats"}
api.Register(cat_resource)
api.Register(cats_resource)
}
func MongoResourceExample() {
// Test:
// curl -H "Content-Type: application/json" -d '{"id": 1,"ping":"pong"}' http://localhost:8000/cats/
cats_resource := resources.MongoResource(
"/cats/",
"127.0.0.1:27017",
"godb",
"cats",
10,
)
api.Register(cats_resource)
}
func main() {
// SimpleResourceExample()
MongoResourceExample()
http.ListenAndServe(":8000", nil)
}