625dec0a by astaxie

finish the doc intro

1 parent 8ef18f5f
Showing 1 changed file with 80 additions and 1 deletions
...@@ -169,7 +169,7 @@ So you can define ChildStruct method to accomplish the interface's method, now l ...@@ -169,7 +169,7 @@ So you can define ChildStruct method to accomplish the interface's method, now l
169 } 169 }
170 170
171 func (this *AddController) Post() { 171 func (this *AddController) Post() {
172 //数据处理 172 //data deal with
173 this.Ct.Request.ParseForm() 173 this.Ct.Request.ParseForm()
174 pkgname := this.Ct.Request.Form.Get("pkgname") 174 pkgname := this.Ct.Request.Form.Get("pkgname")
175 content := this.Ct.Request.Form.Get("content") 175 content := this.Ct.Request.Form.Get("content")
...@@ -261,7 +261,22 @@ beego has three default defined funtion: ...@@ -261,7 +261,22 @@ beego has three default defined funtion:
261 - beegoTplFuncMap["compare"] = Compare 261 - beegoTplFuncMap["compare"] = Compare
262 262
263 Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal.Whitespace is trimmed. Used by the template parser as "eq" 263 Compare is a quick and dirty comparison function. It will convert whatever you give it to strings and see if the two values are equal.Whitespace is trimmed. Used by the template parser as "eq"
264
265 ### JSON/XML output
266 You can use `beego.Controller.ServeJson` or `beego.Controller.ServeXml` for serializing to Json and Xml. I found myself constantly writing code to serialize, set content type, content length, etc. Feel free to use these functions to eliminate redundant code in your app.
267
268 Helper function for serving Json, sets content type to application/json:
269
270 func (this *AddController) Get() {
271 mystruct := { ... }
272 routes.ServeJson(w, &mystruct)
273 }
274 Helper function for serving Xml, sets content type to application/xml:
264 275
276 func (this *AddController) Get() {
277 mystruct := { ... }
278 routes.ServeXml(w, &mystruct)
279 }
265 ## Beego Variables 280 ## Beego Variables
266 ============ 281 ============
267 beego has many default variables, as follow is a list to show: 282 beego has many default variables, as follow is a list to show:
...@@ -317,10 +332,74 @@ beego has many default variables, as follow is a list to show: ...@@ -317,10 +332,74 @@ beego has many default variables, as follow is a list to show:
317 332
318 beego support parse ini file, beego will parse the default file in the path `conf/app.conf` 333 beego support parse ini file, beego will parse the default file in the path `conf/app.conf`
319 334
335 throw this conf file you can set many Beego Variables to change default values.
336
337 app.conf
338
339 appname = beepkg
340 httpaddr = "127.0.0.1"
341 httpport = 9090
342 runmode ="dev"
343 autorender = false
344 autorecover = false
345 viewspath = "myview"
346
347 this variables will replace the default beego variable's values
348
349 you can also set you own variables such as database setting
350
351 mysqluser = "root"
352 mysqlpass = "rootpass"
353 mysqlurls = "127.0.0.1"
354 mysqldb = "beego"
355
356 In you app you can get the config like this:
320 357
358 beego.AppConfig.String("mysqluser")
359 beego.AppConfig.String("mysqlpass")
360 beego.AppConfig.String("mysqlurls")
361 beego.AppConfig.String("mysqldb")
321 362
322 ## Logger 363 ## Logger
323 ============ 364 ============
365 beego has a default log named BeeLogger which output to os.Stdout.
366
367 you can change it output with the standard log.Logger like this:
368
369 fd,err := os.OpenFile("/opt/app/beepkg/beepkg.log", os.O_RDWR|os.O_APPEND, 0644)
370 if err != nil {
371 beego.Critical("openfile beepkg.log:", err)
372 return
373 }
374 lg := log.New(fd, "", log.Ldate|log.Ltime)
375 beego.SetLogger(lg)
376
377
378 ### Supported log levels
379 - Trace - For pervasive information on states of all elementary constructs. Use 'Trace' for in-depth debugging to find problem parts of a function, to check values of temporary variables, etc.
380 - Debug - For detailed system behavior reports and diagnostic messages to help to locate problems during development.
381 - Info - For general information on the application's work. Use 'Info' level in your code so that you could leave it 'enabled' even in production. So it is a 'production log level'.
382 - Warn - For indicating small errors, strange situations, failures that are automatically handled in a safe manner.
383 - Error - For severe failures that affects application's workflow, not fatal, however (without forcing app shutdown).
384 - Critical - For producing final messages before application’s death. Note: critical messages force immediate flush because in critical situation it is important to avoid log message losses if app crashes.
385 - Off - A special log level used to turn off logging
386
387 beego has follow functions:
388
389 - Trace(v ...interface{})
390 - Debug(v ...interface{})
391 - Info(v ...interface{})
392 - Warn(v ...interface{})
393 - Error(v ...interface{})
394 - Critical(v ...interface{})
395
396 you can set log levels like this :
397
398 beego.SetLevel(beego.LevelError)
399
400 after set the log levels, in the logs function which below the setlevels willn't output anything
324 401
402 after set levels to beego.LevelError
325 403
404 Trace, Debug, Info, Warn will not output anything. So you can change it when in dev and prod mode.
326 405
...\ No newline at end of file ...\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!