Add nil checks for Action and Bind in translate function to prevent potential nil pointer dereferences

This commit is contained in:
Max 2024-11-08 07:22:15 +08:00
parent 13a343a7f4
commit 7efce91092

View file

@ -106,16 +106,16 @@ func (dsl *DSL) translate(name string, process *gouProcess.Process, data interfa
}
widgets := []string{}
if dsl.Action.Bind.Model != "" {
if dsl.Action != nil && dsl.Action.Bind != nil && dsl.Action.Bind.Model != "" {
m := model.Select(dsl.Action.Bind.Model)
widgets = append(widgets, fmt.Sprintf("model.%s", m.ID))
}
if dsl.Action.Bind.Table != "" {
if dsl.Action != nil && dsl.Action.Bind != nil && dsl.Action.Bind.Table != "" {
widgets = append(widgets, fmt.Sprintf("table.%s", dsl.Action.Bind.Table))
}
if dsl.Action.Bind.Form != "" {
if dsl.Action != nil && dsl.Action.Bind != nil && dsl.Action.Bind.Form != "" {
widgets = append(widgets, fmt.Sprintf("form.%s", dsl.Action.Bind.Form))
}