mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Postgres datastore errors and cleanup (#579)
* improved postgres datastore error handling * remove excess postgres datastore validation * postgres datastore errors and cleanup
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
3fcdca73a7
commit
690d0d92e4
@@ -159,7 +159,7 @@ func Test(t *testing.T, ds models.Datastore) {
|
|||||||
}
|
}
|
||||||
if app != nil {
|
if app != nil {
|
||||||
t.Log(buf.String())
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: failed to remove the app")
|
t.Fatal("Test RemoveApp: failed to remove the app")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test update inexistent app
|
// Test update inexistent app
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ type rowScanner interface {
|
|||||||
Scan(dest ...interface{}) error
|
Scan(dest ...interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type rowQuerier interface {
|
|
||||||
QueryRow(query string, args ...interface{}) *sql.Row
|
|
||||||
}
|
|
||||||
|
|
||||||
type PostgresDatastore struct {
|
type PostgresDatastore struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
}
|
}
|
||||||
@@ -88,14 +84,6 @@ func (ds *PostgresDatastore) InsertApp(ctx context.Context, app *models.App) (*m
|
|||||||
var cbyte []byte
|
var cbyte []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if app == nil {
|
|
||||||
return nil, models.ErrDatastoreEmptyApp
|
|
||||||
}
|
|
||||||
|
|
||||||
if app.Name == "" {
|
|
||||||
return nil, models.ErrDatastoreEmptyAppName
|
|
||||||
}
|
|
||||||
|
|
||||||
if app.Config != nil {
|
if app.Config != nil {
|
||||||
cbyte, err = json.Marshal(app.Config)
|
cbyte, err = json.Marshal(app.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -185,17 +173,18 @@ func (ds *PostgresDatastore) GetApp(ctx context.Context, name string) (*models.A
|
|||||||
var resName string
|
var resName string
|
||||||
var config string
|
var config string
|
||||||
err := row.Scan(&resName, &config)
|
err := row.Scan(&resName, &config)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return nil, models.ErrAppsNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
res := &models.App{
|
res := &models.App{
|
||||||
Name: resName,
|
Name: resName,
|
||||||
}
|
}
|
||||||
|
|
||||||
json.Unmarshal([]byte(config), &res.Config)
|
if err := json.Unmarshal([]byte(config), &res.Config); err != nil {
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return nil, models.ErrAppsNotFound
|
|
||||||
}
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,10 +198,11 @@ func scanApp(scanner rowScanner, app *models.App) error {
|
|||||||
&app.Name,
|
&app.Name,
|
||||||
&configStr,
|
&configStr,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
json.Unmarshal([]byte(configStr), &app.Config)
|
return json.Unmarshal([]byte(configStr), &app.Config)
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *PostgresDatastore) GetApps(ctx context.Context, filter *models.AppFilter) ([]*models.App, error) {
|
func (ds *PostgresDatastore) GetApps(ctx context.Context, filter *models.AppFilter) ([]*models.App, error) {
|
||||||
@@ -411,15 +401,18 @@ func scanRoute(scanner rowScanner, route *models.Route) error {
|
|||||||
&headerStr,
|
&headerStr,
|
||||||
&configStr,
|
&configStr,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if headerStr == "" {
|
if headerStr == "" {
|
||||||
return models.ErrRoutesNotFound
|
return models.ErrRoutesNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
json.Unmarshal([]byte(headerStr), &route.Headers)
|
if err := json.Unmarshal([]byte(headerStr), &route.Headers); err != nil {
|
||||||
json.Unmarshal([]byte(configStr), &route.Config)
|
return err
|
||||||
|
}
|
||||||
return err
|
return json.Unmarshal([]byte(configStr), &route.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *PostgresDatastore) GetRoute(ctx context.Context, appName, routePath string) (*models.Route, error) {
|
func (ds *PostgresDatastore) GetRoute(ctx context.Context, appName, routePath string) (*models.Route, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user