1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
16 City, State, Zip string
29 type Implicit struct {
33 type Application struct {
37 func (c Hotels) Show(id int) Result {
39 hotel := &Hotel{id, "A Hotel", "300 Main St.", "New York", "NY", "10010", "USA", 300}
40 // The line number below must match the one with the code : RenderArgNames: map[int][]string{43: {"title", "hotel"}},
41 return c.Render(title, hotel)
44 func (c Hotels) Book(id int) Result {
45 hotel := &Hotel{id, "A Hotel", "300 Main St.", "New York", "NY", "10010", "USA", 300}
46 return c.RenderJSON(hotel)
49 func (c Hotels) Index() Result {
50 return c.RenderText("Hello, World!")
53 func (c Static) Serve(prefix, path string) Result {
54 var basePath, dirName string
56 if !filepath.IsAbs(dirName) {
60 fname := filepath.Join(basePath, prefix, path)
61 file, err := os.Open(fname)
62 if os.IsNotExist(err) {
64 } else if err != nil {
65 RevelLog.Errorf("Problem opening file (%s): %s ", fname, err)
66 return c.NotFound("This was found but not sure why we couldn't open it.")
68 return c.RenderFile(file, "")
71 // Register controllers is in its own function so the route test can use it as well
72 func registerControllers() {
73 controllers = make(map[string]*ControllerType)
74 RaiseEvent(ROUTE_REFRESH_REQUESTED, nil)
75 RegisterController((*Hotels)(nil),
83 {"id", reflect.TypeOf((*int)(nil))},
85 RenderArgNames: map[int][]string{41: {"title", "hotel"}},
90 {"id", reflect.TypeOf((*int)(nil))},
95 RegisterController((*Static)(nil),
100 {Name: "prefix", Type: reflect.TypeOf((*string)(nil))},
101 {Name: "filepath", Type: reflect.TypeOf((*string)(nil))},
103 RenderArgNames: map[int][]string{},
106 RegisterController((*Implicit)(nil),
111 {Name: "prefix", Type: reflect.TypeOf((*string)(nil))},
112 {Name: "filepath", Type: reflect.TypeOf((*string)(nil))},
114 RenderArgNames: map[int][]string{},
117 RegisterController((*Application)(nil),
122 {Name: "prefix", Type: reflect.TypeOf((*string)(nil))},
123 {Name: "filepath", Type: reflect.TypeOf((*string)(nil))},
125 RenderArgNames: map[int][]string{},
130 {Name: "foo", Type: reflect.TypeOf((*string)(nil))},
131 {Name: "bar", Type: reflect.TypeOf((*string)(nil))},
133 RenderArgNames: map[int][]string{},
137 func startFakeBookingApp() {
138 Init("prod", "github.com/revel/revel/testdata", "")
140 MainTemplateLoader = NewTemplateLoader([]string{ViewsPath, filepath.Join(RevelPath, "templates")})
141 if err := MainTemplateLoader.Refresh(); err != nil {
142 RevelLog.Fatal("Template error","error",err)
145 registerControllers()
147 InitServerEngine(9000, GO_NATIVE_SERVER_ENGINE)
148 RaiseEvent(ENGINE_BEFORE_INITIALIZED, nil)
151 RaiseEvent(ENGINE_STARTED, nil)