|
@@ -2,22 +2,16 @@ package actions
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "net/http"
|
|
|
"strings"
|
|
|
|
|
|
- "golang-fave/engine/sessions"
|
|
|
+ "golang-fave/engine/wrapper"
|
|
|
)
|
|
|
|
|
|
type hRun func(e *Action)
|
|
|
|
|
|
type Action struct {
|
|
|
- W *http.ResponseWriter
|
|
|
- R *http.Request
|
|
|
- VHost string
|
|
|
- VHostHome string
|
|
|
- RemoteIp string
|
|
|
- Session *sessions.Session
|
|
|
- list map[string]hRun
|
|
|
+ w *wrapper.Wrapper
|
|
|
+ list map[string]hRun
|
|
|
}
|
|
|
|
|
|
func (e *Action) register(name string, handle hRun) {
|
|
@@ -25,7 +19,7 @@ func (e *Action) register(name string, handle hRun) {
|
|
|
}
|
|
|
|
|
|
func (e *Action) write(data string) {
|
|
|
- (*e.W).Write([]byte(data))
|
|
|
+ (*e.w.W).Write([]byte(data))
|
|
|
}
|
|
|
|
|
|
func (e *Action) msg_show(title string, msg string) {
|
|
@@ -43,8 +37,8 @@ func (e *Action) msg_error(msg string) {
|
|
|
e.msg_show("Error", msg)
|
|
|
}
|
|
|
|
|
|
-func New(w *http.ResponseWriter, r *http.Request, vhost string, vhosthome string, remoteip string, session *sessions.Session) *Action {
|
|
|
- act := Action{w, r, vhost, vhosthome, remoteip, session, make(map[string]hRun)}
|
|
|
+func New(w *wrapper.Wrapper) *Action {
|
|
|
+ act := Action{w, make(map[string]hRun)}
|
|
|
|
|
|
// Register all action here
|
|
|
act.register("mysql", action_mysql)
|
|
@@ -54,17 +48,17 @@ func New(w *http.ResponseWriter, r *http.Request, vhost string, vhosthome string
|
|
|
}
|
|
|
|
|
|
func (e *Action) Call() bool {
|
|
|
- if e.R.Method != "POST" {
|
|
|
+ if e.w.R.Method != "POST" {
|
|
|
return false
|
|
|
}
|
|
|
- if err := e.R.ParseForm(); err == nil {
|
|
|
- action := e.R.FormValue("action")
|
|
|
+ if err := e.w.R.ParseForm(); err == nil {
|
|
|
+ action := e.w.R.FormValue("action")
|
|
|
if action != "" {
|
|
|
- fn, ok := e.list[action]
|
|
|
+ function, ok := e.list[action]
|
|
|
if ok {
|
|
|
- (*e.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
- (*e.W).Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
- fn(e)
|
|
|
+ (*e.w.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
+ (*e.w.W).Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
|
+ function(e)
|
|
|
return true
|
|
|
}
|
|
|
}
|