-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontroller.go
137 lines (109 loc) · 3.6 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package trygo
import (
"net/http"
)
type ControllerInterface interface {
Init(app *App, ctx *Context, controllerName, methodName string)
Prepare()
Get()
Post()
Delete()
Put()
Head()
Patch()
Options()
Finish()
}
type Controller struct {
Data map[interface{}]interface{}
Ctx *Context
ControllerName string
ActionName string
TplNames string
TplExt string
App *App
}
func (c *Controller) Init(app *App, ctx *Context, controllerName, actionName string) {
c.Data = make(map[interface{}]interface{})
c.App = app
c.ControllerName = controllerName
c.ActionName = actionName
c.Ctx = ctx
c.TplExt = "tpl"
}
func (c *Controller) Prepare() {
}
func (c *Controller) Finish() {
}
func (c *Controller) Get() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Post() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Delete() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Put() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Head() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Patch() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Options() {
http.Error(c.Ctx.ResponseWriter, "Method Not Allowed", http.StatusMethodNotAllowed)
}
func (c *Controller) Redirect(url string, code int) {
c.Ctx.Redirect(code, url)
}
func (c *Controller) Error(message string, code int) {
c.Ctx.ResponseWriter.Error(message, code)
}
func (c *Controller) Render(data ...interface{}) *render {
return Render(c.Ctx, data...)
}
func (c *Controller) RenderTemplate() *render {
if c.TplNames == "" {
c.TplNames = c.ControllerName + "/" + c.ActionName + "." + c.TplExt
}
return RenderTemplate(c.Ctx, c.TplNames, c.Data)
}
func (c *Controller) RenderFile(filename string) *render {
return RenderFile(c.Ctx, filename)
}
//func (c *Controller) Render(contentType string, data []byte) (err error) {
// return Render(c.Ctx.ResponseWriter, contentType, data)
//}
//func (c *Controller) RenderHtml(content string) (err error) {
// return RenderHtml(c.Ctx.ResponseWriter, content)
//}
//func (c *Controller) RenderText(content string) (err error) {
// return RenderText(c.Ctx.ResponseWriter, content)
//}
//func (c *Controller) RenderJson(data interface{}) (err error) {
// return RenderJson(c.Ctx.ResponseWriter, data)
//}
//func (c *Controller) RenderJQueryCallback(jsoncallback string, data interface{}) error {
// return RenderJQueryCallback(c.Ctx.ResponseWriter, jsoncallback, data)
//}
//func (c *Controller) RenderXml(data interface{}) error {
// return RenderXml(c.Ctx.ResponseWriter, data)
//}
//func (c *Controller) RenderTemplate(contentType ...string) (err error) {
// if c.TplNames == "" {
// c.TplNames = c.ControllerName + "/" + c.MethodName + "." + c.TplExt
// }
// return RenderTemplate(c.Ctx.ResponseWriter, c.App, c.TplNames, c.Data, contentType...)
//}
//func (c *Controller) RenderData(format string, data []byte) error {
// return RenderData(c.Ctx.ResponseWriter, format, data)
//}
//func (c *Controller) RenderError(err interface{}, code int, fmtAndJsoncallback ...string) error {
// return RenderError(c.Ctx.ResponseWriter, err, code, fmtAndJsoncallback...)
//}
//func (c *Controller) RenderSucceed(data interface{}, fmtAndJsoncallback ...string) error {
// return RenderSucceed(c.Ctx.ResponseWriter, data, fmtAndJsoncallback...)
//}