From 9387e9bc414f01cbde68dfa7a0c21a630cc3feaa Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Fri, 2 Dec 2016 22:44:57 -0200 Subject: [PATCH] fix postgres GetApp bug when filter is nil (#383) --- api/datastore/postgres/postgres.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/api/datastore/postgres/postgres.go b/api/datastore/postgres/postgres.go index 28c318d7e..4c0f48aa0 100644 --- a/api/datastore/postgres/postgres.go +++ b/api/datastore/postgres/postgres.go @@ -482,16 +482,18 @@ func (ds *PostgresDatastore) GetRoutesByApp(ctx context.Context, appName string, func buildFilterAppQuery(filter *models.AppFilter) string { filterQuery := "" - filterQueries := []string{} - if filter.Name != "" { - filterQueries = append(filterQueries, fmt.Sprintf("name LIKE '%s'", filter.Name)) - } + if filter != nil { + filterQueries := []string{} + if filter.Name != "" { + filterQueries = append(filterQueries, fmt.Sprintf("name LIKE '%s'", filter.Name)) + } - for i, field := range filterQueries { - if i == 0 { - filterQuery = fmt.Sprintf("WHERE %s ", field) - } else { - filterQuery = fmt.Sprintf("%s AND %s", filterQuery, field) + for i, field := range filterQueries { + if i == 0 { + filterQuery = fmt.Sprintf("WHERE %s ", field) + } else { + filterQuery = fmt.Sprintf("%s AND %s", filterQuery, field) + } } }