Browse Source

Test module, fixes, todo tips

Vova Tkach 6 years ago
parent
commit
2bb5c18f45
4 changed files with 39 additions and 8 deletions
  1. 11 0
      engine/engine.go
  2. 3 6
      modules/module_index.go
  3. 24 0
      modules/module_some.go
  4. 1 2
      modules/modules.go

+ 11 - 0
engine/engine.go

@@ -33,12 +33,19 @@ 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")
 	this.Wrap.UrlArgs = append(this.Wrap.UrlArgs, utils.UrlToArray(this.Wrap.R.URL.Path)...)
+	if this.Wrap.IsBackend && len(this.Wrap.UrlArgs) >= 1 && this.Wrap.UrlArgs[0] == "cp" {
+		this.Wrap.UrlArgs = this.Wrap.UrlArgs[1:]
+	}
 
 	// Action
 	if this.Mods.XXXActionFire(this.Wrap) {
 		return true
 	}
 
+	//
+	// TODO: make a redirect or display error page?
+	//
+
 	// Redirect to CP for creating MySQL config file
 	if !this.Wrap.IsBackend && !this.Wrap.ConfMysqlExists {
 		this.Wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
@@ -46,6 +53,10 @@ func (this *Engine) Process() bool {
 		return true
 	}
 
+	//
+	// TODO: show or not show configure MySQL form?
+	//
+
 	// Display MySQL install page on backend
 	if this.Wrap.IsBackend && !this.Wrap.ConfMysqlExists {
 		utils.SystemRenderTemplate(this.Wrap.W, assets.TmplCpMySql, nil)

+ 3 - 6
modules/module_index.go

@@ -1,7 +1,6 @@
 package modules
 
 import (
-	"fmt"
 	"net/http"
 
 	"golang-fave/engine/wrapper"
@@ -9,23 +8,21 @@ import (
 
 func (this *Modules) RegisterModule_Index() *Module {
 	return this.newModule(false, "index", "Pages", func(wrap *wrapper.Wrapper) {
-		//fmt.Printf("FrontEnd func call\n")
 		wrap.W.WriteHeader(http.StatusOK)
 		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-		wrap.W.Write([]byte(`FrontEnd func call`))
+		wrap.W.Write([]byte(`INDEX FrontEnd func call (` + wrap.CurrModule + `)`))
 	}, func(wrap *wrapper.Wrapper) {
-		//fmt.Printf("BackEnd func call\n")
 		wrap.W.WriteHeader(http.StatusOK)
 		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-		wrap.W.Write([]byte(`BackEnd func call`))
+		wrap.W.Write([]byte(`INDEX BackEnd func call (` + wrap.CurrModule + `)`))
 	})
 }
 
 func (this *Modules) RegisterAction_MysqlSetup() *Action {
 	return this.newAction(false, "mysql", func(wrap *wrapper.Wrapper) {
-		fmt.Printf("ActFunc func call\n")
+		wrap.MsgError(`Some error`)
 	})
 }
 

+ 24 - 0
modules/module_some.go

@@ -0,0 +1,24 @@
+package modules
+
+import (
+	"fmt"
+	"net/http"
+
+	"golang-fave/engine/wrapper"
+)
+
+func (this *Modules) RegisterModule_Some() *Module {
+	return this.newModule(false, "some", "Some Module", func(wrap *wrapper.Wrapper) {
+		fmt.Printf("SOME FrontEnd func call\n")
+		wrap.W.WriteHeader(http.StatusOK)
+		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
+		wrap.W.Write([]byte(`SOME FrontEnd func call (` + wrap.CurrModule + `)`))
+	}, func(wrap *wrapper.Wrapper) {
+		fmt.Printf("SOME BackEnd func call\n")
+		wrap.W.WriteHeader(http.StatusOK)
+		wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+		wrap.W.Header().Set("Content-Type", "text/html; charset=utf-8")
+		wrap.W.Write([]byte(`SOME BackEnd func call (` + wrap.CurrModule + `)`))
+	})
+}

+ 1 - 2
modules/modules.go

@@ -1,7 +1,6 @@
 package modules
 
 import (
-	//"fmt"
 	"net/http"
 	"reflect"
 	"strings"
@@ -86,7 +85,7 @@ func (this *Modules) getCurrentModule(wrap *wrapper.Wrapper) (*Module, string) {
 	var modCurr string = ""
 
 	// Some module
-	if len(wrap.UrlArgs) > 0 {
+	if len(wrap.UrlArgs) >= 1 {
 		if m, ok := this.mods[wrap.UrlArgs[0]]; ok {
 			mod = m
 			modCurr = wrap.UrlArgs[0]