Browse Source

Front-end / back-end in another files

Vova Tkach 6 years ago
parent
commit
384f7266e0
3 changed files with 34 additions and 19 deletions
  1. 5 0
      engine/backend.go
  2. 5 19
      engine/engine.go
  3. 24 0
      engine/frontend.go

+ 5 - 0
engine/backend.go

@@ -0,0 +1,5 @@
+package engine
+
+func (this *Engine) BackEnd() bool {
+	return false
+}

+ 5 - 19
engine/engine.go

@@ -2,7 +2,6 @@ package engine
 
 import (
 	"database/sql"
-	"fmt"
 	"net/http"
 	"os"
 	"strings"
@@ -32,7 +31,7 @@ func (this *Engine) Process() bool {
 	this.Wrap.IsBackend = this.Wrap.R.URL.Path == "/cp" || strings.HasPrefix(this.Wrap.R.URL.Path, "/cp/")
 	this.Wrap.ConfMysqlExists = utils.IsMySqlConfigExists(this.Wrap.DConfig + string(os.PathSeparator) + "mysql.json")
 
-	// Some system actions here...
+	// All actions here...
 	// MySQL install
 	// MySQL first user
 	// User login
@@ -74,22 +73,9 @@ func (this *Engine) Process() bool {
 		return true
 	}
 
-	// Front-end or back-end here...
-	if this.Wrap.R.URL.Path == "/" {
-		this.Wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
-		this.Wrap.W.Header().Set("Content-Type", "text/html")
-
-		counter := this.Wrap.S.GetInt("counter", 0)
-		// this.Wrap.LogAccess(fmt.Sprintf("Counter value was: %d", counter))
-
-		this.Wrap.W.Write([]byte(`Logic -> (` + fmt.Sprintf("%d", counter) + `)`))
-
-		counter++
-		this.Wrap.S.SetInt("counter", counter)
-		// this.Wrap.LogAccess(fmt.Sprintf("Counter value now: %d", counter))
-
-		return true
+	// Separated logic
+	if this.Wrap.IsBackend {
+		return this.BackEnd()
 	}
-
-	return false
+	return this.FrontEnd()
 }

+ 24 - 0
engine/frontend.go

@@ -0,0 +1,24 @@
+package engine
+
+import (
+	"fmt"
+)
+
+func (this *Engine) FrontEnd() bool {
+	if this.Wrap.R.URL.Path == "/" {
+		this.Wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+		this.Wrap.W.Header().Set("Content-Type", "text/html")
+
+		counter := this.Wrap.S.GetInt("counter", 0)
+		// this.Wrap.LogAccess(fmt.Sprintf("Counter value was: %d", counter))
+
+		this.Wrap.W.Write([]byte(`Logic -> (` + fmt.Sprintf("%d", counter) + `)`))
+
+		counter++
+		this.Wrap.S.SetInt("counter", counter)
+		// this.Wrap.LogAccess(fmt.Sprintf("Counter value now: %d", counter))
+
+		return true
+	}
+	return false
+}