s3manager-web/main.go

68 lines
1.4 KiB
Go
Raw Normal View History

2016-12-18 22:54:21 +01:00
package main
import (
"log"
"net/http"
"os"
2017-03-09 21:20:40 +01:00
2017-03-10 10:54:30 +01:00
"github.com/gorilla/mux"
2017-03-17 23:57:58 +01:00
"github.com/minio/minio-go"
2016-12-18 22:54:21 +01:00
)
2017-03-09 21:20:40 +01:00
// Server is a server containing a minio client
type Server struct {
2017-03-12 16:07:59 +01:00
S3 *minio.Client
2017-03-09 21:20:40 +01:00
}
2016-12-18 22:54:21 +01:00
func main() {
2017-03-10 10:54:30 +01:00
s := &Server{
2017-03-12 16:07:59 +01:00
S3: NewMinioClient(),
2017-03-10 10:54:30 +01:00
}
2017-03-18 01:05:21 +01:00
logger := log.New(os.Stdout, "request: ", log.Lshortfile)
2017-03-30 14:00:06 +02:00
router := mux.NewRouter()
2017-03-10 10:54:30 +01:00
router.
Methods("GET").
Path("/").
2017-03-18 01:05:21 +01:00
Handler(Adapt(IndexHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
router.
Methods("GET").
Path("/buckets").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.BucketsPageHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
router.
Methods("GET").
Path("/buckets/{bucketName}").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.BucketPageHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
api := router.PathPrefix("/api").Subrouter()
buckets := api.PathPrefix("/buckets").Subrouter()
buckets.
Methods("POST").
Path("").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.CreateBucketHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
buckets.
Methods("DELETE").
Path("/{bucketName}").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.DeleteBucketHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
buckets.
Methods("POST").
Path("/{bucketName}/objects").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.CreateObjectHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
buckets.
Methods("GET").
Path("/{bucketName}/objects/{objectName}").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.GetObjectHandler(), Logging(logger)))
2017-03-10 10:54:30 +01:00
buckets.
Methods("DELETE").
Path("/{bucketName}/objects/{objectName}").
2017-03-18 01:05:21 +01:00
Handler(Adapt(s.DeleteObjectHandler(), Logging(logger)))
2016-12-18 22:54:21 +01:00
2017-03-30 14:00:06 +02:00
port := os.Getenv("PORT")
if len(port) == 0 {
port = "8080"
}
2016-12-20 19:47:36 +01:00
log.Fatal(http.ListenAndServe(":"+port, router))
2016-12-18 22:54:21 +01:00
}