2015-01-18 16:31:22 -05:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-01-18 18:50:53 -05:00
|
|
|
"io"
|
2015-01-18 16:31:22 -05:00
|
|
|
"log"
|
2015-01-18 18:50:53 -05:00
|
|
|
"net/http"
|
2015-01-18 16:31:22 -05:00
|
|
|
"reflect"
|
|
|
|
|
2015-01-18 18:50:53 -05:00
|
|
|
"github.com/gorilla/mux"
|
2015-01-18 16:31:22 -05:00
|
|
|
"github.com/minio-io/minio/pkg/httpserver"
|
|
|
|
"github.com/minio-io/minio/pkg/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Start() {
|
|
|
|
ctrlChans := make([]chan<- string, 0)
|
|
|
|
statusChans := make([]<-chan error, 0)
|
|
|
|
|
|
|
|
ctrlChan, statusChan := storage.Start()
|
|
|
|
ctrlChans = append(ctrlChans, ctrlChan)
|
|
|
|
statusChans = append(statusChans, statusChan)
|
|
|
|
|
2015-01-18 18:50:53 -05:00
|
|
|
ctrlChan, statusChan = httpserver.Start(getHttpHandler())
|
2015-01-18 16:31:22 -05:00
|
|
|
ctrlChans = append(ctrlChans, ctrlChan)
|
|
|
|
statusChans = append(statusChans, statusChan)
|
|
|
|
|
|
|
|
cases := createSelectCases(statusChans)
|
|
|
|
|
|
|
|
for {
|
|
|
|
chosen, value, recvOk := reflect.Select(cases)
|
|
|
|
if recvOk == true {
|
|
|
|
// Status Message Received
|
|
|
|
log.Println(chosen, value.Interface(), recvOk)
|
|
|
|
} else {
|
|
|
|
// Channel closed, remove from list
|
|
|
|
aliveStatusChans := make([]<-chan error, 0)
|
|
|
|
for i, ch := range statusChans {
|
|
|
|
if i != chosen {
|
|
|
|
aliveStatusChans = append(aliveStatusChans, ch)
|
|
|
|
}
|
|
|
|
}
|
2015-01-18 18:50:53 -05:00
|
|
|
// create new select cases without defunct channel
|
2015-01-18 16:31:22 -05:00
|
|
|
statusChans = aliveStatusChans
|
|
|
|
cases = createSelectCases(statusChans)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createSelectCases(channels []<-chan error) []reflect.SelectCase {
|
|
|
|
cases := make([]reflect.SelectCase, len(channels))
|
|
|
|
for i, ch := range channels {
|
|
|
|
cases[i] = reflect.SelectCase{
|
|
|
|
Dir: reflect.SelectRecv,
|
|
|
|
Chan: reflect.ValueOf(ch),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cases
|
|
|
|
}
|
2015-01-18 18:50:53 -05:00
|
|
|
|
|
|
|
func getHttpHandler() http.Handler {
|
|
|
|
mux := mux.NewRouter()
|
|
|
|
mux.HandleFunc("/", storageHandler)
|
|
|
|
return mux
|
|
|
|
}
|
|
|
|
|
|
|
|
func storageHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
io.WriteString(w, "MINIO")
|
|
|
|
}
|