-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice.go
61 lines (50 loc) · 1.65 KB
/
service.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
54
55
56
57
58
59
60
61
package s2
import (
"encoding/xml"
"net/http"
"time"
"github.com/sirupsen/logrus"
)
// Bucket is an XML marshallable representation of a bucket
type Bucket struct {
// Name is the bucket name
Name string `xml:"Name"`
// CreationDate is when the bucket was created
CreationDate time.Time `xml:"CreationDate"`
}
// ListBucketsResult is a response from a ListBucket call
type ListBucketsResult struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListAllMyBucketsResult"`
// Owner is the owner of the buckets
Owner *User `xml:"Owner"`
// Buckets are a list of buckets under the given owner
Buckets []*Bucket `xml:"Buckets>Bucket"`
}
// ServiceController is an interface defining service-level functionality
type ServiceController interface {
// ListBuckets lists all buckets
ListBuckets(r *http.Request) (*ListBucketsResult, error)
}
// unimplementedServiceController defines a controller that returns
// `NotImplementedError` for all functionality
type unimplementedServiceController struct{}
func (c unimplementedServiceController) ListBuckets(r *http.Request) (*ListBucketsResult, error) {
return nil, NotImplementedError(r)
}
type serviceHandler struct {
controller ServiceController
logger *logrus.Entry
}
func (h *serviceHandler) get(w http.ResponseWriter, r *http.Request) {
result, err := h.controller.ListBuckets(r)
if err != nil {
WriteError(h.logger, w, r, err)
return
}
// some clients (e.g. minio-python) can't handle sub-seconds in datetime
// output
for _, bucket := range result.Buckets {
bucket.CreationDate = bucket.CreationDate.UTC().Round(time.Second)
}
writeXML(h.logger, w, r, http.StatusOK, result)
}