fix multipart & add three useful function
c.GetString() c. GetInt() c.GetBool()
Showing
2 changed files
with
25 additions
and
1 deletions
| ... | @@ -35,6 +35,7 @@ var ( | ... | @@ -35,6 +35,7 @@ var ( |
| 35 | SessionGCMaxLifetime int64 // session's gc maxlifetime | 35 | SessionGCMaxLifetime int64 // session's gc maxlifetime |
| 36 | SessionSavePath string // session savepath if use mysql/redis/file this set to the connectinfo | 36 | SessionSavePath string // session savepath if use mysql/redis/file this set to the connectinfo |
| 37 | UseFcgi bool | 37 | UseFcgi bool |
| 38 | MaxMemory int64 | ||
| 38 | 39 | ||
| 39 | GlobalSessions *session.Manager //GlobalSessions | 40 | GlobalSessions *session.Manager //GlobalSessions |
| 40 | ) | 41 | ) |
| ... | @@ -62,6 +63,7 @@ func init() { | ... | @@ -62,6 +63,7 @@ func init() { |
| 62 | SessionGCMaxLifetime = 3600 | 63 | SessionGCMaxLifetime = 3600 |
| 63 | SessionSavePath = "" | 64 | SessionSavePath = "" |
| 64 | UseFcgi = false | 65 | UseFcgi = false |
| 66 | MaxMemory = 1 << 26 //64MB | ||
| 65 | } else { | 67 | } else { |
| 66 | HttpAddr = AppConfig.String("httpaddr") | 68 | HttpAddr = AppConfig.String("httpaddr") |
| 67 | if v, err := AppConfig.Int("httpport"); err != nil { | 69 | if v, err := AppConfig.Int("httpport"); err != nil { |
| ... | @@ -69,6 +71,11 @@ func init() { | ... | @@ -69,6 +71,11 @@ func init() { |
| 69 | } else { | 71 | } else { |
| 70 | HttpPort = v | 72 | HttpPort = v |
| 71 | } | 73 | } |
| 74 | if v, err := AppConfig.Int64("maxmemory"); err != nil { | ||
| 75 | MaxMemory = 1 << 26 | ||
| 76 | } else { | ||
| 77 | MaxMemory = v | ||
| 78 | } | ||
| 72 | AppName = AppConfig.String("appname") | 79 | AppName = AppConfig.String("appname") |
| 73 | if runmode := AppConfig.String("runmode"); runmode != "" { | 80 | if runmode := AppConfig.String("runmode"); runmode != "" { |
| 74 | RunMode = runmode | 81 | RunMode = runmode | ... | ... |
| ... | @@ -170,10 +170,27 @@ func (c *Controller) ServeXml() { | ... | @@ -170,10 +170,27 @@ func (c *Controller) ServeXml() { |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | func (c *Controller) Input() url.Values { | 172 | func (c *Controller) Input() url.Values { |
| 173 | c.Ctx.Request.ParseForm() | 173 | ct := c.Ctx.Request.Header.Get("Content-Type") |
| 174 | if ct == "multipart/form-data" { | ||
| 175 | c.Ctx.Request.ParseMultipartForm(MaxMemory) //64MB | ||
| 176 | } else { | ||
| 177 | c.Ctx.Request.ParseForm() | ||
| 178 | } | ||
| 174 | return c.Ctx.Request.Form | 179 | return c.Ctx.Request.Form |
| 175 | } | 180 | } |
| 176 | 181 | ||
| 182 | func (c *Controller) GetString(key string) string { | ||
| 183 | return c.Input().Get(key) | ||
| 184 | } | ||
| 185 | |||
| 186 | func (c *Controller) GetInt(key string) (int64, error) { | ||
| 187 | return strconv.ParseInt(c.Input().Get(key), 10, 64) | ||
| 188 | } | ||
| 189 | |||
| 190 | func (c *Controller) GetBool(key string) (bool, error) { | ||
| 191 | return strconv.ParseBool(c.Input().Get(key)) | ||
| 192 | } | ||
| 193 | |||
| 177 | func (c *Controller) StartSession() (sess session.SessionStore) { | 194 | func (c *Controller) StartSession() (sess session.SessionStore) { |
| 178 | sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request) | 195 | sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request) |
| 179 | return | 196 | return | ... | ... |
-
Please register or sign in to post a comment