-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathmain.go
51 lines (40 loc) · 928 Bytes
/
main.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
51
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type whoami struct {
Name string
Title string
State string
}
func main() {
request1()
}
func whoAmI(response http.ResponseWriter, r *http.Request) {
who := []whoami{
whoami{Name: "Michael Levan",
Title: "Kubernetes Engineer",
State: "NJ",
},
}
json.NewEncoder(response).Encode(who)
fmt.Println("Endpoint Hit", who)
}
func homePage(response http.ResponseWriter, r *http.Request) {
fmt.Fprintf(response, "Welcome to the Go Web API!")
fmt.Println("Endpoint Hit: homePage")
}
func aboutMe(response http.ResponseWriter, r *http.Request) {
who := "MichaelLevan"
fmt.Fprintf(response, "A little bit about Michael Levan...")
fmt.Println("Endpoint Hit: ", who)
}
func request1() {
http.HandleFunc("/", homePage)
http.HandleFunc("/aboutme", aboutMe)
http.HandleFunc("/whoami", whoAmI)
log.Fatal(http.ListenAndServe(":8080", nil))
}