Browse Source

Protect code, can be nil

Vova Tkach 6 years ago
parent
commit
9596a9d377
3 changed files with 37 additions and 19 deletions
  1. 20 10
      engine/fetdata/content.go
  2. 5 3
      engine/fetdata/fetdata.go
  3. 12 6
      engine/fetdata/meta_data.go

+ 20 - 10
engine/fetdata/content.go

@@ -8,36 +8,46 @@ import (
 )
 
 func (this *FERData) Name() string {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_name
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_name
+		}
 	}
 	return ""
 }
 
 func (this *FERData) Alias() string {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_alias
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_alias
+		}
 	}
 	return ""
 }
 
 func (this *FERData) Content() template.HTML {
-	if this.Wrap.CurrModule == "index" {
-		return template.HTML(this.DataRow.(*utils.MySql_page).A_content)
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return template.HTML(this.DataRow.(*utils.MySql_page).A_content)
+		}
 	}
 	return template.HTML("")
 }
 
 func (this *FERData) DateTime() int {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_datetime
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_datetime
+		}
 	}
 	return 0
 }
 
 func (this *FERData) DateTimeFormat(format string) string {
-	if this.Wrap.CurrModule == "index" {
-		return time.Unix(int64(this.DataRow.(*utils.MySql_page).A_datetime), 0).Format(format)
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return time.Unix(int64(this.DataRow.(*utils.MySql_page).A_datetime), 0).Format(format)
+		}
 	}
 	return ""
 }

+ 5 - 3
engine/fetdata/fetdata.go

@@ -21,9 +21,11 @@ func New(wrap *wrapper.Wrapper, drow interface{}) *FERData {
 }
 
 func (this *FERData) init() *FERData {
-	if this.Wrap.CurrModule == "index" {
-		if this.DataRow.(*utils.MySql_page).A_meta_title == "" {
-			this.DataRow.(*utils.MySql_page).A_meta_title = this.DataRow.(*utils.MySql_page).A_name
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			if this.DataRow.(*utils.MySql_page).A_meta_title == "" {
+				this.DataRow.(*utils.MySql_page).A_meta_title = this.DataRow.(*utils.MySql_page).A_name
+			}
 		}
 	}
 	return this

+ 12 - 6
engine/fetdata/meta_data.go

@@ -5,22 +5,28 @@ import (
 )
 
 func (this *FERData) MetaTitle() string {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_meta_title
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_meta_title
+		}
 	}
 	return ""
 }
 
 func (this *FERData) MetaKeywords() string {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_meta_keywords
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_meta_keywords
+		}
 	}
 	return ""
 }
 
 func (this *FERData) MetaDescription() string {
-	if this.Wrap.CurrModule == "index" {
-		return this.DataRow.(*utils.MySql_page).A_meta_description
+	if this.DataRow != nil {
+		if this.Wrap.CurrModule == "index" {
+			return this.DataRow.(*utils.MySql_page).A_meta_description
+		}
 	}
 	return ""
 }