68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/minio/minio-go"
|
|
)
|
|
|
|
// Server is a server containing a minio client
|
|
type Server struct {
|
|
S3 *minio.Client
|
|
}
|
|
|
|
func main() {
|
|
port := os.Getenv("PORT")
|
|
if len(port) == 0 {
|
|
port = "8080"
|
|
}
|
|
|
|
s := &Server{
|
|
S3: NewMinioClient(),
|
|
}
|
|
|
|
router := mux.NewRouter()
|
|
logger := log.New(os.Stdout, "request: ", log.Lshortfile)
|
|
|
|
router.
|
|
Methods("GET").
|
|
Path("/").
|
|
Handler(Adapt(IndexHandler(), Logging(logger)))
|
|
router.
|
|
Methods("GET").
|
|
Path("/buckets").
|
|
Handler(Adapt(s.BucketsPageHandler(), Logging(logger)))
|
|
router.
|
|
Methods("GET").
|
|
Path("/buckets/{bucketName}").
|
|
Handler(Adapt(s.BucketPageHandler(), Logging(logger)))
|
|
|
|
api := router.PathPrefix("/api").Subrouter()
|
|
|
|
buckets := api.PathPrefix("/buckets").Subrouter()
|
|
buckets.
|
|
Methods("POST").
|
|
Path("").
|
|
Handler(Adapt(s.CreateBucketHandler(), Logging(logger)))
|
|
buckets.
|
|
Methods("DELETE").
|
|
Path("/{bucketName}").
|
|
Handler(Adapt(s.DeleteBucketHandler(), Logging(logger)))
|
|
buckets.
|
|
Methods("POST").
|
|
Path("/{bucketName}/objects").
|
|
Handler(Adapt(s.CreateObjectHandler(), Logging(logger)))
|
|
buckets.
|
|
Methods("GET").
|
|
Path("/{bucketName}/objects/{objectName}").
|
|
Handler(Adapt(s.GetObjectHandler(), Logging(logger)))
|
|
buckets.
|
|
Methods("DELETE").
|
|
Path("/{bucketName}/objects/{objectName}").
|
|
Handler(Adapt(s.DeleteObjectHandler(), Logging(logger)))
|
|
|
|
log.Fatal(http.ListenAndServe(":"+port, router))
|
|
}
|