mirror of
https://github.com/minio/minio.git
synced 2025-02-09 04:38:09 -05:00
Merge pull request #20 from fkautz/pr_out_moving_web_logic_to_minioapi_package
This commit is contained in:
commit
cc288a5fd7
@ -2,26 +2,22 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/minio-io/minio/pkg/httpserver"
|
"github.com/minio-io/minio/pkg/httpserver"
|
||||||
storageModule "github.com/minio-io/minio/pkg/storage"
|
storageModule "github.com/minio-io/minio/pkg/storage"
|
||||||
|
"github.com/minio-io/minio/pkg/webapi/minioapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var storage *storageModule.Storage
|
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
ctrlChans := make([]chan<- string, 0)
|
ctrlChans := make([]chan<- string, 0)
|
||||||
statusChans := make([]<-chan error, 0)
|
statusChans := make([]<-chan error, 0)
|
||||||
|
|
||||||
ctrlChan, statusChan, storageSystem := storageModule.Start()
|
ctrlChan, statusChan, storage := storageModule.Start()
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
statusChans = append(statusChans, statusChan)
|
statusChans = append(statusChans, statusChan)
|
||||||
storage = storageSystem
|
|
||||||
|
|
||||||
ctrlChan, statusChan = httpserver.Start(getHttpHandler())
|
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage))
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
statusChans = append(statusChans, statusChan)
|
statusChans = append(statusChans, statusChan)
|
||||||
|
|
||||||
@ -57,24 +53,3 @@ func createSelectCases(channels []<-chan error) []reflect.SelectCase {
|
|||||||
}
|
}
|
||||||
return cases
|
return cases
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHttpHandler() http.Handler {
|
|
||||||
mux := mux.NewRouter()
|
|
||||||
mux.HandleFunc("/{bucket}/{object:.*}", getObjectHandler).Methods("GET")
|
|
||||||
mux.HandleFunc("/{bucket}/{object:.*}", putObjectHandler).Methods("PUT")
|
|
||||||
return mux
|
|
||||||
}
|
|
||||||
|
|
||||||
func getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
|
||||||
vars := mux.Vars(req)
|
|
||||||
bucket := vars["bucket"]
|
|
||||||
object := vars["object"]
|
|
||||||
storage.CopyObjectToWriter(w, bucket, object)
|
|
||||||
}
|
|
||||||
|
|
||||||
func putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
|
||||||
vars := mux.Vars(req)
|
|
||||||
bucket := vars["bucket"]
|
|
||||||
object := vars["object"]
|
|
||||||
storage.StoreObject(bucket, object, req.Body)
|
|
||||||
}
|
|
||||||
|
36
pkg/webapi/minioapi/minioapi.go
Normal file
36
pkg/webapi/minioapi/minioapi.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package minioapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
mstorage "github.com/minio-io/minio/pkg/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
type minioApi struct {
|
||||||
|
storage *mstorage.Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
func HttpHandler(storage *mstorage.Storage) http.Handler {
|
||||||
|
mux := mux.NewRouter()
|
||||||
|
api := minioApi{
|
||||||
|
storage: storage,
|
||||||
|
}
|
||||||
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
||||||
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
||||||
|
return mux
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
bucket := vars["bucket"]
|
||||||
|
object := vars["object"]
|
||||||
|
server.storage.CopyObjectToWriter(w, bucket, object)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
bucket := vars["bucket"]
|
||||||
|
object := vars["object"]
|
||||||
|
server.storage.StoreObject(bucket, object, req.Body)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user