-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
60 lines (51 loc) · 1.38 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
package webframe
//type CollectionRouter interface {
// Index(b http.ResponseWriter, request *http.Request)
// Show(b http.ResponseWriter, request *http.Request)
//
// New(b http.ResponseWriter, request *http.Request)
// Create(b http.ResponseWriter, request *http.Request)
//
// Edit(b http.ResponseWriter, request *http.Request)
// Update(b http.ResponseWriter, request *http.Request)
// Delete(b http.ResponseWriter, request *http.Request)
//}
// TODO: We need to incldue a way to specify a model, and a way to whitelist
// field interaction from the controller.
type Controller struct {
Framework *Framework
Name string
Views []*View
BeforeAction []func()
AfterAction []func()
}
// TODO: Concept if we go with a gin like solution
//func (c Controller) Root(c framework.Context) {
// p := c.Param("test")
//
// c.HTML(views.Root())
// c.JSON(someJSON)
// c.Render()
//}
//func ServeHTTP() {
//
//}
// TODO: The controller could store these views to establish our cache system
// too which will need to be fairly complex for big applications
func (c Controller) View(name string) *View {
for _, view := range c.Views {
if len(view.Name) == len(name) && view.Name == name {
return view
}
}
return nil
}
func (c Controller) NewView(name string) *View {
if c.View(name) == nil {
c.Views = append(c.Views, &View{
Name: name,
})
return c.Views[len(c.Views)-1]
}
return nil
}