add api comments in file config.go, controller.go, filter.go and flash.go
Showing
4 changed files
with
62 additions
and
21 deletions
| ... | @@ -14,54 +14,81 @@ import ( | ... | @@ -14,54 +14,81 @@ import ( |
| 14 | ) | 14 | ) |
| 15 | 15 | ||
| 16 | var ( | 16 | var ( |
| 17 | // beego application | ||
| 17 | BeeApp *App | 18 | BeeApp *App |
| 19 | // application configurations | ||
| 18 | AppName string | 20 | AppName string |
| 19 | AppPath string | 21 | AppPath string |
| 20 | AppConfigPath string | 22 | AppConfigPath string |
| 21 | StaticDir map[string]string | 23 | StaticDir map[string]string |
| 24 | // template caching map | ||
| 22 | TemplateCache map[string]*template.Template | 25 | TemplateCache map[string]*template.Template |
| 23 | StaticExtensionsToGzip []string //Files which should also be compressed with gzip (.js, .css, etc) | 26 | // files with should be compressed with gzip (.js,.css,etc) |
| 27 | StaticExtensionsToGzip []string | ||
| 28 | // http server configurations | ||
| 24 | HttpAddr string | 29 | HttpAddr string |
| 25 | HttpPort int | 30 | HttpPort int |
| 26 | HttpTLS bool | 31 | HttpTLS bool |
| 27 | HttpCertFile string | 32 | HttpCertFile string |
| 28 | HttpKeyFile string | 33 | HttpKeyFile string |
| 34 | // flag of auto recover panic | ||
| 29 | RecoverPanic bool | 35 | RecoverPanic bool |
| 36 | // flag of render template automatically | ||
| 30 | AutoRender bool | 37 | AutoRender bool |
| 31 | ViewsPath string | 38 | ViewsPath string |
| 32 | RunMode string //"dev" or "prod" | 39 | // run mode, "dev" or "prod" |
| 40 | RunMode string | ||
| 33 | AppConfig config.ConfigContainer | 41 | AppConfig config.ConfigContainer |
| 34 | //related to session | 42 | // global session mananger |
| 35 | GlobalSessions *session.Manager //GlobalSessions | 43 | GlobalSessions *session.Manager |
| 36 | SessionOn bool // whether auto start session,default is false | 44 | // flag of starting session auto. default is false. |
| 37 | SessionProvider string // default session provider memory mysql redis | 45 | SessionOn bool |
| 38 | SessionName string // sessionName cookie's name | 46 | // default session provider, memory, mysql , redis ,etc. |
| 39 | SessionGCMaxLifetime int64 // session's gc maxlifetime | 47 | SessionProvider string |
| 40 | SessionSavePath string // session savepath if use mysql/redis/file this set to the connectinfo | 48 | // the cookie name when saving session id into cookie. |
| 49 | SessionName string | ||
| 50 | // session gc time for auto cleaning expired session. | ||
| 51 | SessionGCMaxLifetime int64 | ||
| 52 | // if use mysql/redis/file provider, define save path to connection info. | ||
| 53 | SessionSavePath string | ||
| 54 | // session hash generation func. | ||
| 41 | SessionHashFunc string | 55 | SessionHashFunc string |
| 56 | // session hash salt string. | ||
| 42 | SessionHashKey string | 57 | SessionHashKey string |
| 58 | // the life time of session id in cookie. | ||
| 43 | SessionCookieLifeTime int | 59 | SessionCookieLifeTime int |
| 44 | UseFcgi bool | 60 | UseFcgi bool |
| 45 | MaxMemory int64 | 61 | MaxMemory int64 |
| 46 | EnableGzip bool // enable gzip | 62 | // flag of enable gzip |
| 47 | DirectoryIndex bool //enable DirectoryIndex default is false | 63 | EnableGzip bool |
| 48 | EnableHotUpdate bool //enable HotUpdate default is false | 64 | // flag of display directory index. default is false. |
| 49 | HttpServerTimeOut int64 //set httpserver timeout | 65 | DirectoryIndex bool |
| 50 | ErrorsShow bool //set weather show errors | 66 | // flag of hot update checking in app self. default is false. |
| 51 | XSRFKEY string //set XSRF | 67 | EnableHotUpdate bool |
| 68 | HttpServerTimeOut int64 | ||
| 69 | // flag of show errors in page. if true, show error and trace info in page rendered with error template. | ||
| 70 | ErrorsShow bool | ||
| 71 | // xsrf hash salt string. | ||
| 72 | XSRFKEY string | ||
| 73 | // flag of enable xsrf. | ||
| 52 | EnableXSRF bool | 74 | EnableXSRF bool |
| 75 | // the expiry of xsrf value. | ||
| 53 | XSRFExpire int | 76 | XSRFExpire int |
| 54 | CopyRequestBody bool //When in raw application, You want to the reqeustbody | 77 | // flag of copy raw request body in context. |
| 78 | CopyRequestBody bool | ||
| 55 | TemplateLeft string | 79 | TemplateLeft string |
| 56 | TemplateRight string | 80 | TemplateRight string |
| 81 | // beego server name exported in response header. | ||
| 57 | BeegoServerName string | 82 | BeegoServerName string |
| 58 | EnableAdmin bool //enable admin module to log api time | 83 | // flag of enable admin module to log every request info. |
| 59 | AdminHttpAddr string //admin module http addr | 84 | EnableAdmin bool |
| 85 | // http server configurations for admin module. | ||
| 86 | AdminHttpAddr string | ||
| 60 | AdminHttpPort int | 87 | AdminHttpPort int |
| 61 | ) | 88 | ) |
| 62 | 89 | ||
| 63 | func init() { | 90 | func init() { |
| 64 | // create beeapp | 91 | // create beego application |
| 65 | BeeApp = NewApp() | 92 | BeeApp = NewApp() |
| 66 | 93 | ||
| 67 | // initialize default configurations | 94 | // initialize default configurations |
| ... | @@ -100,7 +127,7 @@ func init() { | ... | @@ -100,7 +127,7 @@ func init() { |
| 100 | 127 | ||
| 101 | UseFcgi = false | 128 | UseFcgi = false |
| 102 | 129 | ||
| 103 | MaxMemory = 1 << 26 //64MB | 130 | MaxMemory = 1<<26 //64MB |
| 104 | 131 | ||
| 105 | EnableGzip = false | 132 | EnableGzip = false |
| 106 | 133 | ||
| ... | @@ -135,7 +162,8 @@ func init() { | ... | @@ -135,7 +162,8 @@ func init() { |
| 135 | } | 162 | } |
| 136 | } | 163 | } |
| 137 | 164 | ||
| 138 | //parse config now only support ini, next will support json | 165 | // ParseConfig parsed default config file. |
| 166 | // now only support ini, next will support json. | ||
| 139 | func ParseConfig() (err error) { | 167 | func ParseConfig() (err error) { |
| 140 | AppConfig, err = config.NewConfig("ini", AppConfigPath) | 168 | AppConfig, err = config.NewConfig("ini", AppConfigPath) |
| 141 | if err != nil { | 169 | if err != nil { | ... | ... |
This diff is collapsed.
Click to expand it.
| ... | @@ -5,6 +5,8 @@ import ( | ... | @@ -5,6 +5,8 @@ import ( |
| 5 | "strings" | 5 | "strings" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | // FilterRouter defines filter operation before controller handler execution. | ||
| 9 | // it can match patterned url and do filter function when action arrives. | ||
| 8 | type FilterRouter struct { | 10 | type FilterRouter struct { |
| 9 | pattern string | 11 | pattern string |
| 10 | regex *regexp.Regexp | 12 | regex *regexp.Regexp |
| ... | @@ -14,6 +16,8 @@ type FilterRouter struct { | ... | @@ -14,6 +16,8 @@ type FilterRouter struct { |
| 14 | parseParams map[string]string | 16 | parseParams map[string]string |
| 15 | } | 17 | } |
| 16 | 18 | ||
| 19 | // ValidRouter check current request is valid for this filter. | ||
| 20 | // if matched, returns parsed params in this request by defined filter router pattern. | ||
| 17 | func (mr *FilterRouter) ValidRouter(router string) (bool, map[string]string) { | 21 | func (mr *FilterRouter) ValidRouter(router string) (bool, map[string]string) { |
| 18 | if mr.pattern == "" { | 22 | if mr.pattern == "" { |
| 19 | return true, nil | 23 | return true, nil | ... | ... |
| ... | @@ -6,18 +6,22 @@ import ( | ... | @@ -6,18 +6,22 @@ import ( |
| 6 | "strings" | 6 | "strings" |
| 7 | ) | 7 | ) |
| 8 | 8 | ||
| 9 | // the separation string when encoding flash data. | ||
| 9 | const BEEGO_FLASH_SEP = "#BEEGOFLASH#" | 10 | const BEEGO_FLASH_SEP = "#BEEGOFLASH#" |
| 10 | 11 | ||
| 12 | // FlashData is a tools to maintain data when using across request. | ||
| 11 | type FlashData struct { | 13 | type FlashData struct { |
| 12 | Data map[string]string | 14 | Data map[string]string |
| 13 | } | 15 | } |
| 14 | 16 | ||
| 17 | // NewFlash return a new empty FlashData struct. | ||
| 15 | func NewFlash() *FlashData { | 18 | func NewFlash() *FlashData { |
| 16 | return &FlashData{ | 19 | return &FlashData{ |
| 17 | Data: make(map[string]string), | 20 | Data: make(map[string]string), |
| 18 | } | 21 | } |
| 19 | } | 22 | } |
| 20 | 23 | ||
| 24 | // Notice writes notice message to flash. | ||
| 21 | func (fd *FlashData) Notice(msg string, args ...interface{}) { | 25 | func (fd *FlashData) Notice(msg string, args ...interface{}) { |
| 22 | if len(args) == 0 { | 26 | if len(args) == 0 { |
| 23 | fd.Data["notice"] = msg | 27 | fd.Data["notice"] = msg |
| ... | @@ -26,6 +30,7 @@ func (fd *FlashData) Notice(msg string, args ...interface{}) { | ... | @@ -26,6 +30,7 @@ func (fd *FlashData) Notice(msg string, args ...interface{}) { |
| 26 | } | 30 | } |
| 27 | } | 31 | } |
| 28 | 32 | ||
| 33 | // Warning writes warning message to flash. | ||
| 29 | func (fd *FlashData) Warning(msg string, args ...interface{}) { | 34 | func (fd *FlashData) Warning(msg string, args ...interface{}) { |
| 30 | if len(args) == 0 { | 35 | if len(args) == 0 { |
| 31 | fd.Data["warning"] = msg | 36 | fd.Data["warning"] = msg |
| ... | @@ -34,6 +39,7 @@ func (fd *FlashData) Warning(msg string, args ...interface{}) { | ... | @@ -34,6 +39,7 @@ func (fd *FlashData) Warning(msg string, args ...interface{}) { |
| 34 | } | 39 | } |
| 35 | } | 40 | } |
| 36 | 41 | ||
| 42 | // Error writes error message to flash. | ||
| 37 | func (fd *FlashData) Error(msg string, args ...interface{}) { | 43 | func (fd *FlashData) Error(msg string, args ...interface{}) { |
| 38 | if len(args) == 0 { | 44 | if len(args) == 0 { |
| 39 | fd.Data["error"] = msg | 45 | fd.Data["error"] = msg |
| ... | @@ -42,6 +48,8 @@ func (fd *FlashData) Error(msg string, args ...interface{}) { | ... | @@ -42,6 +48,8 @@ func (fd *FlashData) Error(msg string, args ...interface{}) { |
| 42 | } | 48 | } |
| 43 | } | 49 | } |
| 44 | 50 | ||
| 51 | // Store does the saving operation of flash data. | ||
| 52 | // the data are encoded and saved in cookie. | ||
| 45 | func (fd *FlashData) Store(c *Controller) { | 53 | func (fd *FlashData) Store(c *Controller) { |
| 46 | c.Data["flash"] = fd.Data | 54 | c.Data["flash"] = fd.Data |
| 47 | var flashValue string | 55 | var flashValue string |
| ... | @@ -51,6 +59,7 @@ func (fd *FlashData) Store(c *Controller) { | ... | @@ -51,6 +59,7 @@ func (fd *FlashData) Store(c *Controller) { |
| 51 | c.Ctx.SetCookie("BEEGO_FLASH", url.QueryEscape(flashValue), 0, "/") | 59 | c.Ctx.SetCookie("BEEGO_FLASH", url.QueryEscape(flashValue), 0, "/") |
| 52 | } | 60 | } |
| 53 | 61 | ||
| 62 | // ReadFromRequest parsed flash data from encoded values in cookie. | ||
| 54 | func ReadFromRequest(c *Controller) *FlashData { | 63 | func ReadFromRequest(c *Controller) *FlashData { |
| 55 | flash := &FlashData{ | 64 | flash := &FlashData{ |
| 56 | Data: make(map[string]string), | 65 | Data: make(map[string]string), | ... | ... |
-
Please register or sign in to post a comment