mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Solving postgres marshal/unmarshal issue (#610)
* Solving postgres marshal/unmarshal issue Postgres datastore was not marshaling the App config during its insert, that behavior was resulting in issues when fetching the App and the datastore couldn't unmarshal the config. The same issue was probably happening with the Route's headers in some situations. This commit's idea is to always try to marshal configs and headers when inserting/updating Apps or Routes. But in Apps and Routes get methods, if the config/headers unmarshal fails, it returns an empty config/headers. * fix one more unmarshal case * returning error when unmarshaling non-empty
This commit is contained in:
committed by
Travis Reeder
parent
5761ce3499
commit
5e8340bc1c
@@ -121,7 +121,7 @@ func (ds *PostgresDatastore) UpdateApp(ctx context.Context, newapp *models.App)
|
||||
return err
|
||||
}
|
||||
|
||||
if config != "" {
|
||||
if len(config) > 0 {
|
||||
err := json.Unmarshal([]byte(config), &app.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -186,7 +186,10 @@ func (ds *PostgresDatastore) GetApp(ctx context.Context, name string) (*models.A
|
||||
}
|
||||
|
||||
if len(config) > 0 {
|
||||
json.Unmarshal([]byte(config), &res.Config)
|
||||
err := json.Unmarshal([]byte(config), &res.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -203,7 +206,14 @@ func scanApp(scanner rowScanner, app *models.App) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(configStr), &app.Config)
|
||||
if len(configStr) > 0 {
|
||||
err = json.Unmarshal([]byte(configStr), &app.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *PostgresDatastore) GetApps(ctx context.Context, filter *models.AppFilter) ([]*models.App, error) {
|
||||
@@ -410,14 +420,21 @@ func scanRoute(scanner rowScanner, route *models.Route) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if headerStr == "" {
|
||||
return models.ErrRoutesNotFound
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(headerStr), &route.Headers); err != nil {
|
||||
if len(headerStr) > 0 {
|
||||
err = json.Unmarshal([]byte(headerStr), &route.Headers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal([]byte(configStr), &route.Config)
|
||||
}
|
||||
|
||||
if len(configStr) > 0 {
|
||||
err = json.Unmarshal([]byte(configStr), &route.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *PostgresDatastore) GetRoute(ctx context.Context, appName, routePath string) (*models.Route, error) {
|
||||
|
||||
Reference in New Issue
Block a user