-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhealthz_handler.go
More file actions
50 lines (44 loc) · 1.19 KB
/
Copy pathhealthz_handler.go
File metadata and controls
50 lines (44 loc) · 1.19 KB
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
package healthsrv
import (
"encoding/json"
"fmt"
"net/http"
"time"
s3 "github.com/aws/aws-sdk-go/service/s3"
"github.com/deis/builder/pkg/gitreceive/log"
)
type healthZRespBucket struct {
Name string `json:"name"`
CreationDate time.Time `json:"creation_date"`
}
func convertBucket(b *s3.Bucket) healthZRespBucket {
return healthZRespBucket{
Name: *b.Name,
CreationDate: *b.CreationDate,
}
}
type healthZResp struct {
Buckets []healthZRespBucket `json:"buckets"`
}
func healthZHandler(s3Client *s3.S3) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lbOut, err := s3Client.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
str := fmt.Sprintf("Error listing buckets (%s)", err)
log.Info(str)
http.Error(w, str, http.StatusInternalServerError)
return
}
var rsp healthZResp
for _, buck := range lbOut.Buckets {
rsp.Buckets = append(rsp.Buckets, convertBucket(buck))
}
if err := json.NewEncoder(w).Encode(rsp); err != nil {
str := fmt.Sprintf("Error encoding JSON (%s)", err)
http.Error(w, str, http.StatusInternalServerError)
return
}
// TODO: check k8s API
// TODO: check server is running
})
}