Browse Source

Code refactoring

Vova Tkach 6 years ago
parent
commit
cefae87147

+ 1 - 1
backend.go

@@ -8,7 +8,7 @@ import (
 
 func handleBackEnd(wrapper *wrapper.Wrapper) bool {
 	// MySQL config page
-	if !utils.IsMySqlConfigExists(wrapper.DirVhostHome) {
+	if !utils.IsMySqlConfigExists(wrapper.DirVHostHome) {
 		return wrapper.TmplBackEnd(templates.CpMySQL, nil)
 	}
 

+ 1 - 1
engine/actions/action_mysql.go

@@ -58,7 +58,7 @@ func (this *Action) Action_mysql() {
 	// Try to install all tables
 
 	// Save mysql config file
-	err = utils.MySqlConfigWrite(this.wrapper.DirVhostHome, pf_host, pf_port, pf_name, pf_user, pf_password)
+	err = utils.MySqlConfigWrite(this.wrapper.DirVHostHome, pf_host, pf_port, pf_name, pf_user, pf_password)
 	if err != nil {
 		this.msg_error(err.Error())
 		return

+ 0 - 4
engine/actions/action_signin.go

@@ -1,9 +1,5 @@
 package actions
 
-import (
-	"fmt"
-)
-
 func (this *Action) Action_signin() {
 	this.msg_success(`Hello from web server`)
 }

+ 1 - 1
engine/wrapper/redirects.go

@@ -7,7 +7,7 @@ import (
 )
 
 func (this *Wrapper) redirectToMainDomain() bool {
-	file, err := ioutil.ReadFile(this.DirVhostHome + "/config/domain")
+	file, err := ioutil.ReadFile(this.DirVHostHome + "/config/domain")
 	if err == nil {
 		maindomain := strings.TrimSpace(string(file))
 		port := ""

+ 9 - 9
engine/wrapper/static.go

@@ -80,31 +80,31 @@ func (this *Wrapper) staticResource() bool {
 func (this *Wrapper) staticFile() bool {
 	file := this.R.URL.Path
 	if file != "/" {
-		f, err := os.Open(this.DirVhostHome + "/htdocs" + file)
+		f, err := os.Open(this.DirVHostHome + "/htdocs" + file)
 		if err == nil {
 			defer f.Close()
-			st, err := os.Stat(this.DirVhostHome + "/htdocs" + file)
+			st, err := os.Stat(this.DirVHostHome + "/htdocs" + file)
 			if err != nil {
 				return false
 			}
 			if st.Mode().IsDir() {
 				return false
 			}
-			http.ServeFile(*this.W, this.R, this.DirVhostHome+"/htdocs"+file)
+			http.ServeFile(*this.W, this.R, this.DirVHostHome+"/htdocs"+file)
 			return true
 		}
 	} else {
-		f, err := os.Open(this.DirVhostHome + "/htdocs/index.html")
+		f, err := os.Open(this.DirVHostHome + "/htdocs/index.html")
 		if err == nil {
 			defer f.Close()
-			st, err := os.Stat(this.DirVhostHome + "/htdocs/index.html")
+			st, err := os.Stat(this.DirVHostHome + "/htdocs/index.html")
 			if err != nil {
 				return false
 			}
 			if st.Mode().IsDir() {
 				return false
 			}
-			http.ServeFile(*this.W, this.R, this.DirVhostHome+"/htdocs/index.html")
+			http.ServeFile(*this.W, this.R, this.DirVHostHome+"/htdocs/index.html")
 			return true
 		}
 	}
@@ -113,10 +113,10 @@ func (this *Wrapper) staticFile() bool {
 
 func (this *Wrapper) printPageDefault() {
 	// Custom page
-	f, err := os.Open(this.DirVhostHome + "/htdocs" + "/index.html")
+	f, err := os.Open(this.DirVHostHome + "/htdocs" + "/index.html")
 	if err == nil {
 		defer f.Close()
-		http.ServeFile(*this.W, this.R, this.DirVhostHome+"/htdocs"+"/index.html")
+		http.ServeFile(*this.W, this.R, this.DirVHostHome+"/htdocs"+"/index.html")
 		return
 	}
 
@@ -135,7 +135,7 @@ func (this *Wrapper) printPageDefault() {
 
 func (this *Wrapper) printPage404() {
 	// Custom 404 error page
-	f, err := ioutil.ReadFile(this.DirVhostHome + "/htdocs" + "/404.html")
+	f, err := ioutil.ReadFile(this.DirVHostHome + "/htdocs" + "/404.html")
 	if err == nil {
 		(*this.W).WriteHeader(http.StatusNotFound)
 		(*this.W).Header().Set("Content-Type", "text/html")

+ 9 - 9
engine/wrapper/wrapper.go

@@ -40,7 +40,7 @@ type Wrapper struct {
 	VHost        string
 	Port         string
 	DirWww       string
-	DirVhostHome string
+	DirVHostHome string
 	RemoteIp     string
 	LoggerAcc    *log.Logger
 	LoggerErr    *log.Logger
@@ -69,7 +69,7 @@ func New(w *http.ResponseWriter, r *http.Request, vhost string, port string, www
 		VHost:        vhost,
 		Port:         port,
 		DirWww:       wwwdir,
-		DirVhostHome: vhosthome,
+		DirVHostHome: vhosthome,
 		W:            w,
 		R:            r,
 		Debug:        debug,
@@ -86,7 +86,7 @@ func (this *Wrapper) Run(hRun handleRun) {
 
 	// Attach file for access log
 	if !this.Debug {
-		acclogfile, acclogfileerr := os.OpenFile(this.DirVhostHome+"/logs/access.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+		acclogfile, acclogfileerr := os.OpenFile(this.DirVHostHome+"/logs/access.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
 		if acclogfileerr == nil {
 			defer acclogfile.Close()
 			this.LoggerAcc.SetOutput(acclogfile)
@@ -95,7 +95,7 @@ func (this *Wrapper) Run(hRun handleRun) {
 
 	// Attach file for access log
 	if !this.Debug {
-		errlogfile, errlogfileerr := os.OpenFile(this.DirVhostHome+"/logs/error.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+		errlogfile, errlogfileerr := os.OpenFile(this.DirVHostHome+"/logs/error.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
 		if errlogfileerr == nil {
 			defer errlogfile.Close()
 			this.LoggerErr.SetOutput(errlogfile)
@@ -132,7 +132,7 @@ func (this *Wrapper) Run(hRun handleRun) {
 	}
 
 	// Create and load session
-	this.Session = sessions.New(this.W, this.R, this.VHost, this.DirVhostHome, this.RemoteIp)
+	this.Session = sessions.New(this.W, this.R, this.VHost, this.DirVHostHome, this.RemoteIp)
 	this.Session.Load()
 
 	// Set session vars
@@ -176,10 +176,10 @@ func (this *Wrapper) LogError(value string) {
 
 func (this *Wrapper) TmplFrontEnd(tname string, data interface{}) bool {
 	tmpl, err := template.ParseFiles(
-		this.DirVhostHome+"/template"+"/"+tname+".html",
-		this.DirVhostHome+"/template"+"/header.html",
-		this.DirVhostHome+"/template"+"/sidebar.html",
-		this.DirVhostHome+"/template"+"/footer.html",
+		this.DirVHostHome+"/template"+"/"+tname+".html",
+		this.DirVHostHome+"/template"+"/header.html",
+		this.DirVHostHome+"/template"+"/sidebar.html",
+		this.DirVHostHome+"/template"+"/footer.html",
 	)
 	if err != nil {
 		this.printTmplPageError(err)

+ 1 - 1
frontend.go

@@ -22,7 +22,7 @@ type TmplData struct {
 
 func handleFrontEnd(wrapper *wrapper.Wrapper) bool {
 	// Redirect to CP, if MySQL config file is not exists
-	if !utils.IsMySqlConfigExists(wrapper.DirVhostHome) {
+	if !utils.IsMySqlConfigExists(wrapper.DirVHostHome) {
 		(*wrapper.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 		http.Redirect(*wrapper.W, wrapper.R, wrapper.R.URL.Scheme+"://"+wrapper.R.Host+"/cp/", 302)
 		return true