-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (30 loc) · 881 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
package main
import (
"bytes"
"fmt"
"net/http"
"time"
)
func home(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", "<h2>Welcome to the home Page</h2>")
fmt.Fprintf(w, "%s", "How are you doing today?")
}
func work(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "[ %s", time.Now())
fmt.Fprintf(w, "]")
}
func main() {
response, _ := http.Get("https://golangcode.com/")
// The line below would fail because Body = io.ReadCloser
// fmt.Printf(response.Body)
// ...so we convert it to a string by passing it through
// a buffer first. A 'costly' but useful process.
buf := new(bytes.Buffer)
buf.ReadFrom(response.Body)
defer response.Body.Close()
serverPort := "8085"
http.HandleFunc("/home", home)
http.HandleFunc("/workTime", work)
fmt.Println("Server is running at port : " + serverPort)
http.ListenAndServe(":"+serverPort, nil)
}