1f67fcb0 by xiemengjun

http support pprof and template add date func like php's date function

http support pprof
PprofOn set to true you can profile the runtime data.
template add date func like php's date function

{{date "Y-m-d H:i:s"}}
1 parent a02a6480
...@@ -332,6 +332,16 @@ beego has many default variables, as follow is a list to show: ...@@ -332,6 +332,16 @@ beego has many default variables, as follow is a list to show:
332 - AppConfig *Config 332 - AppConfig *Config
333 333
334 Appconfig is a result that parse file from conf/app.conf, if this file not exist then the variable is nil. if the file exist, then return the Config as follow. 334 Appconfig is a result that parse file from conf/app.conf, if this file not exist then the variable is nil. if the file exist, then return the Config as follow.
335
336 - PprofOn bool
337
338 default is false. turn on pprof, if set to true. you can visit like this:
339
340 /debug/pprof
341 /debug/pprof/cmdline
342 /debug/pprof/profile
343 /debug/pprof/symbol
344 this serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool. For more information about pprof, see http://golang.org/pkg/net/http/pprof/
335 345
336 ## Config 346 ## Config
337 ============ 347 ============
......
...@@ -18,6 +18,7 @@ func init() { ...@@ -18,6 +18,7 @@ func init() {
18 beegoTplFuncMap = make(template.FuncMap) 18 beegoTplFuncMap = make(template.FuncMap)
19 beegoTplFuncMap["markdown"] = MarkDown 19 beegoTplFuncMap["markdown"] = MarkDown
20 beegoTplFuncMap["dateformat"] = DateFormat 20 beegoTplFuncMap["dateformat"] = DateFormat
21 beegoTplFuncMap["date"] = Date
21 beegoTplFuncMap["compare"] = Compare 22 beegoTplFuncMap["compare"] = Compare
22 } 23 }
23 24
...@@ -35,6 +36,45 @@ func DateFormat(t time.Time, layout string) (datestring string) { ...@@ -35,6 +36,45 @@ func DateFormat(t time.Time, layout string) (datestring string) {
35 return 36 return
36 } 37 }
37 38
39 // Date takes a PHP like date func to Go's time fomate
40 func Date(t time.Time, format string) (datestring string) {
41 patterns := []string{
42 // year
43 "Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
44 "y", "06", //A two digit representation of a year Examples: 99 or 03
45
46 // month
47 "m", "01", // Numeric representation of a month, with leading zeros 01 through 12
48 "n", "1", // Numeric representation of a month, without leading zeros 1 through 12
49 "M", "Jan", // A short textual representation of a month, three letters Jan through Dec
50 "F", "January", // A full textual representation of a month, such as January or March January through December
51
52 // day
53 "d", "02", // Day of the month, 2 digits with leading zeros 01 to 31
54 "j", "2", // Day of the month without leading zeros 1 to 31
55
56 // week
57 "D", "Mon", // A textual representation of a day, three letters Mon through Sun
58 "l", "Monday", // A full textual representation of the day of the week Sunday through Saturday
59
60 // time
61 "g", "3", // 12-hour format of an hour without leading zeros 1 through 12
62 "G", "15", // 24-hour format of an hour without leading zeros 0 through 23
63 "h", "03", // 12-hour format of an hour with leading zeros 01 through 12
64 "H", "15", // 24-hour format of an hour with leading zeros 00 through 23
65
66 "a", "pm", // Lowercase Ante meridiem and Post meridiem am or pm
67 "A", "PM", // Uppercase Ante meridiem and Post meridiem AM or PM
68
69 "i", "04", // Minutes with leading zeros 00 to 59
70 "s", "05", // Seconds, with leading zeros 00 through 59
71 }
72 replacer := strings.NewReplacer(patterns...)
73 format = replacer.Replace(format)
74 datestring = t.Format(format)
75 return
76 }
77
38 // 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. 78 // 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.
39 // Whitespace is trimmed. Used by the template parser as "eq" 79 // Whitespace is trimmed. Used by the template parser as "eq"
40 func Compare(a, b interface{}) (equal bool) { 80 func Compare(a, b interface{}) (equal bool) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!