Merge pull request #11 from fkautz/pr_out_adding_initial_web_server_and_storage_server_module_infrastructure
commit
4e644a1f41
@ -1,4 +1,7 @@ |
||||
package main |
||||
|
||||
import "github.com/minio-io/minio/pkg/server" |
||||
|
||||
func main() { |
||||
server.Start() |
||||
} |
||||
|
@ -0,0 +1,19 @@ |
||||
package httpserver |
||||
|
||||
import ( |
||||
"log" |
||||
"net/http" |
||||
) |
||||
|
||||
func Start(handler http.Handler) (chan<- string, <-chan error) { |
||||
ctrlChannel := make(chan string) |
||||
errorChannel := make(chan error) |
||||
go start(ctrlChannel, errorChannel, handler) |
||||
return ctrlChannel, errorChannel |
||||
} |
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler) { |
||||
log.Println("Starting HTTP Server") |
||||
err := http.ListenAndServe(":8080", router) |
||||
errorChannel <- err |
||||
} |
@ -0,0 +1,54 @@ |
||||
package server |
||||
|
||||
import ( |
||||
"log" |
||||
"reflect" |
||||
|
||||
"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) |
||||
|
||||
ctrlChan, statusChan = httpserver.Start(storage.GetHttpHandler()) |
||||
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) |
||||
} |
||||
} |
||||
statusChans = aliveStatusChans |
||||
cases = createSelectCases(statusChans) |
||||
} |
||||
// create new select case
|
||||
} |
||||
} |
||||
|
||||
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 |
||||
} |
@ -1 +1,33 @@ |
||||
package storage |
||||
|
||||
import ( |
||||
"errors" |
||||
"io" |
||||
"net/http" |
||||
|
||||
"github.com/gorilla/mux" |
||||
) |
||||
|
||||
func GetHttpHandler() http.Handler { |
||||
mux := mux.NewRouter() |
||||
mux.HandleFunc("/", storageHandler) |
||||
return mux |
||||
} |
||||
|
||||
func storageHandler(w http.ResponseWriter, req *http.Request) { |
||||
io.WriteString(w, "MINIO") |
||||
} |
||||
|
||||
func Start() (chan<- string, <-chan error) { |
||||
ctrlChannel := make(chan string) |
||||
errorChannel := make(chan error) |
||||
go start(ctrlChannel, errorChannel) |
||||
return ctrlChannel, errorChannel |
||||
} |
||||
|
||||
func start(ctrlChannel <-chan string, errorChannel chan<- error) { |
||||
errorChannel <- errors.New("STORAGE MSG") |
||||
errorChannel <- errors.New("STORAGE MSG") |
||||
errorChannel <- errors.New("STORAGE MSG") |
||||
close(errorChannel) |
||||
} |
||||
|
Loading…
Reference in new issue