mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Merge pull request #8 from fkautz/pr_out_setting_up_initial_cli_options_and_http_handlers
Setting up initial cli options and http handlers
This commit is contained in:
commit
428f012830
5
Makefile
5
Makefile
@ -1,6 +1,6 @@
|
|||||||
GOPATH := $(CURDIR)/tmp/gopath
|
GOPATH := $(CURDIR)/tmp/gopath
|
||||||
|
|
||||||
all: build copy_bin
|
all: build test copy_bin
|
||||||
|
|
||||||
copy_bin:
|
copy_bin:
|
||||||
cp tmp/gopath/bin/* bin/
|
cp tmp/gopath/bin/* bin/
|
||||||
@ -12,6 +12,9 @@ stage_build:
|
|||||||
rsync -a . tmp/gopath/src/github.com/minios/minios/
|
rsync -a . tmp/gopath/src/github.com/minios/minios/
|
||||||
rsync -a third_party/* tmp/gopath
|
rsync -a third_party/* tmp/gopath
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test github.com/minios/minios
|
||||||
|
go test github.com/minios/minios/minio
|
||||||
|
|
||||||
build: stage_build
|
build: stage_build
|
||||||
go install github.com/minios/minios/minio
|
go install github.com/minios/minios/minio
|
||||||
|
15
gateway.go
Normal file
15
gateway.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package minio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GatewayHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
fmt.Fprintf(w, "Gateway")
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterGatewayHandlers(router *mux.Router) {
|
||||||
|
router.HandleFunc("/gateway/rpc", GatewayHandler)
|
||||||
|
}
|
27
gateway_test.go
Normal file
27
gateway_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package minio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrintsGateway(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(GatewayHandler))
|
||||||
|
defer server.Close()
|
||||||
|
res, err := http.Get(server.URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
bodyString := string(body)
|
||||||
|
if bodyString != "Gateway" {
|
||||||
|
log.Fatal("Expected 'Gateway', Received '" + bodyString + "'")
|
||||||
|
}
|
||||||
|
}
|
@ -2,12 +2,40 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/minios/minios"
|
"github.com/minios/minios"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cli.NewApp().Run(os.Args)
|
app := cli.NewApp()
|
||||||
server := minio.Server{}
|
router := mux.NewRouter()
|
||||||
server.Start()
|
runServer := false
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "storage",
|
||||||
|
Usage: "Start a storage node",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
minio.RegisterStorageHandlers(router)
|
||||||
|
runServer = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "gateway",
|
||||||
|
Usage: "Start a gateway node",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
minio.RegisterGatewayHandlers(router)
|
||||||
|
runServer = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("App failed to load", err)
|
||||||
|
}
|
||||||
|
if runServer {
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", router))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
21
server.go
21
server.go
@ -1,21 +0,0 @@
|
|||||||
package minio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Server struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) Start() error {
|
|
||||||
r := mux.NewRouter()
|
|
||||||
r.HandleFunc("/", HelloHandler)
|
|
||||||
fmt.Println("Running http server on port 8080")
|
|
||||||
return http.ListenAndServe(":8080", r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func HelloHandler(w http.ResponseWriter, req *http.Request) {
|
|
||||||
fmt.Fprintf(w, "Host: "+req.Host)
|
|
||||||
}
|
|
15
storage.go
Normal file
15
storage.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package minio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterStorageHandlers(router *mux.Router) {
|
||||||
|
router.HandleFunc("/storage/rpc", StorageHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StorageHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
fmt.Fprintf(w, "Storage")
|
||||||
|
}
|
27
storage_test.go
Normal file
27
storage_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package minio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrintsStorage(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(StorageHandler))
|
||||||
|
defer server.Close()
|
||||||
|
res, err := http.Get(server.URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
bodyString := string(body)
|
||||||
|
if bodyString != "Storage" {
|
||||||
|
log.Fatal("Expected 'Storage', Received '" + bodyString + "'")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user