1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 17:10:50 +00:00

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"}}
This commit is contained in:
xiemengjun 2013-01-01 21:42:16 +08:00
parent a02a64806e
commit 1f67fcb0f9
2 changed files with 50 additions and 0 deletions

View File

@ -332,6 +332,16 @@ beego has many default variables, as follow is a list to show:
- AppConfig *Config
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.
- PprofOn bool
default is false. turn on pprof, if set to true. you can visit like this:
/debug/pprof
/debug/pprof/cmdline
/debug/pprof/profile
/debug/pprof/symbol
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/
## Config
============

View File

@ -18,6 +18,7 @@ func init() {
beegoTplFuncMap = make(template.FuncMap)
beegoTplFuncMap["markdown"] = MarkDown
beegoTplFuncMap["dateformat"] = DateFormat
beegoTplFuncMap["date"] = Date
beegoTplFuncMap["compare"] = Compare
}
@ -35,6 +36,45 @@ func DateFormat(t time.Time, layout string) (datestring string) {
return
}
// Date takes a PHP like date func to Go's time fomate
func Date(t time.Time, format string) (datestring string) {
patterns := []string{
// year
"Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
"y", "06", //A two digit representation of a year Examples: 99 or 03
// month
"m", "01", // Numeric representation of a month, with leading zeros 01 through 12
"n", "1", // Numeric representation of a month, without leading zeros 1 through 12
"M", "Jan", // A short textual representation of a month, three letters Jan through Dec
"F", "January", // A full textual representation of a month, such as January or March January through December
// day
"d", "02", // Day of the month, 2 digits with leading zeros 01 to 31
"j", "2", // Day of the month without leading zeros 1 to 31
// week
"D", "Mon", // A textual representation of a day, three letters Mon through Sun
"l", "Monday", // A full textual representation of the day of the week Sunday through Saturday
// time
"g", "3", // 12-hour format of an hour without leading zeros 1 through 12
"G", "15", // 24-hour format of an hour without leading zeros 0 through 23
"h", "03", // 12-hour format of an hour with leading zeros 01 through 12
"H", "15", // 24-hour format of an hour with leading zeros 00 through 23
"a", "pm", // Lowercase Ante meridiem and Post meridiem am or pm
"A", "PM", // Uppercase Ante meridiem and Post meridiem AM or PM
"i", "04", // Minutes with leading zeros 00 to 59
"s", "05", // Seconds, with leading zeros 00 through 59
}
replacer := strings.NewReplacer(patterns...)
format = replacer.Replace(format)
datestring = t.Format(format)
return
}
// 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"
func Compare(a, b interface{}) (equal bool) {