-
Notifications
You must be signed in to change notification settings - Fork 9
/
hello.go
42 lines (35 loc) · 978 Bytes
/
hello.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
package api
import (
"net/http"
"time"
)
// HandleHello returns hello message.
func (ar *Router) HandleHello() http.HandlerFunc {
type helloResponse struct {
Answer string `json:"answer,omitempty"`
Date time.Time `json:"date,omitempty"`
}
return func(w http.ResponseWriter, r *http.Request) {
locale := r.Header.Get("Accept-Language")
ar.logger.Println("trace Hello handler")
hello := helloResponse{
Answer: "Hello, my name is Identifo",
Date: time.Now(),
}
ar.ServeJSON(w, locale, http.StatusOK, hello)
}
}
// HandlePing returns pong message.
func (ar *Router) HandlePing(w http.ResponseWriter, r *http.Request) {
type pongResponse struct {
Message string `json:"message,omitempty"`
Date time.Time `json:"date,omitempty"`
}
locale := r.Header.Get("Accept-Language")
ar.logger.Println("trace pong handler")
pong := pongResponse{
Message: "Pong!",
Date: time.Now(),
}
ar.ServeJSON(w, locale, http.StatusOK, pong)
}