mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
fix: nil error if init data is empty (#1247)
This commit is contained in:
parent
6bb7b545b4
commit
9d5b019243
@ -56,12 +56,40 @@ func readInitDataFromFile(filePath string) *InitData {
|
||||
|
||||
s := util.ReadStringFromPath(filePath)
|
||||
|
||||
data := &InitData{}
|
||||
data := &InitData{
|
||||
Organizations: []*Organization{},
|
||||
Applications: []*Application{},
|
||||
Users: []*User{},
|
||||
Certs: []*Cert{},
|
||||
Providers: []*Provider{},
|
||||
Ldaps: []*Ldap{},
|
||||
}
|
||||
err := util.JsonToStruct(s, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// transform nil slice to empty slice
|
||||
for _, organization := range data.Organizations {
|
||||
if organization.Tags == nil {
|
||||
organization.Tags = []string{}
|
||||
}
|
||||
}
|
||||
for _, application := range data.Applications {
|
||||
if application.Providers == nil {
|
||||
application.Providers = []*ProviderItem{}
|
||||
}
|
||||
if application.SignupItems == nil {
|
||||
application.SignupItems = []*SignupItem{}
|
||||
}
|
||||
if application.GrantTypes == nil {
|
||||
application.GrantTypes = []string{}
|
||||
}
|
||||
if application.RedirectUris == nil {
|
||||
application.RedirectUris = []string{}
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user