-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (26 loc) · 808 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 (
"fmt"
"time"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
func main() {
fmt.Println("Starting server...")
r := mux.NewRouter()
r.HandleFunc("/time/", Time).Methods("GET")
r.HandleFunc("/time/now/", TimeNow).Methods("GET")
http.ListenAndServe("localhost:8080", r)
}
func Time(response http.ResponseWriter, request *http.Request){
now := time.Now()
response.Write([]byte("A hora do servidor é: " + now.Format("02/01/2006 15:04:05")))
}
func TimeNow(response http.ResponseWriter, request *http.Request){
gmt := request.URL.Query()["gmt"][0]
gmtNumber,_:=strconv.Atoi(gmt)
locationTime := time.FixedZone("", gmtNumber*60*60)
hora := time.Now().In(locationTime).Format("02/01/2006 15:04:05")
response.Write([]byte("A hora do servidor é: " + hora))
}