933e98e4 by 傅小黑

add api comments in file beego.go

1 parent 3f3bf299
...@@ -125,7 +125,7 @@ func (app *App) UrlFor(endpoint string, values ...string) string { ...@@ -125,7 +125,7 @@ func (app *App) UrlFor(endpoint string, values ...string) string {
125 return app.Handlers.UrlFor(endpoint, values...) 125 return app.Handlers.UrlFor(endpoint, values...)
126 } 126 }
127 127
128 // [Deprecated] 128 // [Deprecated] use InsertFilter.
129 // Filter adds a FilterFunc under pattern condition and named action. 129 // Filter adds a FilterFunc under pattern condition and named action.
130 // The actions contains BeforeRouter,AfterStatic,BeforeExec,AfterExec and FinishRouter. 130 // The actions contains BeforeRouter,AfterStatic,BeforeExec,AfterExec and FinishRouter.
131 func (app *App) Filter(pattern, action string, filter FilterFunc) *App { 131 func (app *App) Filter(pattern, action string, filter FilterFunc) *App {
......
...@@ -10,34 +10,50 @@ import ( ...@@ -10,34 +10,50 @@ import (
10 "github.com/astaxie/beego/session" 10 "github.com/astaxie/beego/session"
11 ) 11 )
12 12
13 // beego web framework version.
13 const VERSION = "1.0.0" 14 const VERSION = "1.0.0"
14 15
16 // Router adds a patterned controller handler to BeeApp.
17 // it's an alias method of App.Router.
15 func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App { 18 func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
16 BeeApp.Router(rootpath, c, mappingMethods...) 19 BeeApp.Router(rootpath, c, mappingMethods...)
17 return BeeApp 20 return BeeApp
18 } 21 }
19 22
23 // RESTRouter adds a restful controller handler to BeeApp.
24 // its' controller implements beego.ControllerInterface and
25 // defines a param "pattern/:objectId" to visit each resource.
20 func RESTRouter(rootpath string, c ControllerInterface) *App { 26 func RESTRouter(rootpath string, c ControllerInterface) *App {
21 Router(rootpath, c) 27 Router(rootpath, c)
22 Router(path.Join(rootpath, ":objectId"), c) 28 Router(path.Join(rootpath, ":objectId"), c)
23 return BeeApp 29 return BeeApp
24 } 30 }
25 31
32 // AutoRouter adds defined controller handler to BeeApp.
33 // it's same to App.AutoRouter.
26 func AutoRouter(c ControllerInterface) *App { 34 func AutoRouter(c ControllerInterface) *App {
27 BeeApp.AutoRouter(c) 35 BeeApp.AutoRouter(c)
28 return BeeApp 36 return BeeApp
29 } 37 }
30 38
39 // ErrorHandler registers http.HandlerFunc to each http err code string.
40 // usage:
41 // beego.ErrorHandler("404",NotFound)
42 // beego.ErrorHandler("500",InternalServerError)
31 func Errorhandler(err string, h http.HandlerFunc) *App { 43 func Errorhandler(err string, h http.HandlerFunc) *App {
32 middleware.Errorhandler(err, h) 44 middleware.Errorhandler(err, h)
33 return BeeApp 45 return BeeApp
34 } 46 }
35 47
48 // SetViewsPath sets view directory to BeeApp.
49 // it's alias of App.SetViewsPath.
36 func SetViewsPath(path string) *App { 50 func SetViewsPath(path string) *App {
37 BeeApp.SetViewsPath(path) 51 BeeApp.SetViewsPath(path)
38 return BeeApp 52 return BeeApp
39 } 53 }
40 54
55 // SetStaticPath sets static directory and url prefix to BeeApp.
56 // it's alias of App.SetStaticPath.
41 func SetStaticPath(url string, path string) *App { 57 func SetStaticPath(url string, path string) *App {
42 if !strings.HasPrefix(url, "/") { 58 if !strings.HasPrefix(url, "/") {
43 url = "/" + url 59 url = "/" + url
...@@ -46,27 +62,33 @@ func SetStaticPath(url string, path string) *App { ...@@ -46,27 +62,33 @@ func SetStaticPath(url string, path string) *App {
46 return BeeApp 62 return BeeApp
47 } 63 }
48 64
65 // DelStaticPath removes the static folder setting in this url pattern in beego application.
66 // it's alias of App.DelStaticPath.
49 func DelStaticPath(url string) *App { 67 func DelStaticPath(url string) *App {
50 delete(StaticDir, url) 68 delete(StaticDir, url)
51 return BeeApp 69 return BeeApp
52 } 70 }
53 71
54 //!!DEPRECATED!! use InsertFilter 72 // [Deprecated] use InsertFilter.
55 //action has four values: 73 // Filter adds a FilterFunc under pattern condition and named action.
56 //BeforRouter 74 // The actions contains BeforeRouter,AfterStatic,BeforeExec,AfterExec and FinishRouter.
57 //AfterStatic 75 // it's alias of App.Filter.
58 //BeforExec
59 //AfterExec
60 func AddFilter(pattern, action string, filter FilterFunc) *App { 76 func AddFilter(pattern, action string, filter FilterFunc) *App {
61 BeeApp.Filter(pattern, action, filter) 77 BeeApp.Filter(pattern, action, filter)
62 return BeeApp 78 return BeeApp
63 } 79 }
64 80
81 // InsertFilter adds a FilterFunc with pattern condition and action constant.
82 // The pos means action constant including
83 // beego.BeforeRouter, beego.AfterStatic, beego.BeforeExec, beego.AfterExec and beego.FinishRouter.
84 // it's alias of App.InsertFilter.
65 func InsertFilter(pattern string, pos int, filter FilterFunc) *App { 85 func InsertFilter(pattern string, pos int, filter FilterFunc) *App {
66 BeeApp.InsertFilter(pattern, pos, filter) 86 BeeApp.InsertFilter(pattern, pos, filter)
67 return BeeApp 87 return BeeApp
68 } 88 }
69 89
90 // Run beego application.
91 // it's alias of App.Run.
70 func Run() { 92 func Run() {
71 // if AppConfigPath not In the conf/app.conf reParse config 93 // if AppConfigPath not In the conf/app.conf reParse config
72 if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { 94 if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!