Merge pull request #689 from harshavardhana/pr_out_expand_http_server_struct_to_store_more_values

master
Harshavardhana 10 years ago
commit f05ad062ee
  1. 33
      pkg/server/httpserver/httpserver.go

@ -33,29 +33,35 @@ type Config struct {
} }
// Server - http server related // Server - http server related
type Server struct{} type Server struct {
config Config
handler http.Handler
}
// Start http server // Start http server
func Start(handler http.Handler, config Config) (chan<- string, <-chan error, *Server) { func Start(handler http.Handler, config Config) (chan<- string, <-chan error, Server) {
ctrlChannel := make(chan string) ctrlChannel := make(chan string)
errorChannel := make(chan error) errorChannel := make(chan error)
server := Server{} server := Server{
go start(ctrlChannel, errorChannel, handler, config, &server) config: config,
return ctrlChannel, errorChannel, &server handler: handler,
}
go start(ctrlChannel, errorChannel, server)
return ctrlChannel, errorChannel, server
} }
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler, config Config, server *Server) { func start(ctrlChannel <-chan string, errorChannel chan<- error, server Server) {
defer close(errorChannel) defer close(errorChannel)
var err error var err error
// Minio server config // Minio server config
httpServer := &http.Server{ httpServer := &http.Server{
Addr: config.Address, Addr: server.config.Address,
Handler: router, Handler: server.handler,
MaxHeaderBytes: 1 << 20, MaxHeaderBytes: 1 << 20,
} }
host, port, err := net.SplitHostPort(config.Address) host, port, err := net.SplitHostPort(server.config.Address)
if err != nil { if err != nil {
errorChannel <- err errorChannel <- err
return return
@ -67,7 +73,10 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Han
hosts = append(hosts, host) hosts = append(hosts, host)
default: default:
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
errorChannel <- err if err != nil {
errorChannel <- err
return
}
for _, addr := range addrs { for _, addr := range addrs {
if addr.Network() == "ip+net" { if addr.Network() == "ip+net" {
host := strings.Split(addr.String(), "/")[0] host := strings.Split(addr.String(), "/")[0]
@ -83,11 +92,11 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Han
fmt.Printf("Starting minio server on: http://%s:%s\n", host, port) fmt.Printf("Starting minio server on: http://%s:%s\n", host, port)
} }
err = httpServer.ListenAndServe() err = httpServer.ListenAndServe()
case config.TLS == true: case server.config.TLS == true:
for _, host := range hosts { for _, host := range hosts {
fmt.Printf("Starting minio server on: https://%s:%s\n", host, port) fmt.Printf("Starting minio server on: https://%s:%s\n", host, port)
} }
err = httpServer.ListenAndServeTLS(config.CertFile, config.KeyFile) err = httpServer.ListenAndServeTLS(server.config.CertFile, server.config.KeyFile)
} }
if err != nil { if err != nil {
errorChannel <- err errorChannel <- err

Loading…
Cancel
Save