From f46131255330f344363908a8ea4c7b6043c9d02a Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Fri, 9 Sep 2016 00:53:46 -0300 Subject: [PATCH] add required memory configuration to Route --- api/datastore/postgres/postgres.go | 11 ++++++++--- api/models/route.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/datastore/postgres/postgres.go b/api/datastore/postgres/postgres.go index 17df7086b..eb46f3cdc 100644 --- a/api/datastore/postgres/postgres.go +++ b/api/datastore/postgres/postgres.go @@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS routes ( app_name character varying(256) NOT NULL, path text NOT NULL, image character varying(256) NOT NULL, + memory integer NOT NULL, headers text NOT NULL, config text NOT NULL, PRIMARY KEY (app_name, path) @@ -31,7 +32,7 @@ const extrasTableCreate = `CREATE TABLE IF NOT EXISTS extras ( value character varying(256) NOT NULL );` -const routeSelector = `SELECT app_name, path, image, headers, config FROM routes` +const routeSelector = `SELECT app_name, path, image, memory, headers, config FROM routes` type rowScanner interface { Scan(dest ...interface{}) error @@ -182,6 +183,7 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err app_name, path, image, + memory, headers, config ) @@ -189,12 +191,14 @@ func (ds *PostgresDatastore) StoreRoute(route *models.Route) (*models.Route, err ON CONFLICT (app_name, path) DO UPDATE SET path = $2, image = $3, - headers = $4, - config = $5; + memory = $4, + headers = $5, + config = $6; `, route.AppName, route.Path, route.Image, + route.Memory, string(hbyte), string(cbyte), ) @@ -225,6 +229,7 @@ func scanRoute(scanner rowScanner, route *models.Route) error { &route.AppName, &route.Path, &route.Image, + &route.Memory, &headerStr, &configStr, ) diff --git a/api/models/route.go b/api/models/route.go index b83566290..e146311f3 100644 --- a/api/models/route.go +++ b/api/models/route.go @@ -24,6 +24,7 @@ type Route struct { AppName string `json:"appname,omitempty"` Path string `json:"path,omitempty"` Image string `json:"image,omitempty"` + Memory uint64 `json:"memory,omitempty"` Headers http.Header `json:"headers,omitempty"` Config `json:"config"` } @@ -43,6 +44,10 @@ func (r *Route) Validate() error { res = append(res, ErrRoutesValidationMissingImage) } + if r.Memory == 0 { + r.Memory = 128 + } + if r.AppName == "" { res = append(res, ErrRoutesValidationMissingAppName) }