Merge pull request #573 from harshavardhana/pr_out_get_rid_of_sub_domain_code_and_some_other_formatting_changes

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

@ -61,10 +61,10 @@ USAGE:
minio mode {{.Name}} limit SIZE expire TIME
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
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
`,
}
@ -93,11 +93,6 @@ EXAMPLES:
}
var flags = []cli.Flag{
// cli.StringFlag{
// Name: "domain",
// Value: "",
// Usage: "domain used for routing incoming API requests",
// },
cli.StringFlag{
Name: "api-address",
Value: ":9000",
@ -154,7 +149,7 @@ func runMemory(c *cli.Context) {
case "limit":
{
if maxMemorySet {
Fatalf("Limit should be set only once")
Fatalln("Limit should be set only once")
}
args = args.Tail()
maxMemory, err = humanize.ParseBytes(args.First())
@ -170,7 +165,7 @@ func runMemory(c *cli.Context) {
case "expire":
{
if expirationSet {
Fatalf("Expiration should be set only once")
Fatalln("Expiration should be set only once")
}
args = args.Tail()
expiration, err = time.ParseDuration(args.First())
@ -203,7 +198,7 @@ func runMemory(c *cli.Context) {
func runDonut(c *cli.Context) {
u, err := user.Current()
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 {
cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
@ -238,7 +233,6 @@ func getAPIServerConfig(c *cli.Context) httpserver.Config {
}
tls := (certFile != "" && keyFile != "")
return httpserver.Config{
// Domain: c.GlobalString("domain"),
Address: c.GlobalString("api-address"),
TLS: tls,
CertFile: certFile,
@ -248,7 +242,6 @@ func getAPIServerConfig(c *cli.Context) httpserver.Config {
func getWebServerConfigFunc(c *cli.Context) server.StartServerFunc {
config := httpserver.Config{
// Domain: c.GlobalString("domain"),
Address: c.GlobalString("web-address"),
TLS: false,
CertFile: "",

@ -30,12 +30,16 @@ import (
// private use
type minioAPI struct {
domain string
driver drivers.Driver
}
// Path based routing
func pathMux(api minioAPI, mux *router.Router) *router.Router {
// HTTPHandler - http wrapper handler
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("/{bucket}", api.listObjectsHandler).Methods("GET")
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.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{}
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 = ignoreResourcesHandler(h)

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

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

@ -42,8 +42,7 @@ type MemoryFactory struct {
func (f MemoryFactory) GetStartServerFunc() StartServerFunc {
return func() (chan<- string, <-chan error) {
_, _, 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
}
}
@ -71,7 +70,7 @@ type DonutFactory struct {
func (f DonutFactory) GetStartServerFunc() StartServerFunc {
return func() (chan<- string, <-chan error) {
_, _, 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
}
}

Loading…
Cancel
Save