forked from emilpriver/language-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 665 Bytes
/
main.go
File metadata and controls
42 lines (34 loc) · 665 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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
func getRoot(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello from GO!\n")
}
func getJson(w http.ResponseWriter, r *http.Request) {
p := R{
Message: "Hello from Go!",
}
b, err := json.Marshal(p)
if err != nil {
io.WriteString(w, "Boomer")
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(b)
}
type R struct {
Message string `json:"message"`
}
func main() {
http.HandleFunc("/", getRoot)
http.HandleFunc("/json", getJson)
err := http.ListenAndServe(":3000", nil)
if err != nil {
panic(err)
}
fmt.Println("Listening on port 3000")
}