Removed "name" from route, only need path.

This commit is contained in:
Travis Reeder
2016-08-07 14:58:05 -04:00
parent 40e1ebd434
commit 3d94fc64c9
8 changed files with 39 additions and 37 deletions

View File

@@ -191,7 +191,7 @@ func (ds *BoltDatastore) StoreRoute(route *models.Route) (*models.Route, error)
return err
}
err = b.Put([]byte(route.Name), buf)
err = b.Put([]byte(route.Path), buf)
if err != nil {
return err
}

View File

@@ -28,7 +28,6 @@ func TestBolt(t *testing.T) {
}
testRoute := &models.Route{
Name: "test",
AppName: testApp.Name,
Path: "/test",
Image: "iron/hello",
@@ -114,12 +113,12 @@ func TestBolt(t *testing.T) {
t.Fatalf("Test GetRoute: expected error when using empty app name", err)
}
route, err := ds.GetRoute(testApp.Name, testRoute.Name)
route, err := ds.GetRoute(testApp.Name, testRoute.Path)
if err != nil {
t.Fatalf("Test GetRoute: error: %s", err)
}
if route.Name != testRoute.Name {
t.Fatalf("Test GetRoute: expected `route.Name` to be `%s` but it was `%s`", route.Name, testRoute.Name)
if route.Path != testRoute.Path {
t.Fatalf("Test GetRoute: expected `route.Name` to be `%s` but it was `%s`", route.Path, testRoute.Path)
}
// Testing list routes
@@ -130,8 +129,8 @@ func TestBolt(t *testing.T) {
if len(routes) == 0 {
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
}
if routes[0].Name != testRoute.Name {
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Name, routes[0].Name)
if routes[0].Path != testRoute.Path {
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
}
// Testing app delete
@@ -145,12 +144,12 @@ func TestBolt(t *testing.T) {
t.Fatalf("Test RemoveRoute: expected error when using empty route name", err)
}
err = ds.RemoveRoute(testRoute.AppName, testRoute.Name)
err = ds.RemoveRoute(testRoute.AppName, testRoute.Path)
if err != nil {
t.Fatalf("Test RemoveApp: error: %s", err)
}
route, err = ds.GetRoute(testRoute.AppName, testRoute.Name)
route, err = ds.GetRoute(testRoute.AppName, testRoute.Path)
if err != nil {
t.Fatalf("Test GetRoute: error: %s", err)
}

View File

@@ -13,9 +13,8 @@ import (
const routesTableCreate = `
CREATE TABLE IF NOT EXISTS routes (
name character varying(256) NOT NULL PRIMARY KEY,
app_name character varying(256) NOT NULL,
path text NOT NULL,
app_name character varying(256) NOT NULL,
image character varying(256) NOT NULL,
headers text NOT NULL
);`
@@ -24,7 +23,7 @@ const appsTableCreate = `CREATE TABLE IF NOT EXISTS apps (
name character varying(256) NOT NULL PRIMARY KEY
);`
const routeSelector = `SELECT name, path, app_name, image, headers FROM routes`
const routeSelector = `SELECT app_name, path, image, headers FROM routes`
type rowScanner interface {
Scan(dest ...interface{}) error
@@ -159,16 +158,15 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err
_, err = ds.db.Exec(`
INSERT INTO routes (
name, app_name, path, image,
app_name, path, image,
headers
)
VALUES ($1, $2, $3, $4, $5, $6, $7)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (name) DO UPDATE SET
path = $3,
image = $4,
headers = $5;
path = $1,
image = $2,
headers = $3;
`,
route.Name,
route.AppName,
route.Path,
route.Image,
@@ -196,9 +194,9 @@ func (ds *PostgresDatastore) RemoveRoute(appName, routeName string) error {
func scanRoute(scanner rowScanner, route *models.Route) error {
var headerStr string
err := scanner.Scan(
&route.Name,
&route.Path,
// &route.Name,
&route.AppName,
&route.Path,
&route.Image,
&headerStr,
)

16
api/ifaces/app.go Normal file
View File

@@ -0,0 +1,16 @@
package ifaces
import "net/http"
type App interface {
Name() string
Routes() Route
Validate() error
}
type Route interface {
// AppName() string `json:"appname"`
Path() string
Image() string
Headers() http.Header
}

View File

@@ -21,7 +21,6 @@ var (
type Routes []*Route
type Route struct {
Name string `json:"name"`
AppName string `json:"appname"`
Path string `json:"path"`
Image string `json:"image"`
@@ -39,10 +38,6 @@ var (
func (r *Route) Validate() error {
var res []error
if r.Name == "" {
res = append(res, ErrRoutesValidationMissingName)
}
if r.Image == "" {
res = append(res, ErrRoutesValidationMissingImage)
}

View File

@@ -27,7 +27,8 @@ func handleRouteUpdate(c *gin.Context) {
}
wroute.Route.AppName = c.Param("app")
wroute.Route.Name = c.Param("route")
log.Infoln("Route: ", c.Param("route"))
wroute.Route.Path = c.Param("route")
if err := wroute.Validate(); err != nil {
log.Error(err)