fix nilled slices

This commit is contained in:
ykomissarov committed 2019-03-12 11:13:00 +03:00
1 parent cfac1dd58e
commit f4a7463eec
7 files changed
+13 -12

No files matched your search

+1 -1
View File
@@ -1 +1 @@
0.3.0
0.3.1
+4 -3
View File
@@ -128,7 +128,7 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
res := make([]*DomainWithServices, l)
for i, d := range domains {
idList[i] = d.Id
dws := &DomainWithServices{Id: d.Id, Name: d.Name, Description: d.Description}
dws := &DomainWithServices{Id: d.Id, Name: d.Name, Description: d.Description, Services: make([]*ServiceWithApps, 0)}
domainsMap[d.Id] = dws
res[i] = dws
}
@@ -143,7 +143,7 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
for i, s := range services {
idList[i] = s.Id
d := domainsMap[s.DomainId]
swa := &ServiceWithApps{Id: s.Id, Name: s.Name, Description: s.Description}
swa := &ServiceWithApps{Id: s.Id, Name: s.Name, Description: s.Description, Apps: make([]*SimpleApp, 0)}
d.Services = append(d.Services, swa)
servicesMap[s.Id] = swa
}
@@ -158,6 +158,7 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
Name: app.Name,
Type: app.Type,
Description: app.Description,
Tokens: make([]entity.Token, 0),
})
}
@@ -174,7 +175,7 @@ func enrichWithTokens(apps ...entity.Application) ([]*AppWithToken, error) {
enriched := make([]*AppWithToken, l)
for i, a := range apps {
idList[i] = a.Id
awt := &AppWithToken{App: a}
awt := &AppWithToken{App: a, Tokens: make([]entity.Token, 0)}
appMap[a.Id] = awt
enriched[i] = awt
}
+2 -2
View File
@@ -17,7 +17,7 @@ type AppRepository struct {
}
func (ar *AppRepository) GetApplications(list []int32) ([]entity.Application, error) {
var res []entity.Application
res := make([]entity.Application, 0)
q := ar.DB.Model(&res)
if len(res) > 0 {
q = q.Where("id IN (?)", pg.In(list))
@@ -27,7 +27,7 @@ func (ar *AppRepository) GetApplications(list []int32) ([]entity.Application, er
}
func (ar *AppRepository) GetApplicationsByServiceId(serviceId ...int32) ([]entity.Application, error) {
var res []entity.Application
res := make([]entity.Application, 0)
err := ar.DB.Model(&res).Where("service_id IN (?)", pg.In(serviceId)).Order("created_at DESC").Select()
return res, err
}
+2 -2
View File
@@ -17,7 +17,7 @@ type DomainRepository struct {
}
func (dr *DomainRepository) GetDomains(list []int32) ([]entity.Domain, error) {
var res []entity.Domain
res := make([]entity.Domain, 0)
q := dr.DB.Model(&res)
if len(res) > 0 {
q = q.Where("id IN (?)", pg.In(list))
@@ -27,7 +27,7 @@ func (dr *DomainRepository) GetDomains(list []int32) ([]entity.Domain, error) {
}
func (dr *DomainRepository) GetDomainsBySystemId(systemId int32) ([]entity.Domain, error) {
var res []entity.Domain
res := make([]entity.Domain, 0)
err := dr.DB.Model(&res).Where("system_id = ?", systemId).Order("created_at DESC").Select()
return res, err
}
+2 -2
View File
@@ -17,7 +17,7 @@ type ServiceRepository struct {
}
func (sr *ServiceRepository) GetServices(list []int32) ([]entity.Service, error) {
var res []entity.Service
res := make([]entity.Service, 0)
q := sr.DB.Model(&res)
if len(res) > 0 {
q = q.Where("id IN (?)", pg.In(list))
@@ -27,7 +27,7 @@ func (sr *ServiceRepository) GetServices(list []int32) ([]entity.Service, error)
}
func (sr *ServiceRepository) GetServicesByDomainId(domainId ...int32) ([]entity.Service, error) {
var res []entity.Service
res := make([]entity.Service, 0)
err := sr.DB.Model(&res).Where("domain_id IN (?)", pg.In(domainId)).Order("created_at DESC").Select()
return res, err
}
+1 -1
View File
@@ -18,7 +18,7 @@ type SystemRepository struct {
}
func (sr *SystemRepository) GetSystems(list []int32) ([]entity.System, error) {
var res []entity.System
res := make([]entity.System, 0)
q := sr.DB.Model(&res)
if len(res) > 0 {
q = q.Where("id IN (?)", pg.In(list))
+1 -1
View File
@@ -31,7 +31,7 @@ func (tr *TokenRepository) GetTokenById(id string) (*entity.Token, error) {
}
func (tr *TokenRepository) GetTokensByAppId(appId ...int32) ([]entity.Token, error) {
var res = make([]entity.Token, 0)
res := make([]entity.Token, 0)
err := tr.DB.Model(&res).Where("app_id IN (?)", pg.In(appId)).Order("created_at DESC").Select()
return res, err
}