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-09 21:20:40 +01:00
minio "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 {
s3 *minio.Client
}
2016-12-18 22:54:21 +01:00
func main() {
port := os.Getenv("PORT")
if len(port) == 0 {
port = "8080"
}
2017-03-10 10:54:30 +01:00
s := &Server{
s3: NewMinioClient(),
}
router := mux.NewRouter().StrictSlash(true)
router.
Methods("GET").
Path("/").
HandlerFunc(Chain(IndexHandler, Logger()))
router.
Methods("GET").
Path("/buckets").
HandlerFunc(Chain(s.BucketsPageHandler, Logger()))
router.
Methods("GET").
Path("/buckets/{bucketName}").
HandlerFunc(Chain(s.BucketPageHandler, Logger()))
api := router.PathPrefix("/api").Subrouter()
buckets := api.PathPrefix("/buckets").Subrouter()
buckets.
Methods("POST").
Path("").
HandlerFunc(Chain(s.CreateBucketHandler, Logger()))
buckets.
Methods("DELETE").
Path("/{bucketName}").
HandlerFunc(Chain(s.DeleteBucketHandler, Logger()))
buckets.
Methods("POST").
Path("/{bucketName}/objects").
HandlerFunc(Chain(s.CreateObjectHandler, Logger()))
buckets.
Methods("GET").
Path("/{bucketName}/objects/{objectName}").
HandlerFunc(Chain(s.GetObjectHandler, Logger()))
buckets.
Methods("DELETE").
Path("/{bucketName}/objects/{objectName}").
HandlerFunc(Chain(s.DeleteObjectHandler, Logger()))
2016-12-18 22:54:21 +01:00
2016-12-20 19:47:36 +01:00
log.Fatal(http.ListenAndServe(":"+port, router))
2016-12-18 22:54:21 +01:00
}