Get rid of sub-domain code and some other formatting changes

master
Harshavardhana 10 years ago
parent 8c5a83ddcf
commit 1df28f3060
  1. 17
      main.go
  2. 56
      pkg/api/api_router.go
  3. 38
      pkg/api/api_test.go
  4. 17
      pkg/server/httpserver/httpserver.go
  5. 5
      pkg/server/server.go

@ -61,10 +61,10 @@ USAGE:
minio mode {{.Name}} limit SIZE expire TIME minio mode {{.Name}} limit SIZE expire TIME
EXAMPLES: EXAMPLES:
1. Limit maximum memory usage to 64MB with 1h expiration 1. Limit maximum memory usage to 64MB with 1 hour expiration
$ minio mode {{.Name}} limit 64MB expire 1h $ minio mode {{.Name}} limit 64MB expire 1h
2. Limit maximum memory usage to 4GB with no time expiration 2. Limit maximum memory usage to 4GB with no expiration
$ minio mode {{.Name}} limit 4GB $ minio mode {{.Name}} limit 4GB
`, `,
} }
@ -93,11 +93,6 @@ EXAMPLES:
} }
var flags = []cli.Flag{ var flags = []cli.Flag{
// cli.StringFlag{
// Name: "domain",
// Value: "",
// Usage: "domain used for routing incoming API requests",
// },
cli.StringFlag{ cli.StringFlag{
Name: "api-address", Name: "api-address",
Value: ":9000", Value: ":9000",
@ -154,7 +149,7 @@ func runMemory(c *cli.Context) {
case "limit": case "limit":
{ {
if maxMemorySet { if maxMemorySet {
Fatalf("Limit should be set only once") Fatalln("Limit should be set only once")
} }
args = args.Tail() args = args.Tail()
maxMemory, err = humanize.ParseBytes(args.First()) maxMemory, err = humanize.ParseBytes(args.First())
@ -170,7 +165,7 @@ func runMemory(c *cli.Context) {
case "expire": case "expire":
{ {
if expirationSet { if expirationSet {
Fatalf("Expiration should be set only once") Fatalln("Expiration should be set only once")
} }
args = args.Tail() args = args.Tail()
expiration, err = time.ParseDuration(args.First()) expiration, err = time.ParseDuration(args.First())
@ -203,7 +198,7 @@ func runMemory(c *cli.Context) {
func runDonut(c *cli.Context) { func runDonut(c *cli.Context) {
u, err := user.Current() u, err := user.Current()
if err != nil { if err != nil {
Fatalln("Unable to determine current user. Reason: %s\n", err) Fatalf("Unable to determine current user. Reason: %s\n", err)
} }
if len(c.Args()) < 1 { if len(c.Args()) < 1 {
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
@ -238,7 +233,6 @@ func getAPIServerConfig(c *cli.Context) httpserver.Config {
} }
tls := (certFile != "" && keyFile != "") tls := (certFile != "" && keyFile != "")
return httpserver.Config{ return httpserver.Config{
// Domain: c.GlobalString("domain"),
Address: c.GlobalString("api-address"), Address: c.GlobalString("api-address"),
TLS: tls, TLS: tls,
CertFile: certFile, CertFile: certFile,
@ -248,7 +242,6 @@ func getAPIServerConfig(c *cli.Context) httpserver.Config {
func getWebServerConfigFunc(c *cli.Context) server.StartServerFunc { func getWebServerConfigFunc(c *cli.Context) server.StartServerFunc {
config := httpserver.Config{ config := httpserver.Config{
// Domain: c.GlobalString("domain"),
Address: c.GlobalString("web-address"), Address: c.GlobalString("web-address"),
TLS: false, TLS: false,
CertFile: "", CertFile: "",

@ -30,12 +30,16 @@ import (
// private use // private use
type minioAPI struct { type minioAPI struct {
domain string
driver drivers.Driver driver drivers.Driver
} }
// Path based routing // HTTPHandler - http wrapper handler
func pathMux(api minioAPI, mux *router.Router) *router.Router { func HTTPHandler(driver drivers.Driver) http.Handler {
var mux *router.Router
var api = minioAPI{}
api.driver = driver
mux = router.NewRouter()
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET") mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET") mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT") mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
@ -44,53 +48,9 @@ func pathMux(api minioAPI, mux *router.Router) *router.Router {
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD") mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT") mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
return mux
}
/*
// Domain based routing
func domainMux(api minioAPI, mux *router.Router) *router.Router {
mux.HandleFunc("/",
api.listObjectsHandler).Host("{bucket}" + "." + api.domain).Methods("GET")
mux.HandleFunc("/{object:.*}",
api.getObjectHandler).Host("{bucket}" + "." + api.domain).Methods("GET")
mux.HandleFunc("/{object:.*}",
api.headObjectHandler).Host("{bucket}" + "." + api.domain).Methods("HEAD")
mux.HandleFunc("/{object:.*}",
api.putObjectHandler).Host("{bucket}" + "." + api.domain).Methods("PUT")
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
return mux
}
*/
// Get proper router based on domain availability
func getMux(api minioAPI, mux *router.Router) *router.Router {
switch true {
case api.domain == "":
return pathMux(api, mux)
// case api.domain != "":
// s := mux.Host(api.domain).Subrouter()
// return domainMux(api, s)
}
return nil
}
// HTTPHandler - http wrapper handler
func HTTPHandler(domain string, driver drivers.Driver) http.Handler {
var mux *router.Router
var api = minioAPI{}
api.driver = driver
api.domain = domain
r := router.NewRouter()
mux = getMux(api, r)
var conf = config.Config{} var conf = config.Config{}
if err := conf.SetupConfig(); err != nil { if err := conf.SetupConfig(); err != nil {
log.Fatal(iodine.New(err, map[string]string{"domain": domain})) log.Fatal(iodine.New(err, nil))
} }
h := timeValidityHandler(mux) h := timeValidityHandler(mux)
h = ignoreResourcesHandler(h) h = ignoreResourcesHandler(h)

@ -135,7 +135,7 @@ func (s *MySuite) TestNonExistantBucket(c *C) {
} }
} }
driver := s.Driver driver := s.Driver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -173,7 +173,7 @@ func (s *MySuite) TestEmptyObject(c *C) {
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once() typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once() typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once() typedDriver.On("GetObjectMetadata", "bucket", "object", "").Return(metadata, nil).Once()
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -216,7 +216,7 @@ func (s *MySuite) TestBucket(c *C) {
typedDriver.On("CreateBucket", "bucket", "private").Return(nil).Once() typedDriver.On("CreateBucket", "bucket", "private").Return(nil).Once()
typedDriver.On("GetBucketMetadata", "bucket").Return(metadata, nil).Once() typedDriver.On("GetBucketMetadata", "bucket").Return(metadata, nil).Once()
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -256,7 +256,7 @@ func (s *MySuite) TestObject(c *C) {
typedDriver.SetGetObjectWriter("bucket", "object", []byte("hello world")) typedDriver.SetGetObjectWriter("bucket", "object", []byte("hello world"))
typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once() typedDriver.On("GetObject", mock.Anything, "bucket", "object").Return(int64(0), nil).Once()
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -315,7 +315,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3", // TODO correct md5 Md5: "5eb63bbbe01eeed093cb22bb8f5acdc3", // TODO correct md5
Size: 11, Size: 11,
} }
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -445,7 +445,7 @@ func (s *MySuite) TestNotImplemented(c *C) {
} }
} }
driver := s.Driver driver := s.Driver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -470,7 +470,7 @@ func (s *MySuite) TestHeader(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
typedDriver.AssertExpectations(c) typedDriver.AssertExpectations(c)
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -539,7 +539,7 @@ func (s *MySuite) TestPutBucket(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -576,7 +576,7 @@ func (s *MySuite) TestPutObject(c *C) {
} }
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -665,7 +665,7 @@ func (s *MySuite) TestListBuckets(c *C) {
} }
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -803,7 +803,7 @@ func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -836,7 +836,7 @@ func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
} }
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -881,7 +881,7 @@ func (s *MySuite) TestContentTypePersists(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -996,7 +996,7 @@ func (s *MySuite) TestPartialContent(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
@ -1054,7 +1054,7 @@ func (s *MySuite) TestListObjectsHandlerErrors(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
client := http.Client{} client := http.Client{}
@ -1121,7 +1121,7 @@ func (s *MySuite) TestListBucketsErrors(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
client := http.Client{} client := http.Client{}
@ -1158,7 +1158,7 @@ func (s *MySuite) TestPutBucketErrors(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
client := http.Client{} client := http.Client{}
@ -1218,7 +1218,7 @@ func (s *MySuite) TestGetObjectErrors(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
client := http.Client{} client := http.Client{}
@ -1291,7 +1291,7 @@ func (s *MySuite) TestGetObjectRangeErrors(c *C) {
driver := s.Driver driver := s.Driver
typedDriver := s.MockDriver typedDriver := s.MockDriver
httpHandler := HTTPHandler("", driver) httpHandler := HTTPHandler(driver)
testServer := httptest.NewServer(httpHandler) testServer := httptest.NewServer(httpHandler)
defer testServer.Close() defer testServer.Close()
client := http.Client{} client := http.Client{}

@ -24,12 +24,10 @@ import (
// Config - http server config // Config - http server config
type Config struct { type Config struct {
Address string Address string
TLS bool TLS bool
CertFile string CertFile string
KeyFile string KeyFile string
Websocket bool // TODO
// Domain string
} }
// Server - http server related // Server - http server related
@ -59,11 +57,12 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error,
} }
log.Println("Starting HTTP Server on:", config.Address) log.Println("Starting HTTP Server on:", config.Address)
if config.TLS { switch {
default:
err = httpServer.ListenAndServe()
case config.TLS == true:
httpServer.TLSConfig = getDefaultTLSConfig() httpServer.TLSConfig = getDefaultTLSConfig()
err = httpServer.ListenAndServeTLS(config.CertFile, config.KeyFile) err = httpServer.ListenAndServeTLS(config.CertFile, config.KeyFile)
} else {
err = httpServer.ListenAndServe()
} }
errorChannel <- err errorChannel <- err
close(errorChannel) close(errorChannel)

@ -42,8 +42,7 @@ type MemoryFactory struct {
func (f MemoryFactory) GetStartServerFunc() StartServerFunc { func (f MemoryFactory) GetStartServerFunc() StartServerFunc {
return func() (chan<- string, <-chan error) { return func() (chan<- string, <-chan error) {
_, _, driver := memory.Start(f.MaxMemory, f.Expiration) _, _, driver := memory.Start(f.MaxMemory, f.Expiration)
//ctrl, status, _ := httpserver.Start(api.HTTPHandler(f.Domain, driver), f.Config) ctrl, status, _ := httpserver.Start(api.HTTPHandler(driver), f.Config)
ctrl, status, _ := httpserver.Start(api.HTTPHandler("", driver), f.Config)
return ctrl, status return ctrl, status
} }
} }
@ -71,7 +70,7 @@ type DonutFactory struct {
func (f DonutFactory) GetStartServerFunc() StartServerFunc { func (f DonutFactory) GetStartServerFunc() StartServerFunc {
return func() (chan<- string, <-chan error) { return func() (chan<- string, <-chan error) {
_, _, driver := donut.Start(f.Paths) _, _, driver := donut.Start(f.Paths)
ctrl, status, _ := httpserver.Start(api.HTTPHandler("", driver), f.Config) ctrl, status, _ := httpserver.Start(api.HTTPHandler(driver), f.Config)
return ctrl, status return ctrl, status
} }
} }

Loading…
Cancel
Save