Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving postgres marshal/unmarshal issue #610

Merged
merged 3 commits into from
Mar 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions api/datastore/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -410,14 +420,21 @@ func scanRoute(scanner rowScanner, route *models.Route) error {
return err
}

if headerStr == "" {
return models.ErrRoutesNotFound
if len(headerStr) > 0 {
err = json.Unmarshal([]byte(headerStr), &route.Headers)
if err != nil {
return err
}
}

if err := json.Unmarshal([]byte(headerStr), &route.Headers); err != nil {
return err
if len(configStr) > 0 {
err = json.Unmarshal([]byte(configStr), &route.Config)
if err != nil {
return err
}
}
return json.Unmarshal([]byte(configStr), &route.Config)

return nil
}

func (ds *PostgresDatastore) GetRoute(ctx context.Context, appName, routePath string) (*models.Route, error) {
Expand Down