-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
38 lines (32 loc) · 802 Bytes
/
server.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
package main
import (
"fmt"
"net/http"
"time"
"encoding/json"
)
type TimeS struct {
Time string `json:"time"`
}
func feature() {
fmt.Println("New feature delivered!")
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Server is running on Go...")
})
http.HandleFunc("/time", func(w http.ResponseWriter, r *http.Request) {
tm := time.Now()
response := fmt.Sprintf("Now time is: %d-%02d-%02dT%02d:%02d:%02d-00:00\n",
tm.Year(), tm.Month(), tm.Day(),
tm.Hour(), tm.Minute(), tm.Second())
fmt.Fprintf(w, response)
jsonData, err := json.Marshal(TimeS{Time: tm.Format(time.RFC3339)})
if err != nil {
panic(err)
}
fmt.Println(string(jsonData))
fmt.Fprintf(w, string(jsonData))
})
http.ListenAndServe(":8795", nil)
}