-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
50 lines (37 loc) · 878 Bytes
/
server.go
File metadata and controls
50 lines (37 loc) · 878 Bytes
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"
"github.com/go-martini/martini"
"io/ioutil"
)
func main() {
m := martini.Classic()
bo,up := read_files()
m.Get("/box_office", func(writer http.ResponseWriter) string {
writer.Header().Set("Content-Type", "application/json")
return bo
})
m.Get("/upcoming_movies", func(writer http.ResponseWriter) string {
writer.Header().Set("Content-Type", "application/json")
return up
})
m.Get("/top_dvds", func() string {
return "Top DVDs"
})
m.Get("/upcoming_dvds", func() string {
return "Upcoming DVDs"
})
m.Run()
}
func check(e error) {
if e != nil {
panic(e)
}
}
func read_files() (string,string) {
bo, err := ioutil.ReadFile("responses/box_office.json")
check(err)
up, err := ioutil.ReadFile("responses/upcoming.json")
check(err)
return string(bo),string(up)
}