-
Notifications
You must be signed in to change notification settings - Fork 4
/
controller.go
63 lines (47 loc) · 1.22 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
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package pine
import (
"reflect"
"github.com/xiusin/logger"
"github.com/xiusin/pine/sessions"
)
type Controller struct {
context *Context
}
var _ IController = (*Controller)(nil)
type IController interface {
Ctx() *Context
Input() *input
Render() *Render
Logger() logger.AbstractLogger
Session() sessions.AbstractSession
}
var reflectingNeedIgnoreMethods = map[string]struct{}{}
func init() {
for typo, i := reflect.TypeOf(&Controller{}), 0; i < typo.NumMethod(); i++ {
reflectingNeedIgnoreMethods[typo.Method(i).Name] = struct{}{}
}
}
func (c *Controller) Ctx() *Context {
return c.context
}
func (c *Controller) Render() *Render {
return c.context.Render()
}
func (c *Controller) View(name string) {
c.Render().HTML(name)
}
func (c *Controller) Logger() logger.AbstractLogger {
return c.context.Logger()
}
func (c *Controller) Session() sessions.AbstractSession {
return c.context.Session()
}
func (c *Controller) Input() *input {
return c.Ctx().Input()
}
func (c *Controller) ViewData(key string, val any) {
c.Render().ViewData(key, val)
}