Merge pull request #85 from fkautz/pr_out_http_server_package_now_follows_convention

master
Frederick F. Kautz IV 10 years ago
commit 698f0b815f
  1. 27
      pkg/httpserver/httpserver.go
  2. 39
      pkg/server/server.go

@ -22,38 +22,41 @@ import (
"time"
)
type HttpServer struct {
type HttpServerConfig struct {
Address string
TLS bool
CertFile string
KeyFile string
}
func Start(handler http.Handler, srv HttpServer) (chan<- string, <-chan error) {
type HttpServer struct{}
func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *HttpServer) {
ctrlChannel := make(chan string)
errorChannel := make(chan error)
go start(ctrlChannel, errorChannel, handler, srv)
return ctrlChannel, errorChannel
server := HttpServer{}
go start(ctrlChannel, errorChannel, handler, config, &server)
return ctrlChannel, errorChannel, &server
}
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler, srv HttpServer) {
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler, config HttpServerConfig, server *HttpServer) {
var err error
// Minio server config
server := &http.Server{
Addr: srv.Address,
httpServer := &http.Server{
Addr: config.Address,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Println("Starting HTTP Server on " + srv.Address)
log.Println("Starting HTTP Server on:", config.Address)
if srv.TLS {
server.TLSConfig = getDefaultTLSConfig()
err = server.ListenAndServeTLS(srv.CertFile, srv.KeyFile)
if config.TLS {
httpServer.TLSConfig = getDefaultTLSConfig()
err = httpServer.ListenAndServeTLS(config.CertFile, config.KeyFile)
} else {
err = server.ListenAndServe()
err = httpServer.ListenAndServe()
}
errorChannel <- err
close(errorChannel)

@ -46,28 +46,45 @@ const (
)
func Start(config ServerConfig) {
// maintain a list of input and output channels for communicating with services
var ctrlChans []chan<- string
var statusChans []<-chan error
// a pair of control channels, we use these primarily to add to the lists above
var ctrlChan chan<- string
var statusChan <-chan error
// configure web server
var storage mstorage.Storage
var srv = httpserver.HttpServer{}
srv.Address = config.Address
srv.TLS = config.Tls
var httpConfig = httpserver.HttpServerConfig{}
httpConfig.Address = config.Address
httpConfig.TLS = config.Tls
if config.CertFile != "" {
srv.CertFile = config.CertFile
httpConfig.CertFile = config.CertFile
}
if config.KeyFile != "" {
srv.KeyFile = config.KeyFile
httpConfig.KeyFile = config.KeyFile
}
if config.StorageType == InMemoryStorage {
// instantiate storage
// preconditions:
// - storage type specified
// - any configuration for storage is populated
// postconditions:
// - storage driver is initialized
// - ctrlChans has channel to communicate to storage
// - statusChans has channel for messages coming from storage
switch {
case config.StorageType == InMemoryStorage:
{
ctrlChan, statusChan, storage = inmemory.Start()
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)
} else if config.StorageType == FileStorage {
}
case config.StorageType == FileStorage:
{
// TODO Replace this with a more configurable and robust version
currentUser, err := user.Current()
if err != nil {
log.Fatal(err)
@ -82,11 +99,13 @@ func Start(config ServerConfig) {
ctrlChan, statusChan, storage = fs.Start(rootPath)
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)
} else {
}
default: // should never happen
log.Fatal("No storage driver found")
}
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv)
// start minio api in a web server, pass storage driver into it
ctrlChan, statusChan, _ = httpserver.Start(minioapi.HttpHandler(storage), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)

Loading…
Cancel
Save