Export S3 client of Server

This commit is contained in:
Lena Fuhrimann 2017-03-12 16:07:59 +01:00
parent c96a874900
commit dadd54eb01
3 changed files with 10 additions and 10 deletions

12
api.go
View file

@ -29,7 +29,7 @@ func (s *Server) CreateBucketHandler() http.Handler {
return return
} }
err = s.s3.MakeBucket(bucket.Name, "") err = s.S3.MakeBucket(bucket.Name, "")
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -64,7 +64,7 @@ func (s *Server) CreateObjectHandler() http.Handler {
objectSource := fmt.Sprintf("/%s/%s", copy.SourceBucketName, copy.SourceObjectName) objectSource := fmt.Sprintf("/%s/%s", copy.SourceBucketName, copy.SourceObjectName)
fmt.Println(copy) fmt.Println(copy)
fmt.Println(objectSource) fmt.Println(objectSource)
err = s.s3.CopyObject(copy.BucketName, copy.ObjectName, objectSource, copyConds) err = s.S3.CopyObject(copy.BucketName, copy.ObjectName, objectSource, copyConds)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -90,7 +90,7 @@ func (s *Server) CreateObjectHandler() http.Handler {
} }
defer file.Close() defer file.Close()
_, err = s.s3.PutObject(vars["bucketName"], handler.Filename, file, "application/octet-stream") _, err = s.S3.PutObject(vars["bucketName"], handler.Filename, file, "application/octet-stream")
if err != nil { if err != nil {
w.WriteHeader(http.StatusUnprocessableEntity) w.WriteHeader(http.StatusUnprocessableEntity)
return return
@ -106,7 +106,7 @@ func (s *Server) DeleteBucketHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
err := s.s3.RemoveBucket(vars["bucketName"]) err := s.S3.RemoveBucket(vars["bucketName"])
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -121,7 +121,7 @@ func (s *Server) DeleteObjectHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
err := s.s3.RemoveObject(vars["bucketName"], vars["objectName"]) err := s.S3.RemoveObject(vars["bucketName"], vars["objectName"])
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
@ -137,7 +137,7 @@ func (s *Server) GetObjectHandler() http.Handler {
vars := mux.Vars(r) vars := mux.Vars(r)
objectName := vars["objectName"] objectName := vars["objectName"]
object, err := s.s3.GetObject(vars["bucketName"], objectName) object, err := s.S3.GetObject(vars["bucketName"], objectName)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return

View file

@ -11,7 +11,7 @@ import (
// Server is a server containing a minio client // Server is a server containing a minio client
type Server struct { type Server struct {
s3 *minio.Client S3 *minio.Client
} }
func main() { func main() {
@ -21,7 +21,7 @@ func main() {
} }
s := &Server{ s := &Server{
s3: NewMinioClient(), S3: NewMinioClient(),
} }
router := mux.NewRouter() router := mux.NewRouter()

View file

@ -38,7 +38,7 @@ func (s *Server) BucketPageHandler() http.Handler {
doneCh := make(chan struct{}) doneCh := make(chan struct{})
objectCh := s.s3.ListObjectsV2(bucketName, "", false, doneCh) objectCh := s.S3.ListObjectsV2(bucketName, "", false, doneCh)
for object := range objectCh { for object := range objectCh {
if object.Err != nil { if object.Err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
@ -73,7 +73,7 @@ func (s *Server) BucketsPageHandler() http.Handler {
return return
} }
buckets, err := s.s3.ListBuckets() buckets, err := s.S3.ListBuckets()
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return