Merge pull request #8 from fkautz/pr_out_setting_up_initial_cli_options_and_http_handlers

Setting up initial cli options and http handlers
master
Anand Babu (AB) Periasamy 10 years ago
commit 428f012830
  1. 5
      Makefile
  2. 15
      gateway.go
  3. 27
      gateway_test.go
  4. 34
      minio/main.go
  5. 21
      server.go
  6. 15
      storage.go
  7. 27
      storage_test.go

@ -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

@ -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)
}

@ -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))
}
} }

@ -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)
}

@ -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")
}

@ -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…
Cancel
Save