forked from AdminTurnedDevOps/GoWebAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (45 loc) · 1.11 KB
/
main.go
File metadata and controls
57 lines (45 loc) · 1.11 KB
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
52
53
54
55
56
57
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{
{Name: "Intern at IBM",
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!\n\nOther endpoints\n- /whoami\n- /aboutme\n- /ping")
fmt.Println("Endpoint Hit: homePage")
}
func aboutMe(response http.ResponseWriter, r *http.Request) {
who := "Intern at IBM"
fmt.Fprintf(response, "A little bit about Intern at IBM...")
fmt.Println("Endpoint Hit: ", who)
}
func ping(response http.ResponseWriter, r *http.Request) {
fmt.Fprintf(response, "pong")
fmt.Println("Endpoint Hit: ping")
}
func request1() {
http.HandleFunc("/", homePage)
http.HandleFunc("/aboutme", aboutMe)
http.HandleFunc("/whoami", whoAmI)
http.HandleFunc("/ping", ping)
log.Fatal(http.ListenAndServe(":8080", nil))
}