-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
53 lines (43 loc) · 1.12 KB
/
handlers.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
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"encoding/json"
"log"
"net/http"
)
type ApiHandler struct{}
type ResponseHealthCheck struct {
Status string `json:"status"`
Description string `json:"description"`
}
type ResponseMetadata struct {
Version string `json:"version"`
Description string `json:"description"`
LastCommitSha string `json:"lastcommitsha"`
}
func (ah *ApiHandler) handleHello(w http.ResponseWriter, r *http.Request) {
response := "Hello World"
w.Write([]byte(response))
}
func (ah *ApiHandler) handleHealthCheck(w http.ResponseWriter, r *http.Request) {
responseHealthCheck := ResponseHealthCheck{
Status: "Ok",
Description: "Basic API Service",
}
response, err := json.Marshal(&responseHealthCheck)
if err != nil {
log.Fatal(err)
}
w.Write(response)
}
func (ah *ApiHandler) handleMetadata(w http.ResponseWriter, r *http.Request) {
responseMetaData := ResponseMetadata{
Version: "1.0.7",
Description: "basic go-lang api service",
LastCommitSha: "oasdfkjqoewrpsdfklnvkjowo",
}
response, err := json.Marshal(&responseMetaData)
if err != nil {
log.Fatal(err)
}
w.Write(response)
}