From 7b7a95677aecc58d4d52b5dbf3523784ac147258 Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Sun, 22 Jun 2014 10:52:14 +0800 Subject: [PATCH 001/120] Generate default value while run ORM cmd tool --- orm/cmd_utils.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index 63cc5a64..0a18264f 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -144,6 +144,10 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex column += " " + "NOT NULL" } + if fi.initial.String() != "" { + column += " DEFAULT " + fi.initial.String() + } + if fi.unique { column += " " + "UNIQUE" } From 0f170a80da0391a0c8efe10c748c3417233d50a5 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 25 Jun 2014 10:39:37 +0800 Subject: [PATCH 002/120] update the comments fix #658 --- admin.go | 4 ++++ app.go | 4 ++++ beego.go | 4 ++++ cache/cache.go | 4 ++++ cache/cache_test.go | 4 ++++ cache/conv.go | 4 ++++ cache/conv_test.go | 4 ++++ cache/file.go | 4 ++++ cache/memcache/memcache.go | 4 ++++ cache/memory.go | 4 ++++ cache/redis/redis.go | 4 ++++ config.go | 4 ++++ config/config.go | 4 ++++ config/fake.go | 4 ++++ config/ini.go | 4 ++++ config/ini_test.go | 4 ++++ config/json.go | 4 ++++ config/json_test.go | 10 +++++++--- config/xml/xml.go | 4 ++++ config/xml/xml_test.go | 4 ++++ config/yaml/yaml.go | 4 ++++ config/yaml/yaml_test.go | 4 ++++ config_test.go | 4 ++++ context/context.go | 4 ++++ context/input.go | 4 ++++ context/input_test.go | 4 ++++ context/output.go | 4 ++++ controller.go | 4 ++++ docs.go | 10 ++++++++++ example/beeapi/main.go | 4 ++++ filter.go | 4 ++++ filter_test.go | 4 ++++ flash.go | 4 ++++ flash_test.go | 4 ++++ httplib/httplib.go | 4 ++++ httplib/httplib_test.go | 6 +++++- log.go | 4 ++++ logs/conn.go | 4 ++++ logs/conn_test.go | 4 ++++ logs/console.go | 4 ++++ logs/console_test.go | 4 ++++ logs/file.go | 4 ++++ logs/file_test.go | 4 ++++ logs/log.go | 4 ++++ logs/smtp.go | 4 ++++ logs/smtp_test.go | 4 ++++ memzipfile.go | 4 ++++ middleware/error.go | 4 ++++ middleware/exceptions.go | 4 ++++ middleware/i18n.go | 4 ++++ mime.go | 4 ++++ namespace.go | 5 +++++ namespace_test.go | 4 ++++ orm/cmd.go | 6 +++++- orm/cmd_utils.go | 6 +++++- orm/db.go | 6 +++++- orm/db_alias.go | 6 +++++- orm/db_mysql.go | 6 +++++- orm/db_oracle.go | 6 +++++- orm/db_postgres.go | 6 +++++- orm/db_sqlite.go | 6 +++++- orm/db_tables.go | 6 +++++- orm/db_utils.go | 6 +++++- orm/models.go | 6 +++++- orm/models_boot.go | 6 +++++- orm/models_fields.go | 6 +++++- orm/models_info_f.go | 6 +++++- orm/models_info_m.go | 6 +++++- orm/models_test.go | 6 +++++- orm/models_utils.go | 6 +++++- orm/orm.go | 6 +++++- orm/orm_conds.go | 6 +++++- orm/orm_log.go | 6 +++++- orm/orm_object.go | 6 +++++- orm/orm_querym2m.go | 6 +++++- orm/orm_queryset.go | 6 +++++- orm/orm_raw.go | 6 +++++- orm/orm_test.go | 6 +++++- orm/types.go | 6 +++++- orm/utils.go | 6 +++++- parser.go | 5 +++++ plugins/auth/basic.go | 6 +++++- router.go | 4 ++++ router_test.go | 4 ++++ session/couchbase/sess_couchbase.go | 4 ++++ session/memcache/sess_memcache.go | 4 ++++ session/mysql/sess_mysql.go | 4 ++++ session/postgres/sess_postgresql.go | 4 ++++ session/redis/sess_redis.go | 4 ++++ session/sess_cookie.go | 4 ++++ session/sess_cookie_test.go | 4 ++++ session/sess_file.go | 4 ++++ session/sess_mem.go | 4 ++++ session/sess_mem_test.go | 4 ++++ session/sess_test.go | 4 ++++ session/sess_utils.go | 4 ++++ session/session.go | 4 ++++ staticfile.go | 11 +++++++---- swagger/docsSpec.go | 10 ++++++++++ template.go | 4 ++++ template_test.go | 4 ++++ templatefunc.go | 11 ++++++----- templatefunc_test.go | 4 ++++ testing/client.go | 4 ++++ toolbox/debug.go | 4 ++++ toolbox/debug_test.go | 4 ++++ toolbox/healthcheck.go | 4 ++++ toolbox/profile.go | 4 ++++ toolbox/profile_test.go | 4 ++++ toolbox/statistics.go | 4 ++++ toolbox/statistics_test.go | 4 ++++ toolbox/task.go | 4 ++++ toolbox/task_test.go | 4 ++++ tree.go | 10 ++++++++++ tree_test.go | 10 ++++++++++ utils/caller.go | 4 ++++ utils/caller_test.go | 4 ++++ utils/captcha/captcha.go | 4 ++++ utils/captcha/image.go | 4 ++++ utils/captcha/image_test.go | 4 ++++ utils/captcha/siprng.go | 4 ++++ utils/captcha/siprng_test.go | 4 ++++ utils/file.go | 4 ++++ utils/file_test.go | 4 ++++ utils/mail.go | 4 ++++ utils/mail_test.go | 4 ++++ utils/rand.go | 11 +++++++---- utils/safemap.go | 4 ++++ utils/safemap_test.go | 4 ++++ utils/slice.go | 4 ++++ utils/slice_test.go | 4 ++++ validation/util.go | 4 ++++ validation/util_test.go | 4 ++++ validation/validation.go | 4 ++++ validation/validation_test.go | 4 ++++ validation/validators.go | 4 ++++ 136 files changed, 610 insertions(+), 45 deletions(-) diff --git a/admin.go b/admin.go index cfaaef72..0ef4f93f 100644 --- a/admin.go +++ b/admin.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/app.go b/app.go index 26e565c5..d0a47665 100644 --- a/app.go +++ b/app.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/beego.go b/beego.go index d230d998..3f33242f 100644 --- a/beego.go +++ b/beego.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/cache/cache.go b/cache/cache.go index 3273e2f9..c4baeba3 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/cache_test.go b/cache/cache_test.go index 263ad257..4ba1fb8a 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/conv.go b/cache/conv.go index 00cbdd24..202939b3 100644 --- a/cache/conv.go +++ b/cache/conv.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/conv_test.go b/cache/conv_test.go index 82d73af7..f6756fc4 100644 --- a/cache/conv_test.go +++ b/cache/conv_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/file.go b/cache/file.go index 7178aa20..62febac3 100644 --- a/cache/file.go +++ b/cache/file.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 37658ffe..7b473dff 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/memory.go b/cache/memory.go index 2d2f3803..00e055e8 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 451166a3..b532ca85 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package cache diff --git a/config.go b/config.go index 280edc6b..1984e3cd 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/config/config.go b/config/config.go index 7446abb4..c7454fe0 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/fake.go b/config/fake.go index ece4f696..1ddf8298 100644 --- a/config/fake.go +++ b/config/fake.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/ini.go b/config/ini.go index 0593864a..500d07c1 100644 --- a/config/ini.go +++ b/config/ini.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/ini_test.go b/config/ini_test.go index 3e792ded..e5e6b9ab 100644 --- a/config/ini_test.go +++ b/config/ini_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/json.go b/config/json.go index 440d98bf..8cac5e21 100644 --- a/config/json.go +++ b/config/json.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/json_test.go b/config/json_test.go index a2741941..849febd0 100644 --- a/config/json_test.go +++ b/config/json_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config @@ -61,13 +65,13 @@ func TestJsonStartsWithArray(t *testing.T) { t.Fatal(err) } rootArray, err := jsonconf.DIY("rootArray") - if (err != nil) { + if err != nil { t.Error("array does not exist as element") } rootArrayCasted := rootArray.([]interface{}) - if (rootArrayCasted == nil) { + if rootArrayCasted == nil { t.Error("array from root is nil") - }else { + } else { elem := rootArrayCasted[0].(map[string]interface{}) if elem["url"] != "user" || elem["serviceAPI"] != "http://www.test.com/user" { t.Error("array[0] values are not valid") diff --git a/config/xml/xml.go b/config/xml/xml.go index f763d4f0..05171a37 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/xml/xml_test.go b/config/xml/xml_test.go index 767b02ed..ba6ebbd6 100644 --- a/config/xml/xml_test.go +++ b/config/xml/xml_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 04a6def3..8cae5109 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config/yaml/yaml_test.go b/config/yaml/yaml_test.go index fbeaf654..3a8d68dc 100644 --- a/config/yaml/yaml_test.go +++ b/config/yaml/yaml_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package config diff --git a/config_test.go b/config_test.go index 19eaeacf..70bbf0d6 100644 --- a/config_test.go +++ b/config_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/context/context.go b/context/context.go index 87986bec..15a05c90 100644 --- a/context/context.go +++ b/context/context.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package context diff --git a/context/input.go b/context/input.go index 400f8a57..46b31352 100644 --- a/context/input.go +++ b/context/input.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package context diff --git a/context/input_test.go b/context/input_test.go index f53d013d..b6d1f9d5 100644 --- a/context/input_test.go +++ b/context/input_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package context diff --git a/context/output.go b/context/output.go index 8011392f..aa9efb4c 100644 --- a/context/output.go +++ b/context/output.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package context diff --git a/controller.go b/controller.go index d1f19e43..6f7b510c 100644 --- a/controller.go +++ b/controller.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/docs.go b/docs.go index b8e7d193..07b25dd4 100644 --- a/docs.go +++ b/docs.go @@ -1,3 +1,13 @@ +// Beego (http://beego.me/) + +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie + package beego import ( diff --git a/example/beeapi/main.go b/example/beeapi/main.go index bed06196..c1250e03 100644 --- a/example/beeapi/main.go +++ b/example/beeapi/main.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package main diff --git a/filter.go b/filter.go index a7db36a4..4f99c300 100644 --- a/filter.go +++ b/filter.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/filter_test.go b/filter_test.go index e5428b96..e6056599 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/flash.go b/flash.go index a67ee5c8..66cb1f07 100644 --- a/flash.go +++ b/flash.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/flash_test.go b/flash_test.go index f0a17480..b3ecc4c5 100644 --- a/flash_test.go +++ b/flash_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/httplib/httplib.go b/httplib/httplib.go index f7d083f2..53b8e6ca 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package httplib diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 7325862c..64de6596 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -1,7 +1,11 @@ -// Beego (http://beego.me) +// Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package httplib diff --git a/log.go b/log.go index ac72ec34..5465dc1a 100644 --- a/log.go +++ b/log.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/logs/conn.go b/logs/conn.go index 588e73f4..d36fa364 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/conn_test.go b/logs/conn_test.go index e05cbe05..aa50b41d 100644 --- a/logs/conn_test.go +++ b/logs/conn_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/console.go b/logs/console.go index 9316a55e..c5c72faa 100644 --- a/logs/console.go +++ b/logs/console.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/console_test.go b/logs/console_test.go index a8c942c1..30e1e4c6 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/file.go b/logs/file.go index f5cbb9ff..a7f4c724 100644 --- a/logs/file.go +++ b/logs/file.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/file_test.go b/logs/file_test.go index 90349ec6..65d543ba 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/log.go b/logs/log.go index 423f9ec3..b3dedf98 100644 --- a/logs/log.go +++ b/logs/log.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/smtp.go b/logs/smtp.go index 2b9e50a0..d5c7101d 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/logs/smtp_test.go b/logs/smtp_test.go index cb8d3009..96cd3759 100644 --- a/logs/smtp_test.go +++ b/logs/smtp_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package logs diff --git a/memzipfile.go b/memzipfile.go index 92d6003a..a100b59d 100644 --- a/memzipfile.go +++ b/memzipfile.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/middleware/error.go b/middleware/error.go index 3aff9a80..10d4fc53 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package middleware diff --git a/middleware/exceptions.go b/middleware/exceptions.go index 09cb46cb..a6a18ff0 100644 --- a/middleware/exceptions.go +++ b/middleware/exceptions.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package middleware diff --git a/middleware/i18n.go b/middleware/i18n.go index 10ec12bb..87886d4a 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package middleware diff --git a/mime.go b/mime.go index f611a16e..ada6d099 100644 --- a/mime.go +++ b/mime.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/namespace.go b/namespace.go index 512afd69..985ded3b 100644 --- a/namespace.go +++ b/namespace.go @@ -1,8 +1,13 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie + package beego import ( diff --git a/namespace_test.go b/namespace_test.go index 9142d62c..64bd8dec 100644 --- a/namespace_test.go +++ b/namespace_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/orm/cmd.go b/orm/cmd.go index ecfc3bd5..a15727ae 100644 --- a/orm/cmd.go +++ b/orm/cmd.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index 63cc5a64..13e6fe59 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db.go b/orm/db.go index d8301b75..847ab0d5 100644 --- a/orm/db.go +++ b/orm/db.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_alias.go b/orm/db_alias.go index f9d0ab5a..816441a6 100644 --- a/orm/db_alias.go +++ b/orm/db_alias.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_mysql.go b/orm/db_mysql.go index 33a01ba4..e024b2a1 100644 --- a/orm/db_mysql.go +++ b/orm/db_mysql.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_oracle.go b/orm/db_oracle.go index d2253758..5c93e3c8 100644 --- a/orm/db_oracle.go +++ b/orm/db_oracle.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_postgres.go b/orm/db_postgres.go index 463150dc..4609d8ca 100644 --- a/orm/db_postgres.go +++ b/orm/db_postgres.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_sqlite.go b/orm/db_sqlite.go index 94c74a69..de2bf63d 100644 --- a/orm/db_sqlite.go +++ b/orm/db_sqlite.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_tables.go b/orm/db_tables.go index 690b4eaa..21d18876 100644 --- a/orm/db_tables.go +++ b/orm/db_tables.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/db_utils.go b/orm/db_utils.go index 8f963f5e..8d895e43 100644 --- a/orm/db_utils.go +++ b/orm/db_utils.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models.go b/orm/models.go index ff71ee62..2d82a204 100644 --- a/orm/models.go +++ b/orm/models.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_boot.go b/orm/models_boot.go index 0abaf98f..eb3fce66 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_fields.go b/orm/models_fields.go index c1c9b7e2..f328999d 100644 --- a/orm/models_fields.go +++ b/orm/models_fields.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_info_f.go b/orm/models_info_f.go index 8ec2bbeb..622791d9 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_info_m.go b/orm/models_info_m.go index 265c6379..f759fa33 100644 --- a/orm/models_info_m.go +++ b/orm/models_info_m.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_test.go b/orm/models_test.go index 775c2856..2b42fd52 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/models_utils.go b/orm/models_utils.go index c448c55e..bf331fed 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm.go b/orm/orm.go index 5503256e..947a453c 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_conds.go b/orm/orm_conds.go index 4b0cfa65..0110ac18 100644 --- a/orm/orm_conds.go +++ b/orm/orm_conds.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_log.go b/orm/orm_log.go index e132992d..cde61449 100644 --- a/orm/orm_log.go +++ b/orm/orm_log.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_object.go b/orm/orm_object.go index 44d4aebc..82067026 100644 --- a/orm/orm_object.go +++ b/orm/orm_object.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_querym2m.go b/orm/orm_querym2m.go index 370de60d..bcd67660 100644 --- a/orm/orm_querym2m.go +++ b/orm/orm_querym2m.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_queryset.go b/orm/orm_queryset.go index 6d2dd418..c6e8f19d 100644 --- a/orm/orm_queryset.go +++ b/orm/orm_queryset.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_raw.go b/orm/orm_raw.go index ea701cce..373aaf1b 100644 --- a/orm/orm_raw.go +++ b/orm/orm_raw.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/orm_test.go b/orm/orm_test.go index 5859f426..016e103b 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/types.go b/orm/types.go index 0f1b37ba..77585570 100644 --- a/orm/types.go +++ b/orm/types.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/orm/utils.go b/orm/utils.go index e53042d9..d2326fc1 100644 --- a/orm/utils.go +++ b/orm/utils.go @@ -1,8 +1,12 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors slene + +// @authors astaxie, slene package orm diff --git a/parser.go b/parser.go index 5b2cd616..7e8f2046 100644 --- a/parser.go +++ b/parser.go @@ -1,8 +1,13 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie + package beego import ( diff --git a/plugins/auth/basic.go b/plugins/auth/basic.go index a74bcf22..16aea240 100644 --- a/plugins/auth/basic.go +++ b/plugins/auth/basic.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package auth @@ -14,7 +18,7 @@ package auth // return false // } // authPlugin := auth.NewBasicAuthenticator(SecretAuth, "My Realm") -// beego.AddFilter("*","AfterStatic",authPlugin) +// beego.InsertFilter("*", beego.BeforeRouter,authPlugin) import ( "encoding/base64" diff --git a/router.go b/router.go index 0041c273..c6900473 100644 --- a/router.go +++ b/router.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/router_test.go b/router_test.go index b80000f4..e96a1403 100644 --- a/router_test.go +++ b/router_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/session/couchbase/sess_couchbase.go b/session/couchbase/sess_couchbase.go index 9f68b946..b033d67e 100644 --- a/session/couchbase/sess_couchbase.go +++ b/session/couchbase/sess_couchbase.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/memcache/sess_memcache.go b/session/memcache/sess_memcache.go index fa8fa165..1558e239 100644 --- a/session/memcache/sess_memcache.go +++ b/session/memcache/sess_memcache.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/mysql/sess_mysql.go b/session/mysql/sess_mysql.go index 530ca158..dc0d1506 100644 --- a/session/mysql/sess_mysql.go +++ b/session/mysql/sess_mysql.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/postgres/sess_postgresql.go b/session/postgres/sess_postgresql.go index 7f905997..4e3aca75 100644 --- a/session/postgres/sess_postgresql.go +++ b/session/postgres/sess_postgresql.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index 3ad19792..0d7032f1 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_cookie.go b/session/sess_cookie.go index 1a06add6..5a75e402 100644 --- a/session/sess_cookie.go +++ b/session/sess_cookie.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_cookie_test.go b/session/sess_cookie_test.go index 9ab321f5..475b836b 100644 --- a/session/sess_cookie_test.go +++ b/session/sess_cookie_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_file.go b/session/sess_file.go index 74b71223..38bfa95b 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_mem.go b/session/sess_mem.go index e440b2f5..676d6058 100644 --- a/session/sess_mem.go +++ b/session/sess_mem.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_mem_test.go b/session/sess_mem_test.go index 5e54c634..79684953 100644 --- a/session/sess_mem_test.go +++ b/session/sess_mem_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_test.go b/session/sess_test.go index 1db55a64..535f0c4c 100644 --- a/session/sess_test.go +++ b/session/sess_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/sess_utils.go b/session/sess_utils.go index b9a965c3..cdf0e99b 100644 --- a/session/sess_utils.go +++ b/session/sess_utils.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/session/session.go b/session/session.go index eb9162b8..c4b281b7 100644 --- a/session/session.go +++ b/session/session.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package session diff --git a/staticfile.go b/staticfile.go index 09f3018f..d74aa223 100644 --- a/staticfile.go +++ b/staticfile.go @@ -1,9 +1,12 @@ // Beego (http://beego.me/) -// @description beego is an open-source, high-performance web framework for the Go programming language. -// @link http://github.com/astaxie/beego for the canonical source repository -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors astaxie +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie package beego import ( diff --git a/swagger/docsSpec.go b/swagger/docsSpec.go index 94ff75ef..23149a20 100644 --- a/swagger/docsSpec.go +++ b/swagger/docsSpec.go @@ -1,3 +1,13 @@ +// Beego (http://beego.me/) + +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie + package swagger const SwaggerVersion = "1.2" diff --git a/template.go b/template.go index 9411930c..ad1902d2 100644 --- a/template.go +++ b/template.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/template_test.go b/template_test.go index 15014980..fc2a90a0 100644 --- a/template_test.go +++ b/template_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/templatefunc.go b/templatefunc.go index ef7658d6..84624d2e 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego @@ -37,23 +41,20 @@ func Substr(s string, start, length int) string { func Html2str(html string) string { src := string(html) - //将HTML标签全转换成小写 re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") src = re.ReplaceAllStringFunc(src, strings.ToLower) - //去除STYLE + //remove STYLE re, _ = regexp.Compile("\\") src = re.ReplaceAllString(src, "") - //去除SCRIPT + //remove SCRIPT re, _ = regexp.Compile("\\") src = re.ReplaceAllString(src, "") - //去除所有尖括号内的HTML代码,并换成换行符 re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") src = re.ReplaceAllString(src, "\n") - //去除连续的换行符 re, _ = regexp.Compile("\\s{2,}") src = re.ReplaceAllString(src, "\n") diff --git a/templatefunc_test.go b/templatefunc_test.go index 8a450408..c3879fbb 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package beego diff --git a/testing/client.go b/testing/client.go index a4408681..a185da55 100644 --- a/testing/client.go +++ b/testing/client.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package testing diff --git a/toolbox/debug.go b/toolbox/debug.go index dd775e69..614a673d 100644 --- a/toolbox/debug.go +++ b/toolbox/debug.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/debug_test.go b/toolbox/debug_test.go index 4ef89983..290bed7c 100644 --- a/toolbox/debug_test.go +++ b/toolbox/debug_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/healthcheck.go b/toolbox/healthcheck.go index 0f4c0e29..4332586f 100644 --- a/toolbox/healthcheck.go +++ b/toolbox/healthcheck.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/profile.go b/toolbox/profile.go index 3200d547..a3588ac3 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/profile_test.go b/toolbox/profile_test.go index 661d6ea1..1a3345e8 100644 --- a/toolbox/profile_test.go +++ b/toolbox/profile_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/statistics.go b/toolbox/statistics.go index 8904dc60..74632ee3 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/statistics_test.go b/toolbox/statistics_test.go index ec7ceab5..1fb99b76 100644 --- a/toolbox/statistics_test.go +++ b/toolbox/statistics_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/task.go b/toolbox/task.go index dadc8913..81fdf110 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/toolbox/task_test.go b/toolbox/task_test.go index 2bbd4ac7..0a9f50ad 100644 --- a/toolbox/task_test.go +++ b/toolbox/task_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package toolbox diff --git a/tree.go b/tree.go index 93d4ab02..9d464225 100644 --- a/tree.go +++ b/tree.go @@ -1,3 +1,13 @@ +// Beego (http://beego.me/) + +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie + package beego import ( diff --git a/tree_test.go b/tree_test.go index 57f0a9fd..69da718a 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1,3 +1,13 @@ +// Beego (http://beego.me/) + +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie + package beego import "testing" diff --git a/utils/caller.go b/utils/caller.go index 52cd5fe4..3ba9e94f 100644 --- a/utils/caller.go +++ b/utils/caller.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/caller_test.go b/utils/caller_test.go index c7068f3c..13b289e0 100644 --- a/utils/caller_test.go +++ b/utils/caller_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 133a2fe2..80c7e77d 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie // an example for use captcha diff --git a/utils/captcha/image.go b/utils/captcha/image.go index 93eb3383..6abfc0a4 100644 --- a/utils/captcha/image.go +++ b/utils/captcha/image.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package captcha diff --git a/utils/captcha/image_test.go b/utils/captcha/image_test.go index 14a18fbc..09c119c5 100644 --- a/utils/captcha/image_test.go +++ b/utils/captcha/image_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package captcha diff --git a/utils/captcha/siprng.go b/utils/captcha/siprng.go index 26651b9b..4afca3bf 100644 --- a/utils/captcha/siprng.go +++ b/utils/captcha/siprng.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package captcha diff --git a/utils/captcha/siprng_test.go b/utils/captcha/siprng_test.go index 8f3444b4..54b5d5be 100644 --- a/utils/captcha/siprng_test.go +++ b/utils/captcha/siprng_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package captcha diff --git a/utils/file.go b/utils/file.go index 5246d88c..aead5e7b 100644 --- a/utils/file.go +++ b/utils/file.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/file_test.go b/utils/file_test.go index 8dfd1ff6..5c72b040 100644 --- a/utils/file_test.go +++ b/utils/file_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/mail.go b/utils/mail.go index 8eb97b1a..d8f79f26 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/mail_test.go b/utils/mail_test.go index 109bf7ba..84660a8e 100644 --- a/utils/mail_test.go +++ b/utils/mail_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/rand.go b/utils/rand.go index 363f41b7..d521dfab 100644 --- a/utils/rand.go +++ b/utils/rand.go @@ -1,9 +1,12 @@ // Beego (http://beego.me/) -// @description beego is an open-source, high-performance web framework for the Go programming language. -// @link http://github.com/astaxie/beego for the canonical source repository -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors astaxie +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie package utils import ( diff --git a/utils/safemap.go b/utils/safemap.go index 35bf695b..2df14a53 100644 --- a/utils/safemap.go +++ b/utils/safemap.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/safemap_test.go b/utils/safemap_test.go index e1148a1c..6c2da5bd 100644 --- a/utils/safemap_test.go +++ b/utils/safemap_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/slice.go b/utils/slice.go index fee1b741..786f47a9 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/utils/slice_test.go b/utils/slice_test.go index fb2266a0..fb9c1d1d 100644 --- a/utils/slice_test.go +++ b/utils/slice_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package utils diff --git a/validation/util.go b/validation/util.go index 3ac56f81..e8ca8a1c 100644 --- a/validation/util.go +++ b/validation/util.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package validation diff --git a/validation/util_test.go b/validation/util_test.go index 8345daa6..bcd0c0e5 100644 --- a/validation/util_test.go +++ b/validation/util_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package validation diff --git a/validation/validation.go b/validation/validation.go index 7087ccff..477676a7 100644 --- a/validation/validation.go +++ b/validation/validation.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package validation diff --git a/validation/validation_test.go b/validation/validation_test.go index 47de304a..d43a5938 100644 --- a/validation/validation_test.go +++ b/validation/validation_test.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package validation diff --git a/validation/validators.go b/validation/validators.go index d59b42b0..5cab1c0f 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) + // @description beego is an open-source, high-performance web framework for the Go programming language. + // @link http://github.com/astaxie/beego for the canonical source repository + // @license http://github.com/astaxie/beego/blob/master/LICENSE + // @authors astaxie package validation From ac96c2b15ea1ccb1ff656bde4d9866654474098e Mon Sep 17 00:00:00 2001 From: ljyf5593 Date: Fri, 27 Jun 2014 11:06:29 +0800 Subject: [PATCH 003/120] beego: fix #657 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 路由地址不区分大小写问题 --- router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.go b/router.go index 0041c273..3fce6745 100644 --- a/router.go +++ b/router.go @@ -599,7 +599,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) if !findrouter { if t, ok := p.routers[r.Method]; ok { - runObject, p := t.Match(r.URL.Path) + runObject, p := t.Match(strings.ToLower(r.URL.Path)) if r, ok := runObject.(*controllerInfo); ok { routerInfo = r findrouter = true From 62e9c890103676d4f9e107709de113a6094fde3b Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 27 Jun 2014 17:53:53 +0800 Subject: [PATCH 004/120] middleware: support i18n --- middleware/i18n.go | 122 ++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 78 deletions(-) diff --git a/middleware/i18n.go b/middleware/i18n.go index 87886d4a..5c44dc4a 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -10,85 +10,51 @@ package middleware -//import ( -// "github.com/astaxie/beego/config" -// "os" -// "path" -//) +import ( + "encoding/json" + "io/ioutil" + "os" +) -//type Translation struct { -// filetype string -// CurrentLocal string -// Locales map[string]map[string]string -//} +type Translation struct { + filepath string + CurrentLocal string + Locales map[string]map[string]string +} -//func NewLocale(filetype string) *Translation { -// return &Translation{ -// filetype: filetype, -// CurrentLocal: "zh", -// Locales: make(map[string]map[string]string), -// } -//} +func NewLocale(filepath string, defaultlocal string) *Translation { + i18n := make(map[string]map[string]string) + file, err := os.Open(filepath) + if err != nil { + panic("open " + filepath + " err :" + err.Error()) + } + data, err := ioutil.ReadAll(file) + if err != nil { + panic("read " + filepath + " err :" + err.Error()) + } + err = json.Unmarshal(data, &i18n) + if err != nil { + panic("json.Unmarshal " + filepath + " err :" + err.Error()) + } + return &Translation{ + filepath: filepath, + CurrentLocal: defaultlocal, + Locales: i18n, + } +} -//func (t *Translation) loadTranslations(dirPath string) error { -// dir, err := os.Open(dirPath) -// if err != nil { -// return err -// } -// defer dir.Close() +func (t *Translation) SetLocale(local string) { + t.CurrentLocal = local +} -// names, err := dir.Readdirnames(-1) -// if err != nil { -// return err -// } - -// for _, name := range names { -// fullPath := path.Join(dirPath, name) - -// fi, err := os.Stat(fullPath) -// if err != nil { -// return err -// } - -// if fi.IsDir() { -// continue -// } else { -// if err := t.loadTranslation(fullPath, name); err != nil { -// return err -// } -// } -// } - -// return nil -//} - -//func (t *Translation) loadTranslation(fullPath, locale string) error { - -// sourceKey2Trans, ok := t.Locales[locale] -// if !ok { -// sourceKey2Trans = make(map[string]string) - -// t.Locales[locale] = sourceKey2Trans -// } - -// for _, m := range trf.Messages { -// if m.Translation != "" { -// sourceKey2Trans[sourceKey(m.Source, m.Context)] = m.Translation -// } -// } - -// return nil -//} - -//func (t *Translation) SetLocale(local string) { -// t.CurrentLocal = local -//} - -//func (t *Translation) Translate(key string) string { -// if ct, ok := t.Locales[t.CurrentLocal]; ok { -// if v, o := ct[key]; o { -// return v -// } -// } -// return key -//} +func (t *Translation) Translate(key string, local string) string { + if local == "" { + local = t.CurrentLocal + } + if ct, ok := t.Locales[key]; ok { + if v, o := ct[local]; o { + return v + } + } + return key +} From 3fe9e6a28afda1cfc4d24fc49df4308f8988bfa1 Mon Sep 17 00:00:00 2001 From: Vangelis Tsoumenis Date: Sun, 29 Jun 2014 19:19:32 +0200 Subject: [PATCH 005/120] extract func `parseFormTag` from templatefunc.RenderForm Extracted a func `parseFormTag` that takes a reflect.StructField and returns the different positional parts of the `form` structTag with default values as documented in http://beego.me/docs/mvc/view/view.md#renderform This makes RenderForm shorter and makes it possible to test the parsing separately. --- templatefunc.go | 72 ++++++++++++++++++++++++++------------------ templatefunc_test.go | 39 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 30 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index 84624d2e..3d42321b 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -368,37 +368,11 @@ func RenderForm(obj interface{}) template.HTML { } fieldT := objT.Field(i) - tags := strings.Split(fieldT.Tag.Get("form"), ",") - label := fieldT.Name + ": " - name := fieldT.Name - fType := "text" - switch len(tags) { - case 1: - if tags[0] == "-" { - continue - } - if len(tags[0]) > 0 { - name = tags[0] - } - case 2: - if len(tags[0]) > 0 { - name = tags[0] - } - if len(tags[1]) > 0 { - fType = tags[1] - } - case 3: - if len(tags[0]) > 0 { - name = tags[0] - } - if len(tags[1]) > 0 { - fType = tags[1] - } - if len(tags[2]) > 0 { - label = tags[2] - } - } + label, name, fType, ignored := parseFormTag(fieldT) + if ignored { + continue + } raw = append(raw, fmt.Sprintf(`%v`, label, name, fType, fieldV.Interface())) @@ -406,6 +380,44 @@ func RenderForm(obj interface{}) template.HTML { return template.HTML(strings.Join(raw, "
")) } +// parseFormTag takes the stuct-tag of a StructField and parses the `form` value. +// returned are the form label, name-property, type and wether the field should be ignored. +func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { + tags := strings.Split(fieldT.Tag.Get("form"), ",") + label = fieldT.Name + ": " + name = fieldT.Name + fType = "text" + ignored = false; + + switch len(tags) { + case 1: + if tags[0] == "-" { + ignored = true + } + if len(tags[0]) > 0 { + name = tags[0] + } + case 2: + if len(tags[0]) > 0 { + name = tags[0] + } + if len(tags[1]) > 0 { + fType = tags[1] + } + case 3: + if len(tags[0]) > 0 { + name = tags[0] + } + if len(tags[1]) > 0 { + fType = tags[1] + } + if len(tags[2]) > 0 { + label = tags[2] + } + } + return +} + func isStructPtr(t reflect.Type) bool { return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct } diff --git a/templatefunc_test.go b/templatefunc_test.go index c3879fbb..a19d9bc5 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -15,6 +15,7 @@ import ( "net/url" "testing" "time" + "reflect" ) func TestSubstr(t *testing.T) { @@ -164,3 +165,41 @@ func TestRenderForm(t *testing.T) { t.Errorf("output should equal `%v` but got `%v`", result, output) } } + +func TestParseFormTag(t *testing.T) { + // create struct to contain field with different types of struct-tag `form` + type user struct { + All int `form:"name,text,年龄:"` + NoName int `form:",hidden,年龄:"` + OnlyLabel int `form:",,年龄:"` + OnlyName int `form:"name"` + Ignored int `form:"-"` + } + + objT := reflect.TypeOf(&user{}).Elem() + + label, name, fType, ignored := parseFormTag(objT.Field(0)) + if !(name == "name" && label == "年龄:" && fType == "text" && ignored == false) { + t.Errorf("Form Tag with name, label and type was not correctly parsed.") + } + + label, name, fType, ignored = parseFormTag(objT.Field(1)) + if !(name == "NoName" && label == "年龄:" && fType == "hidden" && ignored == false) { + t.Errorf("Form Tag with label and type but without name was not correctly parsed.") + } + + label, name, fType, ignored = parseFormTag(objT.Field(2)) + if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && ignored == false) { + t.Errorf("Form Tag containing only label was not correctly parsed.") + } + + label, name, fType, ignored = parseFormTag(objT.Field(3)) + if !(name == "name" && label == "OnlyName: " && fType == "text" && ignored == false) { + t.Errorf("Form Tag containing only name was not correctly parsed.") + } + + label, name, fType, ignored = parseFormTag(objT.Field(4)) + if (ignored == false) { + t.Errorf("Form Tag that should be ignored was not correctly parsed.") + } +} From a991b9dcdea080ff3bd6586b44e775e7759e7ac5 Mon Sep 17 00:00:00 2001 From: Vangelis Tsoumenis Date: Sun, 29 Jun 2014 19:29:43 +0200 Subject: [PATCH 006/120] Removes unused FormType map from templatefunc --- templatefunc.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index 3d42321b..f51eaac4 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -327,13 +327,6 @@ func ParseForm(form url.Values, obj interface{}) error { return nil } -// form types for RenderForm function -var FormType = map[string]bool{ - "text": true, - "textarea": true, - "hidden": true, - "password": true, -} var unKind = map[reflect.Kind]bool{ reflect.Uintptr: true, From 4994d36b663951d93d90b865cb18876bb0f20e42 Mon Sep 17 00:00:00 2001 From: Vangelis Tsoumenis Date: Sun, 29 Jun 2014 20:30:11 +0200 Subject: [PATCH 007/120] templateform.RenderForm now renders textarea When RenderForm encounters a field with the structTag `form` value type `textarea` it renders an actual `) if output != result { t.Errorf("output should equal `%v` but got `%v`", result, output) } } +func TestRenderFormField(t *testing.T) { + html := renderFormField("Label: ", "Name", "text", "Value") + if html != `Label: ` { + t.Errorf("Wrong html output for input[type=text]: %v ", html) + } + + html = renderFormField("Label: ", "Name", "textarea", "Value") + if html != `Label: ` { + t.Errorf("Wrong html output for textarea: %v ", html) + } +} + func TestParseFormTag(t *testing.T) { // create struct to contain field with different types of struct-tag `form` type user struct { From 4dde2c59fff5b60c5f40b0e4805b7b9d51b01a2f Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 30 Jun 2014 15:57:36 +0800 Subject: [PATCH 008/120] fix the parser.go lastupdate --- parser.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/parser.go b/parser.go index 7e8f2046..f8818295 100644 --- a/parser.go +++ b/parser.go @@ -165,12 +165,12 @@ func compareFile(pkgRealpath string) bool { return true } json.Unmarshal(content, &pkgLastupdate) - ft, err := os.Lstat(pkgRealpath) + lastupdate, err := getpathTime(pkgRealpath) if err != nil { return true } if v, ok := pkgLastupdate[pkgRealpath]; ok { - if ft.ModTime().UnixNano() <= v { + if lastupdate <= v { return false } } @@ -179,14 +179,27 @@ func compareFile(pkgRealpath string) bool { } func savetoFile(pkgRealpath string) { - ft, err := os.Lstat(pkgRealpath) + lastupdate, err := getpathTime(pkgRealpath) if err != nil { return } - pkgLastupdate[pkgRealpath] = ft.ModTime().UnixNano() + pkgLastupdate[pkgRealpath] = lastupdate d, err := json.Marshal(pkgLastupdate) if err != nil { return } ioutil.WriteFile(path.Join(AppPath, lastupdateFilename), d, os.ModePerm) } + +func getpathTime(pkgRealpath string) (lastupdate int64, err error) { + fl, err := ioutil.ReadDir(pkgRealpath) + if err != nil { + return lastupdate, err + } + for _, f := range fl { + if lastupdate < f.ModTime().UnixNano() { + lastupdate = f.ModTime().UnixNano() + } + } + return lastupdate, nil +} From 34572193c6ebb493815776c14fa82340e54648f4 Mon Sep 17 00:00:00 2001 From: Vangelis Tsoumenis Date: Mon, 30 Jun 2014 10:38:32 +0200 Subject: [PATCH 009/120] Adds html5 input types to valid intput types of RenderForm. --- templatefunc.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index ea98470a..274e3af9 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -371,6 +371,7 @@ func RenderForm(obj interface{}) template.HTML { return template.HTML(strings.Join(raw, "
")) } +// renderFormField returns a string containing HTML of a single form field. func renderFormField(label, name, fType string, value interface{}) string { if isValidForInput(fType) { return fmt.Sprintf(`%v`, label, name, fType, value) @@ -379,8 +380,9 @@ func renderFormField(label, name, fType string, value interface{}) string { return fmt.Sprintf(`%v<%v name="%v">%v`, label, fType, name, value, fType) } +// isValidForInput checks if fType is a valid value for the `type` property of an HTML input element. func isValidForInput(fType string) bool { - validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button") + validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button search email url tel number range date month week time datetime datetime-local color") for _, validType := range validInputTypes { if fType == validType { return true @@ -389,7 +391,6 @@ func isValidForInput(fType string) bool { return false } - // parseFormTag takes the stuct-tag of a StructField and parses the `form` value. // returned are the form label, name-property, type and wether the field should be ignored. func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { From 53353fce56fe78b60c536e91df48808a9f8d0a73 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 30 Jun 2014 23:49:11 +0800 Subject: [PATCH 010/120] beego:fix the :id & * mixed router --- tree.go | 4 ++++ tree_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tree.go b/tree.go index 9d464225..f2bc6aa9 100644 --- a/tree.go +++ b/tree.go @@ -159,6 +159,10 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, iswild = true regexpStr = seg } + if seg == "*" && len(wildcards) > 0 && reg == "" { + iswild = true + regexpStr = "(.+)" + } if iswild { if t.wildcard == nil { t.wildcard = NewTree() diff --git a/tree_test.go b/tree_test.go index 69da718a..0a30f677 100644 --- a/tree_test.go +++ b/tree_test.go @@ -32,6 +32,9 @@ func init() { routers = append(routers, testinfo{"/aa/*/bb", "/aa/2009/bb", map[string]string{":splat": "2009"}}) routers = append(routers, testinfo{"/cc/*/dd", "/cc/2009/11/dd", map[string]string{":splat": "2009/11"}}) routers = append(routers, testinfo{"/ee/:year/*/ff", "/ee/2009/11/ff", map[string]string{":year": "2009", ":splat": "11"}}) + routers = append(routers, testinfo{"/thumbnail/:size/uploads/*", + "/thumbnail/100x100/uploads/items/2014/04/20/dPRCdChkUd651t1Hvs18.jpg", + map[string]string{":size": "100x100", ":splat": "items/2014/04/20/dPRCdChkUd651t1Hvs18.jpg"}}) routers = append(routers, testinfo{"/*.*", "/nice/api.json", map[string]string{":path": "nice/api", ":ext": "json"}}) routers = append(routers, testinfo{"/:name/*.*", "/nice/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) routers = append(routers, testinfo{"/:name/test/*.*", "/nice/test/api.json", map[string]string{":name": "nice", ":path": "api", ":ext": "json"}}) From 36ba1e49b128c7ebda7ff47153d7c7d0a4070878 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 1 Jul 2014 00:06:35 +0800 Subject: [PATCH 011/120] beego:change to 1.3.2 --- beego.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beego.go b/beego.go index 3f33242f..e6484802 100644 --- a/beego.go +++ b/beego.go @@ -23,7 +23,7 @@ import ( ) // beego web framework version. -const VERSION = "1.3.1" +const VERSION = "1.3.2" type hookfunc func() error //hook function to run var hooks []hookfunc //hook function slice to store the hookfunc From 8946f816f9f66ff99ddd40a6a7ca6dc23bd904be Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 1 Jul 2014 00:30:05 +0800 Subject: [PATCH 012/120] orm:change the models_test default value --- orm/models_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orm/models_test.go b/orm/models_test.go index 2b42fd52..bd0f0ebb 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -205,7 +205,7 @@ type User struct { Password string `orm:"size(100)"` Status int16 `orm:"column(Status)"` IsStaff bool - IsActive bool `orm:"default(1)"` + IsActive bool `orm:"default(TRUE)"` Created time.Time `orm:"auto_now_add;type(date)"` Updated time.Time `orm:"auto_now"` Profile *Profile `orm:"null;rel(one);on_delete(set_null)"` From 17a9c3c3a9ea5246173d7f8a7415cc268404ba0a Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 1 Jul 2014 09:30:08 +0800 Subject: [PATCH 013/120] =?UTF-8?q?ORM=EF=BC=9Arevert=20default=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orm/cmd_utils.go | 6 +++--- orm/models_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index 8e1d3fdb..ffb354e0 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -148,9 +148,9 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex column += " " + "NOT NULL" } - if fi.initial.String() != "" { - column += " DEFAULT " + fi.initial.String() - } + //if fi.initial.String() != "" { + // column += " DEFAULT " + fi.initial.String() + //} if fi.unique { column += " " + "UNIQUE" diff --git a/orm/models_test.go b/orm/models_test.go index bd0f0ebb..2b42fd52 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -205,7 +205,7 @@ type User struct { Password string `orm:"size(100)"` Status int16 `orm:"column(Status)"` IsStaff bool - IsActive bool `orm:"default(TRUE)"` + IsActive bool `orm:"default(1)"` Created time.Time `orm:"auto_now_add;type(date)"` Updated time.Time `orm:"auto_now"` Profile *Profile `orm:"null;rel(one);on_delete(set_null)"` From 14dee37a2159ee9db1770e79ab23651c59797ebc Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 1 Jul 2014 16:55:23 +0800 Subject: [PATCH 014/120] beego: autorouter params --- router.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/router.go b/router.go index 0fc8a387..52e641c0 100644 --- a/router.go +++ b/router.go @@ -346,19 +346,23 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) reflectVal := reflect.ValueOf(c) rt := reflectVal.Type() ct := reflect.Indirect(reflectVal).Type() - controllerName := strings.ToLower(strings.TrimSuffix(ct.Name(), "Controller")) + controllerName := strings.TrimSuffix(ct.Name(), "Controller") for i := 0; i < rt.NumMethod(); i++ { if !utils.InSlice(rt.Method(i).Name, exceptMethod) { route := &controllerInfo{} route.routerType = routerTypeBeego route.methods = map[string]string{"*": rt.Method(i).Name} route.controllerType = ct - pattern := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name), "*") - patternfix := path.Join(prefix, controllerName, strings.ToLower(rt.Method(i).Name)) + pattern := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name), "*") + patternInit := path.Join(prefix, controllerName, rt.Method(i).Name, "*") + patternfix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name)) + patternfixInit := path.Join(prefix, controllerName, rt.Method(i).Name) route.pattern = pattern for _, m := range HTTPMETHOD { p.addToRouter(m, pattern, route) + p.addToRouter(m, patternInit, route) p.addToRouter(m, patternfix, route) + p.addToRouter(m, patternfixInit, route) } } } @@ -603,7 +607,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) if !findrouter { if t, ok := p.routers[r.Method]; ok { - runObject, p := t.Match(strings.ToLower(r.URL.Path)) + runObject, p := t.Match(r.URL.Path) if r, ok := runObject.(*controllerInfo); ok { routerInfo = r findrouter = true From fefd8ddb5b8c531515bf44c5550cda5f7a2ec651 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 3 Jul 2014 23:40:21 +0800 Subject: [PATCH 015/120] beego: update licence& fix #669 --- .go_style | 16 ++ admin.go | 9 +- app.go | 9 +- beego.go | 9 +- cache/cache.go | 9 +- cache/cache_test.go | 9 +- cache/conv.go | 9 +- cache/conv_test.go | 9 +- cache/file.go | 9 +- cache/memcache/memcache.go | 9 +- cache/memory.go | 9 +- cache/redis/redis.go | 9 +- config.go | 9 +- config/config.go | 9 +- config/fake.go | 9 +- config/ini.go | 9 +- config/ini_test.go | 9 +- config/json.go | 9 +- config/json_test.go | 9 +- config/xml/xml.go | 9 +- config/xml/xml_test.go | 9 +- config/yaml/yaml.go | 9 +- config/yaml/yaml_test.go | 9 +- config_test.go | 9 +- context/context.go | 9 +- context/input.go | 9 +- context/input_test.go | 9 +- context/output.go | 9 +- controller.go | 9 +- docs.go | 9 +- filter.go | 9 +- filter_test.go | 9 +- flash.go | 9 +- flash_test.go | 9 +- forms/elements/button.go | 15 ++ forms/elements/captcha.go | 1 + forms/elements/checkbox.go | 1 + forms/elements/csrf.go | 1 + forms/elements/date.go | 1 + forms/elements/element.go | 232 ++++++++++++++++++++++++++++ forms/elements/email.go | 1 + forms/elements/file.go | 1 + forms/elements/hidden.go | 1 + forms/elements/image.go | 1 + forms/elements/multicheckbox.go | 1 + forms/elements/number.go | 1 + forms/elements/password.go | 1 + forms/elements/radio.go | 1 + forms/elements/range.go | 1 + forms/elements/select.go | 1 + forms/elements/submit.go | 15 ++ forms/elements/text.go | 15 ++ forms/elements/textarea.go | 15 ++ forms/elements/time.go | 1 + forms/elements/url.go | 1 + forms/form.go | 57 +++++++ forms/form_test.go | 21 +++ httplib/httplib.go | 9 +- httplib/httplib_test.go | 9 +- log.go | 9 +- logs/conn.go | 9 +- logs/conn_test.go | 9 +- logs/console.go | 9 +- logs/console_test.go | 9 +- logs/file.go | 9 +- logs/file_test.go | 9 +- logs/log.go | 9 +- logs/smtp.go | 9 +- logs/smtp_test.go | 9 +- memzipfile.go | 9 +- middleware/error.go | 9 +- middleware/exceptions.go | 9 +- middleware/i18n.go | 9 +- mime.go | 9 +- namespace.go | 9 +- namespace_test.go | 9 +- orm/cmd.go | 9 +- orm/cmd_utils.go | 9 +- orm/db.go | 9 +- orm/db_alias.go | 9 +- orm/db_mysql.go | 9 +- orm/db_oracle.go | 9 +- orm/db_postgres.go | 9 +- orm/db_sqlite.go | 9 +- orm/db_tables.go | 9 +- orm/db_utils.go | 9 +- orm/models.go | 9 +- orm/models_boot.go | 9 +- orm/models_fields.go | 9 +- orm/models_info_f.go | 9 +- orm/models_info_m.go | 9 +- orm/models_test.go | 9 +- orm/models_utils.go | 9 +- orm/orm.go | 9 +- orm/orm_conds.go | 9 +- orm/orm_log.go | 9 +- orm/orm_object.go | 9 +- orm/orm_querym2m.go | 9 +- orm/orm_queryset.go | 9 +- orm/orm_raw.go | 9 +- orm/orm_test.go | 9 +- orm/types.go | 9 +- orm/utils.go | 9 +- parser.go | 9 +- plugins/auth/basic.go | 9 +- router.go | 36 +++-- router_test.go | 31 +++- session/couchbase/sess_couchbase.go | 9 +- session/memcache/sess_memcache.go | 9 +- session/mysql/sess_mysql.go | 9 +- session/postgres/sess_postgresql.go | 9 +- session/redis/sess_redis.go | 9 +- session/sess_cookie.go | 9 +- session/sess_cookie_test.go | 9 +- session/sess_file.go | 9 +- session/sess_mem.go | 9 +- session/sess_mem_test.go | 9 +- session/sess_test.go | 9 +- session/sess_utils.go | 9 +- session/session.go | 9 +- staticfile.go | 8 +- swagger/docsSpec.go | 9 +- template.go | 9 +- template_test.go | 9 +- templatefunc.go | 103 ++++++------ templatefunc_test.go | 87 ++++++----- testing/assertions.go | 10 ++ testing/client.go | 9 +- toolbox/debug.go | 9 +- toolbox/debug_test.go | 9 +- toolbox/healthcheck.go | 9 +- toolbox/profile.go | 9 +- toolbox/profile_test.go | 9 +- toolbox/statistics.go | 9 +- toolbox/statistics_test.go | 9 +- toolbox/task.go | 9 +- toolbox/task_test.go | 9 +- tree.go | 9 +- tree_test.go | 9 +- utils/caller.go | 9 +- utils/caller_test.go | 9 +- utils/captcha/captcha.go | 10 +- utils/captcha/image.go | 9 +- utils/captcha/image_test.go | 9 +- utils/captcha/siprng.go | 9 +- utils/captcha/siprng_test.go | 9 +- utils/file.go | 9 +- utils/file_test.go | 9 +- utils/mail.go | 9 +- utils/mail_test.go | 9 +- utils/rand.go | 8 +- utils/safemap.go | 9 +- utils/safemap_test.go | 9 +- utils/slice.go | 9 +- utils/slice_test.go | 9 +- validation/util.go | 9 +- validation/util_test.go | 9 +- validation/validation.go | 9 +- validation/validation_test.go | 9 +- validation/validators.go | 9 +- 160 files changed, 1074 insertions(+), 773 deletions(-) create mode 100644 .go_style create mode 100644 forms/elements/button.go create mode 100644 forms/elements/captcha.go create mode 100644 forms/elements/checkbox.go create mode 100644 forms/elements/csrf.go create mode 100644 forms/elements/date.go create mode 100644 forms/elements/element.go create mode 100644 forms/elements/email.go create mode 100644 forms/elements/file.go create mode 100644 forms/elements/hidden.go create mode 100644 forms/elements/image.go create mode 100644 forms/elements/multicheckbox.go create mode 100644 forms/elements/number.go create mode 100644 forms/elements/password.go create mode 100644 forms/elements/radio.go create mode 100644 forms/elements/range.go create mode 100644 forms/elements/select.go create mode 100644 forms/elements/submit.go create mode 100644 forms/elements/text.go create mode 100644 forms/elements/textarea.go create mode 100644 forms/elements/time.go create mode 100644 forms/elements/url.go create mode 100644 forms/form.go create mode 100644 forms/form_test.go create mode 100644 testing/assertions.go diff --git a/.go_style b/.go_style new file mode 100644 index 00000000..26682eed --- /dev/null +++ b/.go_style @@ -0,0 +1,16 @@ +{ + "file_line": 500, + "func_line": 80, + "params_num":4, + "results_num":3, + "formated": true, + "pkg_name": true, + "camel_name":true, + "ignore":[ + "a/*", + "b/*/c/*.go" + ], + "fatal":[ + "formated" + ] +} diff --git a/admin.go b/admin.go index 0ef4f93f..fa9ef3b3 100644 --- a/admin.go +++ b/admin.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/app.go b/app.go index d0a47665..cc7f218e 100644 --- a/app.go +++ b/app.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/beego.go b/beego.go index e6484802..05737a88 100644 --- a/beego.go +++ b/beego.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/cache/cache.go b/cache/cache.go index c4baeba3..472c7c9a 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/cache_test.go b/cache/cache_test.go index 4ba1fb8a..9426e159 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/conv.go b/cache/conv.go index 202939b3..7f06992c 100644 --- a/cache/conv.go +++ b/cache/conv.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/conv_test.go b/cache/conv_test.go index f6756fc4..d98db9e3 100644 --- a/cache/conv_test.go +++ b/cache/conv_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/file.go b/cache/file.go index 62febac3..dd9fd843 100644 --- a/cache/file.go +++ b/cache/file.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 7b473dff..a7c9f197 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/memory.go b/cache/memory.go index 00e055e8..68147d96 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/cache/redis/redis.go b/cache/redis/redis.go index b532ca85..6ce1ff18 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package cache import ( diff --git a/config.go b/config.go index 1984e3cd..55290cd5 100644 --- a/config.go +++ b/config.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/config/config.go b/config/config.go index c7454fe0..8e719562 100644 --- a/config/config.go +++ b/config/config.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/fake.go b/config/fake.go index 1ddf8298..dba1a470 100644 --- a/config/fake.go +++ b/config/fake.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/ini.go b/config/ini.go index 500d07c1..ba3fd23a 100644 --- a/config/ini.go +++ b/config/ini.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/ini_test.go b/config/ini_test.go index e5e6b9ab..fc4d88dd 100644 --- a/config/ini_test.go +++ b/config/ini_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/json.go b/config/json.go index 8cac5e21..332280f4 100644 --- a/config/json.go +++ b/config/json.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/json_test.go b/config/json_test.go index 849febd0..80f5148c 100644 --- a/config/json_test.go +++ b/config/json_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/xml/xml.go b/config/xml/xml.go index 05171a37..fbd15190 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/xml/xml_test.go b/config/xml/xml_test.go index ba6ebbd6..dac1a527 100644 --- a/config/xml/xml_test.go +++ b/config/xml/xml_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 8cae5109..5d2d2b84 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config/yaml/yaml_test.go b/config/yaml/yaml_test.go index 3a8d68dc..ca066c72 100644 --- a/config/yaml/yaml_test.go +++ b/config/yaml/yaml_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package config import ( diff --git a/config_test.go b/config_test.go index 70bbf0d6..9b355c45 100644 --- a/config_test.go +++ b/config_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/context/context.go b/context/context.go index 15a05c90..8ef8233f 100644 --- a/context/context.go +++ b/context/context.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package context import ( diff --git a/context/input.go b/context/input.go index 46b31352..13f78fbc 100644 --- a/context/input.go +++ b/context/input.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package context import ( diff --git a/context/input_test.go b/context/input_test.go index b6d1f9d5..dc554786 100644 --- a/context/input_test.go +++ b/context/input_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package context import ( diff --git a/context/output.go b/context/output.go index aa9efb4c..b46c6a2d 100644 --- a/context/output.go +++ b/context/output.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package context import ( diff --git a/controller.go b/controller.go index 6f7b510c..f486bc36 100644 --- a/controller.go +++ b/controller.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/docs.go b/docs.go index 07b25dd4..8dfd3d82 100644 --- a/docs.go +++ b/docs.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/filter.go b/filter.go index 4f99c300..d9024f9a 100644 --- a/filter.go +++ b/filter.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego // FilterRouter defines filter operation before controller handler execution. diff --git a/filter_test.go b/filter_test.go index e6056599..089fea03 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/flash.go b/flash.go index 66cb1f07..68de09c9 100644 --- a/flash.go +++ b/flash.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/flash_test.go b/flash_test.go index b3ecc4c5..383a10b7 100644 --- a/flash_test.go +++ b/flash_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/forms/elements/button.go b/forms/elements/button.go new file mode 100644 index 00000000..4a9e5ba6 --- /dev/null +++ b/forms/elements/button.go @@ -0,0 +1,15 @@ +package elements + +type Button struct { + Element +} + +func NewButton() *Button { + b := &Button{} + b.options = make(map[string]interface{}) + b.attributes = make(map[string]interface{}) + b.labelAttributes = make(map[string]interface{}) + b.labelOptions = make(map[string]interface{}) + b.SetAttribute("type", "button") + return b +} diff --git a/forms/elements/captcha.go b/forms/elements/captcha.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/captcha.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/checkbox.go b/forms/elements/checkbox.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/checkbox.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/csrf.go b/forms/elements/csrf.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/csrf.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/date.go b/forms/elements/date.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/date.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/element.go b/forms/elements/element.go new file mode 100644 index 00000000..ccb914c4 --- /dev/null +++ b/forms/elements/element.go @@ -0,0 +1,232 @@ +package elements + +type LableInterface interface { + SetLable(label string) + GetLable() (label string) + SetLabelAttributes(labelattrs map[string]interface{}) + GetLabelAttributes() (labelattrs map[string]interface{}) + SetLabelOptions(labelOptions map[string]interface{}) + GetLabelOptions() (labelOptions map[string]interface{}) + ClearLabelOptions() + RemoveLabelOptions(keys []string) + SetLabelOption(key string, val interface{}) + GetLabelOption(key string) (val interface{}) + RemoveLabelOption(key string) + HasLabelOption(key string) bool +} + +type ElementInterface interface { + SetName(name string) + GetName() (name string) + SetOptions(options map[string]interface{}) + SetOption(key string, val interface{}) + GetOptions() (options map[string]interface{}) + GetOption(key string) (val interface{}) + SetAttribute(key string, val interface{}) + GetAttribute(key string) (val interface{}) + RemoveAttribute(key string) + HasAttribute(key string) bool + SetAttributes(attributes map[string]interface{}) + GetAttributes() (attributes map[string]interface{}) + RemoveAttributes(keys []string) + ClearAttributes() + SetValue(val interface{}) + GetValue() (val interface{}) + SetMessages(msg string) + GetMessages() (msg string) + SetValidator(v ValidatorInterface) + Valid(val interface{}) bool + GetMessage() string + LableInterface +} + +type ValidatorInterface interface { + IsValid(val interface{}) bool + GetMessages() (msg string) +} + +type Element struct { + options map[string]interface{} + attributes map[string]interface{} + labelAttributes map[string]interface{} + labelOptions map[string]interface{} + value interface{} + lable string + messages string + validator ValidatorInterface +} + +func (e *Element) SetName(name string) { + e.SetAttribute("name", name) +} + +func (e *Element) GetName() (name string) { + return e.GetAttribute("name").(string) +} + +func (e *Element) SetOptions(options map[string]interface{}) { + if val, ok := options["label"]; ok { + e.SetLable(val.(string)) + } + + if val, ok := options["label_attributes"]; ok { + e.SetLabelAttributes(val.(map[string]interface{})) + } + + if val, ok := options["label_options"]; ok { + e.SetLabelOptions(val.(map[string]interface{})) + } + e.options = options +} + +func (e *Element) SetOption(key string, val interface{}) { + e.options[key] = val +} + +func (e *Element) GetOptions() (options map[string]interface{}) { + return e.options +} + +func (e *Element) GetOption(key string) (val interface{}) { + if val, ok := e.options[key]; ok { + return val + } + return nil +} + +func (e *Element) SetAttribute(key string, val interface{}) { + e.attributes[key] = val +} + +func (e *Element) GetAttribute(key string) (val interface{}) { + if val, ok := e.attributes[key]; ok { + return val + } + return nil +} + +func (e *Element) RemoveAttribute(key string) { + delete(e.attributes, key) +} + +func (e *Element) HasAttribute(key string) bool { + if _, ok := e.attributes[key]; ok { + return true + } + return false +} + +func (e *Element) SetAttributes(attributes map[string]interface{}) { + for key, val := range attributes { + e.SetAttribute(key, val) + } +} + +func (e *Element) GetAttributes() (attributes map[string]interface{}) { + return e.attributes +} + +func (e *Element) RemoveAttributes(keys []string) { + for _, key := range keys { + e.RemoveAttribute(key) + } +} + +func (e *Element) ClearAttributes() { + e.attributes = make(map[string]interface{}) +} + +func (e *Element) SetValue(val interface{}) { + e.value = val +} + +func (e *Element) GetValue() (val interface{}) { + return e.value +} + +func (e *Element) SetLable(label string) { + e.lable = label +} + +func (e *Element) GetLable() (label string) { + return e.lable +} + +func (e *Element) SetLabelAttributes(labelattrs map[string]interface{}) { + e.labelAttributes = labelattrs +} + +func (e *Element) GetLabelAttributes() (labelattrs map[string]interface{}) { + return e.labelAttributes +} + +func (e *Element) SetLabelOptions(labelOptions map[string]interface{}) { + for key, val := range labelOptions { + e.SetLabelOption(key, val) + } +} + +func (e *Element) GetLabelOptions() (labelOptions map[string]interface{}) { + return e.labelOptions +} + +func (e *Element) ClearLabelOptions() { + e.labelOptions = make(map[string]interface{}) +} + +func (e *Element) RemoveLabelOptions(keys []string) { + for _, key := range keys { + e.RemoveLabelOption(key) + } +} + +func (e *Element) SetLabelOption(key string, val interface{}) { + e.labelOptions[key] = val +} + +func (e *Element) GetLabelOption(key string) (val interface{}) { + if v, ok := e.labelOptions[key]; ok { + return v + } + return nil +} + +func (e *Element) RemoveLabelOption(key string) { + delete(e.labelOptions, key) +} + +func (e *Element) HasLabelOption(key string) bool { + if _, ok := e.labelOptions[key]; ok { + return true + } + return false +} + +func (e *Element) SetMessages(msg string) { + e.messages = msg +} + +func (e *Element) GetMessages() (msg string) { + return e.messages +} + +func (e *Element) SetValidator(v ValidatorInterface) { + e.validator = v +} + +func (e *Element) Valid(val interface{}) bool { + if e.validator == nil { + return true + } + if e.validator.IsValid(val) { + return true + } + return false +} + +func (e *Element) GetMessage() string { + if e.validator == nil { + return "" + } + return e.validator.GetMessages() +} diff --git a/forms/elements/email.go b/forms/elements/email.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/email.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/file.go b/forms/elements/file.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/file.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/hidden.go b/forms/elements/hidden.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/hidden.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/image.go b/forms/elements/image.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/image.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/multicheckbox.go b/forms/elements/multicheckbox.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/multicheckbox.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/number.go b/forms/elements/number.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/number.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/password.go b/forms/elements/password.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/password.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/radio.go b/forms/elements/radio.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/radio.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/range.go b/forms/elements/range.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/range.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/select.go b/forms/elements/select.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/select.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/submit.go b/forms/elements/submit.go new file mode 100644 index 00000000..faa88a5a --- /dev/null +++ b/forms/elements/submit.go @@ -0,0 +1,15 @@ +package elements + +type Submit struct { + Element +} + +func NewSubmit() *Submit { + b := &Submit{} + b.options = make(map[string]interface{}) + b.attributes = make(map[string]interface{}) + b.labelAttributes = make(map[string]interface{}) + b.labelOptions = make(map[string]interface{}) + b.SetAttribute("type", "submit") + return b +} diff --git a/forms/elements/text.go b/forms/elements/text.go new file mode 100644 index 00000000..c1050c3d --- /dev/null +++ b/forms/elements/text.go @@ -0,0 +1,15 @@ +package elements + +type Text struct { + Element +} + +func NewText() *Text { + b := &Text{} + b.options = make(map[string]interface{}) + b.attributes = make(map[string]interface{}) + b.labelAttributes = make(map[string]interface{}) + b.labelOptions = make(map[string]interface{}) + b.SetAttribute("type", "text") + return b +} diff --git a/forms/elements/textarea.go b/forms/elements/textarea.go new file mode 100644 index 00000000..c879ec49 --- /dev/null +++ b/forms/elements/textarea.go @@ -0,0 +1,15 @@ +package elements + +type Textarea struct { + Element +} + +func NewTextarea() *Textarea { + b := &Textarea{} + b.options = make(map[string]interface{}) + b.attributes = make(map[string]interface{}) + b.labelAttributes = make(map[string]interface{}) + b.labelOptions = make(map[string]interface{}) + b.SetAttribute("type", "textarea") + return b +} diff --git a/forms/elements/time.go b/forms/elements/time.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/time.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/elements/url.go b/forms/elements/url.go new file mode 100644 index 00000000..395f9955 --- /dev/null +++ b/forms/elements/url.go @@ -0,0 +1 @@ +package elements \ No newline at end of file diff --git a/forms/form.go b/forms/form.go new file mode 100644 index 00000000..b554037d --- /dev/null +++ b/forms/form.go @@ -0,0 +1,57 @@ +// Beego (http://beego.me/) +// @description beego is an open-source, high-performance web framework for the Go programming language. +// @link http://github.com/astaxie/beego for the canonical source repository +// @license http://github.com/astaxie/beego/blob/master/LICENSE +// @authors astaxie + +package forms + +import ( + "github.com/astaxie/beego/forms/elements" +) + +type Form struct { + elements map[string]elements.ElementInterface +} + +func NewForm() *Form { + f := &Form{} + f.elements = make(map[string]elements.ElementInterface) + return f +} + +func (f *Form) Init() *Form { + f.elements = make(map[string]elements.ElementInterface) +} + +func (f *Form) Valid(data map[string]interface{}) bool { + for k, val := range data { + if e, ok := f.elements[k]; ok { + if !e.Valid(val) { + return false + } + } + } + return true +} + +func (f *Form) SetData() { + +} + +func (f *Form) Bind() { + +} + +func (f *Form) SaveData() { + +} + +func (f *Form) AddElement(e elements.ElementInterface) { + name := e.GetName() + f.elements[name] = e +} + +func (f *Form) Render() string { + +} diff --git a/forms/form_test.go b/forms/form_test.go new file mode 100644 index 00000000..6a1a78b9 --- /dev/null +++ b/forms/form_test.go @@ -0,0 +1,21 @@ +package forms + +import ( + "fmt" + "testing" + + "./elements" +) + +func formTest(t *testing.T) { + rf := NewForm() + username := elements.NewText() + username.SetAttribute("name", "username") + username.SetAttribute("id", "username") + rf.AddElement(username) + + button := elements.NewSubmit() + rf.AddElement(rf) + + fmt.Println(rf.Render()) +} diff --git a/httplib/httplib.go b/httplib/httplib.go index 53b8e6ca..e60ac7ac 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package httplib import ( diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 64de6596..9a94116e 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package httplib import ( diff --git a/log.go b/log.go index 5465dc1a..2a6793b0 100644 --- a/log.go +++ b/log.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/logs/conn.go b/logs/conn.go index d36fa364..e7b0464f 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/conn_test.go b/logs/conn_test.go index aa50b41d..3108ca15 100644 --- a/logs/conn_test.go +++ b/logs/conn_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/console.go b/logs/console.go index c5c72faa..e552c92d 100644 --- a/logs/console.go +++ b/logs/console.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/console_test.go b/logs/console_test.go index 30e1e4c6..fe08d4f8 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/file.go b/logs/file.go index a7f4c724..512df983 100644 --- a/logs/file.go +++ b/logs/file.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/file_test.go b/logs/file_test.go index 65d543ba..bc88d607 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/log.go b/logs/log.go index b3dedf98..b62105ec 100644 --- a/logs/log.go +++ b/logs/log.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/smtp.go b/logs/smtp.go index d5c7101d..b45b2fbb 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/logs/smtp_test.go b/logs/smtp_test.go index 96cd3759..58e15134 100644 --- a/logs/smtp_test.go +++ b/logs/smtp_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package logs import ( diff --git a/memzipfile.go b/memzipfile.go index a100b59d..2fce9b81 100644 --- a/memzipfile.go +++ b/memzipfile.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/middleware/error.go b/middleware/error.go index 10d4fc53..743180cb 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package middleware import ( diff --git a/middleware/exceptions.go b/middleware/exceptions.go index a6a18ff0..4165c3e6 100644 --- a/middleware/exceptions.go +++ b/middleware/exceptions.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package middleware import "fmt" diff --git a/middleware/i18n.go b/middleware/i18n.go index 5c44dc4a..3009b46d 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package middleware import ( diff --git a/mime.go b/mime.go index ada6d099..57487398 100644 --- a/mime.go +++ b/mime.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/namespace.go b/namespace.go index 985ded3b..c8ec2488 100644 --- a/namespace.go +++ b/namespace.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/namespace_test.go b/namespace_test.go index 64bd8dec..7587f4b2 100644 --- a/namespace_test.go +++ b/namespace_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/orm/cmd.go b/orm/cmd.go index a15727ae..e31b0ef4 100644 --- a/orm/cmd.go +++ b/orm/cmd.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index ffb354e0..82f125d3 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db.go b/orm/db.go index 847ab0d5..f4a9f42c 100644 --- a/orm/db.go +++ b/orm/db.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_alias.go b/orm/db_alias.go index 816441a6..a8f64edf 100644 --- a/orm/db_alias.go +++ b/orm/db_alias.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_mysql.go b/orm/db_mysql.go index e024b2a1..85582966 100644 --- a/orm/db_mysql.go +++ b/orm/db_mysql.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_oracle.go b/orm/db_oracle.go index 5c93e3c8..c8321c5a 100644 --- a/orm/db_oracle.go +++ b/orm/db_oracle.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm // oracle dbBaser diff --git a/orm/db_postgres.go b/orm/db_postgres.go index 4609d8ca..ac94446e 100644 --- a/orm/db_postgres.go +++ b/orm/db_postgres.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_sqlite.go b/orm/db_sqlite.go index de2bf63d..8f6aae76 100644 --- a/orm/db_sqlite.go +++ b/orm/db_sqlite.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_tables.go b/orm/db_tables.go index 21d18876..56e19759 100644 --- a/orm/db_tables.go +++ b/orm/db_tables.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/db_utils.go b/orm/db_utils.go index 8d895e43..713eb51c 100644 --- a/orm/db_utils.go +++ b/orm/db_utils.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models.go b/orm/models.go index 2d82a204..c1c51deb 100644 --- a/orm/models.go +++ b/orm/models.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_boot.go b/orm/models_boot.go index eb3fce66..138a4844 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_fields.go b/orm/models_fields.go index f328999d..dd99596f 100644 --- a/orm/models_fields.go +++ b/orm/models_fields.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_info_f.go b/orm/models_info_f.go index 622791d9..ebd140f7 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_info_m.go b/orm/models_info_m.go index f759fa33..e9d2e65f 100644 --- a/orm/models_info_m.go +++ b/orm/models_info_m.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_test.go b/orm/models_test.go index 2b42fd52..99377bfa 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/models_utils.go b/orm/models_utils.go index bf331fed..1d19a466 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm.go b/orm/orm.go index 947a453c..96cb3430 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_conds.go b/orm/orm_conds.go index 0110ac18..c5a57305 100644 --- a/orm/orm_conds.go +++ b/orm/orm_conds.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_log.go b/orm/orm_log.go index cde61449..ad9ae70c 100644 --- a/orm/orm_log.go +++ b/orm/orm_log.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_object.go b/orm/orm_object.go index 82067026..1a91d789 100644 --- a/orm/orm_object.go +++ b/orm/orm_object.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_querym2m.go b/orm/orm_querym2m.go index bcd67660..c525d42e 100644 --- a/orm/orm_querym2m.go +++ b/orm/orm_querym2m.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_queryset.go b/orm/orm_queryset.go index c6e8f19d..5c651023 100644 --- a/orm/orm_queryset.go +++ b/orm/orm_queryset.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_raw.go b/orm/orm_raw.go index 373aaf1b..5936e590 100644 --- a/orm/orm_raw.go +++ b/orm/orm_raw.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/orm_test.go b/orm/orm_test.go index 016e103b..d8b48ef4 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/types.go b/orm/types.go index 77585570..f104513a 100644 --- a/orm/types.go +++ b/orm/types.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/orm/utils.go b/orm/utils.go index d2326fc1..a0bb94a3 100644 --- a/orm/utils.go +++ b/orm/utils.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie, slene - package orm import ( diff --git a/parser.go b/parser.go index f8818295..35382741 100644 --- a/parser.go +++ b/parser.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/plugins/auth/basic.go b/plugins/auth/basic.go index 16aea240..feafc0c9 100644 --- a/plugins/auth/basic.go +++ b/plugins/auth/basic.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package auth // Example: diff --git a/router.go b/router.go index 52e641c0..e43e55fe 100644 --- a/router.go +++ b/router.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( @@ -66,6 +65,8 @@ var ( "DelSession", "SessionRegenerateID", "DestroySession", "IsAjax", "GetSecureCookie", "SetSecureCookie", "XsrfToken", "CheckXsrfCookie", "XsrfFormHtml", "GetControllerAndAction"} + + url_placeholder = "{{placeholder}}" ) // To append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter @@ -428,6 +429,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin } } if t.wildcard != nil { + url = path.Join(url, url_placeholder) ok, u := p.geturl(t.wildcard, url, controllName, methodName, params) if ok { return ok, u @@ -456,15 +458,14 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin if find { if l.regexps == nil { if len(l.wildcards) == 0 { - return true, url + return true, strings.Replace(url, "/"+url_placeholder, "", 1) } if len(l.wildcards) == 1 { if v, ok := params[l.wildcards[0]]; ok { delete(params, l.wildcards[0]) - return true, url + "/" + v + tourl(params) - } - if l.wildcards[0] == ":splat" { - return true, url + tourl(params) + return true, strings.Replace(url, url_placeholder, v, 1) + tourl(params) + } else { + return false, "" } } if len(l.wildcards) == 3 && l.wildcards[0] == "." { @@ -472,7 +473,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin if e, isok := params[":ext"]; isok { delete(params, ":path") delete(params, ":ext") - return true, url + "/" + p + "." + e + tourl(params) + return true, strings.Replace(url, url_placeholder, p+"."+e, -1) + tourl(params) } } } @@ -483,7 +484,8 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin continue } if u, ok := params[v]; ok { - url += "/" + u + delete(params, v) + url = strings.Replace(url, url_placeholder, u, 1) } else { if canskip { canskip = false @@ -493,7 +495,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin } } } - return true, url + return true, url + tourl(params) } else { var i int var startreg bool @@ -516,11 +518,11 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin } } if l.regexps.MatchString(regurl) { - if url == "/" { - return true, url + regurl + tourl(params) - } else { - return true, url + "/" + regurl + tourl(params) + ps := strings.Split(regurl, "/") + for _, p := range ps { + url = strings.Replace(url, url_placeholder, p, 1) } + return true, url + tourl(params) } } } diff --git a/router_test.go b/router_test.go index e96a1403..d4d80fa0 100644 --- a/router_test.go +++ b/router_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( @@ -95,10 +94,10 @@ func TestUrlFor(t *testing.T) { func TestUrlFor3(t *testing.T) { handler := NewControllerRegister() handler.AddAuto(&TestController{}) - if a := handler.UrlFor("TestController.Myext"); a != "/test/myext" { + if a := handler.UrlFor("TestController.Myext"); a != "/test/myext" && a != "/Test/Myext" { t.Errorf("TestController.Myext must equal to /test/myext, but get " + a) } - if a := handler.UrlFor("TestController.GetUrl"); a != "/test/geturl" { + if a := handler.UrlFor("TestController.GetUrl"); a != "/test/geturl" && a != "/Test/GetUrl" { t.Errorf("TestController.GetUrl must equal to /test/geturl, but get " + a) } } @@ -106,8 +105,14 @@ func TestUrlFor3(t *testing.T) { func TestUrlFor2(t *testing.T) { handler := NewControllerRegister() handler.Add("/v1/:v/cms_:id(.+)_:page(.+).html", &TestController{}, "*:List") + handler.Add("/v1/:username/edit", &TestController{}, "get:GetUrl") handler.Add("/v1/:v(.+)_cms/ttt_:id(.+)_:page(.+).html", &TestController{}, "*:Param") handler.Add("/:year:int/:month:int/:title/:entid", &TestController{}) + if handler.UrlFor("TestController.GetUrl", ":username", "astaxie") != "/v1/astaxie/edit" { + Info(handler.UrlFor("TestController.GetUrl")) + t.Errorf("TestController.List must equal to /v1/astaxie/edit") + } + if handler.UrlFor("TestController.List", ":v", "za", ":id", "12", ":page", "123") != "/v1/za/cms_12_123.html" { Info(handler.UrlFor("TestController.List")) @@ -162,6 +167,18 @@ func TestAutoFunc(t *testing.T) { } } +func TestAutoFunc2(t *testing.T) { + r, _ := http.NewRequest("GET", "/Test/List", nil) + w := httptest.NewRecorder() + + handler := NewControllerRegister() + handler.AddAuto(&TestController{}) + handler.ServeHTTP(w, r) + if w.Body.String() != "i am list" { + t.Errorf("user define func can't run") + } +} + func TestAutoFuncParams(t *testing.T) { r, _ := http.NewRequest("GET", "/test/params/2009/11/12", nil) w := httptest.NewRecorder() diff --git a/session/couchbase/sess_couchbase.go b/session/couchbase/sess_couchbase.go index b033d67e..7d15654d 100644 --- a/session/couchbase/sess_couchbase.go +++ b/session/couchbase/sess_couchbase.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/memcache/sess_memcache.go b/session/memcache/sess_memcache.go index 1558e239..8712743a 100644 --- a/session/memcache/sess_memcache.go +++ b/session/memcache/sess_memcache.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/mysql/sess_mysql.go b/session/mysql/sess_mysql.go index dc0d1506..39f31230 100644 --- a/session/mysql/sess_mysql.go +++ b/session/mysql/sess_mysql.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session // mysql session support need create table as sql: diff --git a/session/postgres/sess_postgresql.go b/session/postgres/sess_postgresql.go index 4e3aca75..1796da2f 100644 --- a/session/postgres/sess_postgresql.go +++ b/session/postgres/sess_postgresql.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session /* diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index 0d7032f1..13527f15 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_cookie.go b/session/sess_cookie.go index 5a75e402..08b1ce38 100644 --- a/session/sess_cookie.go +++ b/session/sess_cookie.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_cookie_test.go b/session/sess_cookie_test.go index 475b836b..0a5831e1 100644 --- a/session/sess_cookie_test.go +++ b/session/sess_cookie_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_file.go b/session/sess_file.go index 38bfa95b..38de7a90 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_mem.go b/session/sess_mem.go index 676d6058..deec8190 100644 --- a/session/sess_mem.go +++ b/session/sess_mem.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_mem_test.go b/session/sess_mem_test.go index 79684953..6bcbd157 100644 --- a/session/sess_mem_test.go +++ b/session/sess_mem_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_test.go b/session/sess_test.go index 535f0c4c..ed9acd9d 100644 --- a/session/sess_test.go +++ b/session/sess_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/sess_utils.go b/session/sess_utils.go index cdf0e99b..63bf3d9c 100644 --- a/session/sess_utils.go +++ b/session/sess_utils.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/session/session.go b/session/session.go index c4b281b7..04ecb986 100644 --- a/session/session.go +++ b/session/session.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package session import ( diff --git a/staticfile.go b/staticfile.go index d74aa223..52ab6dc4 100644 --- a/staticfile.go +++ b/staticfile.go @@ -1,11 +1,11 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie package beego diff --git a/swagger/docsSpec.go b/swagger/docsSpec.go index 23149a20..fd054c52 100644 --- a/swagger/docsSpec.go +++ b/swagger/docsSpec.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package swagger const SwaggerVersion = "1.2" diff --git a/template.go b/template.go index ad1902d2..69a286c2 100644 --- a/template.go +++ b/template.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego //@todo add template funcs diff --git a/template_test.go b/template_test.go index fc2a90a0..a18dc09f 100644 --- a/template_test.go +++ b/template_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/templatefunc.go b/templatefunc.go index 274e3af9..da1ebc56 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( @@ -361,10 +360,10 @@ func RenderForm(obj interface{}) template.HTML { fieldT := objT.Field(i) - label, name, fType, ignored := parseFormTag(fieldT) - if ignored { - continue - } + label, name, fType, ignored := parseFormTag(fieldT) + if ignored { + continue + } raw = append(raw, renderFormField(label, name, fType, fieldV.Interface())) } @@ -373,60 +372,60 @@ func RenderForm(obj interface{}) template.HTML { // renderFormField returns a string containing HTML of a single form field. func renderFormField(label, name, fType string, value interface{}) string { - if isValidForInput(fType) { - return fmt.Sprintf(`%v`, label, name, fType, value) - } + if isValidForInput(fType) { + return fmt.Sprintf(`%v`, label, name, fType, value) + } - return fmt.Sprintf(`%v<%v name="%v">%v`, label, fType, name, value, fType) + return fmt.Sprintf(`%v<%v name="%v">%v`, label, fType, name, value, fType) } // isValidForInput checks if fType is a valid value for the `type` property of an HTML input element. func isValidForInput(fType string) bool { - validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button search email url tel number range date month week time datetime datetime-local color") - for _, validType := range validInputTypes { - if fType == validType { - return true - } - } - return false + validInputTypes := strings.Fields("text password checkbox radio submit reset hidden image file button search email url tel number range date month week time datetime datetime-local color") + for _, validType := range validInputTypes { + if fType == validType { + return true + } + } + return false } // parseFormTag takes the stuct-tag of a StructField and parses the `form` value. // returned are the form label, name-property, type and wether the field should be ignored. func parseFormTag(fieldT reflect.StructField) (label, name, fType string, ignored bool) { - tags := strings.Split(fieldT.Tag.Get("form"), ",") - label = fieldT.Name + ": " - name = fieldT.Name - fType = "text" - ignored = false; + tags := strings.Split(fieldT.Tag.Get("form"), ",") + label = fieldT.Name + ": " + name = fieldT.Name + fType = "text" + ignored = false - switch len(tags) { - case 1: - if tags[0] == "-" { - ignored = true - } - if len(tags[0]) > 0 { - name = tags[0] - } - case 2: - if len(tags[0]) > 0 { - name = tags[0] - } - if len(tags[1]) > 0 { - fType = tags[1] - } - case 3: - if len(tags[0]) > 0 { - name = tags[0] - } - if len(tags[1]) > 0 { - fType = tags[1] - } - if len(tags[2]) > 0 { - label = tags[2] - } - } - return + switch len(tags) { + case 1: + if tags[0] == "-" { + ignored = true + } + if len(tags[0]) > 0 { + name = tags[0] + } + case 2: + if len(tags[0]) > 0 { + name = tags[0] + } + if len(tags[1]) > 0 { + fType = tags[1] + } + case 3: + if len(tags[0]) > 0 { + name = tags[0] + } + if len(tags[1]) > 0 { + fType = tags[1] + } + if len(tags[2]) > 0 { + label = tags[2] + } + } + return } func isStructPtr(t reflect.Type) bool { diff --git a/templatefunc_test.go b/templatefunc_test.go index 373b11fa..fabbb431 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -1,21 +1,20 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( "html/template" "net/url" + "reflect" "testing" "time" - "reflect" ) func TestSubstr(t *testing.T) { @@ -141,17 +140,17 @@ func TestParseForm(t *testing.T) { func TestRenderForm(t *testing.T) { type user struct { - Id int `form:"-"` - tag string `form:"tag"` - Name interface{} `form:"username"` - Age int `form:"age,text,年龄:"` - Sex string - Email []string - Intro string `form:",textarea"` + Id int `form:"-"` + tag string `form:"tag"` + Name interface{} `form:"username"` + Age int `form:"age,text,年龄:"` + Sex string + Email []string + Intro string `form:",textarea"` Ignored string `form:"-"` } - u := user{Name: "test", Intro: "Some Text"} + u := user{Name: "test", Intro: "Some Text"} output := RenderForm(u) if output != template.HTML("") { t.Errorf("output should be empty but got %v", output) @@ -168,51 +167,51 @@ func TestRenderForm(t *testing.T) { } func TestRenderFormField(t *testing.T) { - html := renderFormField("Label: ", "Name", "text", "Value") - if html != `Label: ` { - t.Errorf("Wrong html output for input[type=text]: %v ", html) - } + html := renderFormField("Label: ", "Name", "text", "Value") + if html != `Label: ` { + t.Errorf("Wrong html output for input[type=text]: %v ", html) + } - html = renderFormField("Label: ", "Name", "textarea", "Value") - if html != `Label: ` { - t.Errorf("Wrong html output for textarea: %v ", html) - } + html = renderFormField("Label: ", "Name", "textarea", "Value") + if html != `Label: ` { + t.Errorf("Wrong html output for textarea: %v ", html) + } } func TestParseFormTag(t *testing.T) { - // create struct to contain field with different types of struct-tag `form` + // create struct to contain field with different types of struct-tag `form` type user struct { All int `form:"name,text,年龄:"` NoName int `form:",hidden,年龄:"` - OnlyLabel int `form:",,年龄:"` - OnlyName int `form:"name"` - Ignored int `form:"-"` - } + OnlyLabel int `form:",,年龄:"` + OnlyName int `form:"name"` + Ignored int `form:"-"` + } objT := reflect.TypeOf(&user{}).Elem() - label, name, fType, ignored := parseFormTag(objT.Field(0)) - if !(name == "name" && label == "年龄:" && fType == "text" && ignored == false) { + label, name, fType, ignored := parseFormTag(objT.Field(0)) + if !(name == "name" && label == "年龄:" && fType == "text" && ignored == false) { t.Errorf("Form Tag with name, label and type was not correctly parsed.") - } + } - label, name, fType, ignored = parseFormTag(objT.Field(1)) - if !(name == "NoName" && label == "年龄:" && fType == "hidden" && ignored == false) { + label, name, fType, ignored = parseFormTag(objT.Field(1)) + if !(name == "NoName" && label == "年龄:" && fType == "hidden" && ignored == false) { t.Errorf("Form Tag with label and type but without name was not correctly parsed.") - } + } - label, name, fType, ignored = parseFormTag(objT.Field(2)) - if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && ignored == false) { + label, name, fType, ignored = parseFormTag(objT.Field(2)) + if !(name == "OnlyLabel" && label == "年龄:" && fType == "text" && ignored == false) { t.Errorf("Form Tag containing only label was not correctly parsed.") - } + } - label, name, fType, ignored = parseFormTag(objT.Field(3)) - if !(name == "name" && label == "OnlyName: " && fType == "text" && ignored == false) { - t.Errorf("Form Tag containing only name was not correctly parsed.") - } + label, name, fType, ignored = parseFormTag(objT.Field(3)) + if !(name == "name" && label == "OnlyName: " && fType == "text" && ignored == false) { + t.Errorf("Form Tag containing only name was not correctly parsed.") + } - label, name, fType, ignored = parseFormTag(objT.Field(4)) - if (ignored == false) { - t.Errorf("Form Tag that should be ignored was not correctly parsed.") - } + label, name, fType, ignored = parseFormTag(objT.Field(4)) + if ignored == false { + t.Errorf("Form Tag that should be ignored was not correctly parsed.") + } } diff --git a/testing/assertions.go b/testing/assertions.go new file mode 100644 index 00000000..7fa4c199 --- /dev/null +++ b/testing/assertions.go @@ -0,0 +1,10 @@ +// Beego (http://beego.me/) +// +// @description beego is an open-source, high-performance web framework for the Go programming language. +// +// @link http://github.com/astaxie/beego for the canonical source repository +// +// @license http://github.com/astaxie/beego/blob/master/LICENSE +// +// @authors astaxie +package testing diff --git a/testing/client.go b/testing/client.go index a185da55..0819d508 100644 --- a/testing/client.go +++ b/testing/client.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package testing import ( diff --git a/toolbox/debug.go b/toolbox/debug.go index 614a673d..3b0ee803 100644 --- a/toolbox/debug.go +++ b/toolbox/debug.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/debug_test.go b/toolbox/debug_test.go index 290bed7c..08f0661f 100644 --- a/toolbox/debug_test.go +++ b/toolbox/debug_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/healthcheck.go b/toolbox/healthcheck.go index 4332586f..dc195549 100644 --- a/toolbox/healthcheck.go +++ b/toolbox/healthcheck.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox //type DatabaseCheck struct { diff --git a/toolbox/profile.go b/toolbox/profile.go index a3588ac3..0e0aaa40 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/profile_test.go b/toolbox/profile_test.go index 1a3345e8..cb3135d5 100644 --- a/toolbox/profile_test.go +++ b/toolbox/profile_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/statistics.go b/toolbox/statistics.go index 74632ee3..fed8cc2b 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/statistics_test.go b/toolbox/statistics_test.go index 1fb99b76..fc6e4dce 100644 --- a/toolbox/statistics_test.go +++ b/toolbox/statistics_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/task.go b/toolbox/task.go index 81fdf110..439035a1 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/toolbox/task_test.go b/toolbox/task_test.go index 0a9f50ad..a1e85166 100644 --- a/toolbox/task_test.go +++ b/toolbox/task_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package toolbox import ( diff --git a/tree.go b/tree.go index f2bc6aa9..1bf72f9d 100644 --- a/tree.go +++ b/tree.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import ( diff --git a/tree_test.go b/tree_test.go index 0a30f677..589b64ca 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package beego import "testing" diff --git a/utils/caller.go b/utils/caller.go index 3ba9e94f..6684880a 100644 --- a/utils/caller.go +++ b/utils/caller.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/caller_test.go b/utils/caller_test.go index 13b289e0..95262d75 100644 --- a/utils/caller_test.go +++ b/utils/caller_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 80c7e77d..5354423e 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -1,13 +1,13 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - +// // an example for use captcha // // ``` diff --git a/utils/captcha/image.go b/utils/captcha/image.go index 6abfc0a4..cde4932a 100644 --- a/utils/captcha/image.go +++ b/utils/captcha/image.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package captcha import ( diff --git a/utils/captcha/image_test.go b/utils/captcha/image_test.go index 09c119c5..393262c8 100644 --- a/utils/captcha/image_test.go +++ b/utils/captcha/image_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package captcha import ( diff --git a/utils/captcha/siprng.go b/utils/captcha/siprng.go index 4afca3bf..54d6e93b 100644 --- a/utils/captcha/siprng.go +++ b/utils/captcha/siprng.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package captcha import ( diff --git a/utils/captcha/siprng_test.go b/utils/captcha/siprng_test.go index 54b5d5be..f6d31055 100644 --- a/utils/captcha/siprng_test.go +++ b/utils/captcha/siprng_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package captcha import "testing" diff --git a/utils/file.go b/utils/file.go index aead5e7b..ad221c92 100644 --- a/utils/file.go +++ b/utils/file.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/file_test.go b/utils/file_test.go index 5c72b040..0805415a 100644 --- a/utils/file_test.go +++ b/utils/file_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/mail.go b/utils/mail.go index d8f79f26..d0383ade 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/mail_test.go b/utils/mail_test.go index 84660a8e..f09f5b78 100644 --- a/utils/mail_test.go +++ b/utils/mail_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import "testing" diff --git a/utils/rand.go b/utils/rand.go index d521dfab..23cf3926 100644 --- a/utils/rand.go +++ b/utils/rand.go @@ -1,11 +1,11 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie package utils diff --git a/utils/safemap.go b/utils/safemap.go index 2df14a53..27c63eba 100644 --- a/utils/safemap.go +++ b/utils/safemap.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/safemap_test.go b/utils/safemap_test.go index 6c2da5bd..32034e91 100644 --- a/utils/safemap_test.go +++ b/utils/safemap_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/slice.go b/utils/slice.go index 786f47a9..6092e79a 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/utils/slice_test.go b/utils/slice_test.go index fb9c1d1d..a1c053c6 100644 --- a/utils/slice_test.go +++ b/utils/slice_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package utils import ( diff --git a/validation/util.go b/validation/util.go index e8ca8a1c..91d2a735 100644 --- a/validation/util.go +++ b/validation/util.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package validation import ( diff --git a/validation/util_test.go b/validation/util_test.go index bcd0c0e5..ca99a7ab 100644 --- a/validation/util_test.go +++ b/validation/util_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package validation import ( diff --git a/validation/validation.go b/validation/validation.go index 477676a7..b86b565f 100644 --- a/validation/validation.go +++ b/validation/validation.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package validation import ( diff --git a/validation/validation_test.go b/validation/validation_test.go index d43a5938..ff279b64 100644 --- a/validation/validation_test.go +++ b/validation/validation_test.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package validation import ( diff --git a/validation/validators.go b/validation/validators.go index 5cab1c0f..5a468d67 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -1,13 +1,12 @@ // Beego (http://beego.me/) - +// // @description beego is an open-source, high-performance web framework for the Go programming language. - +// // @link http://github.com/astaxie/beego for the canonical source repository - +// // @license http://github.com/astaxie/beego/blob/master/LICENSE - +// // @authors astaxie - package validation import ( From 707c9513029571b0e5493e5418031be76d0d69e0 Mon Sep 17 00:00:00 2001 From: sandysong Date: Fri, 4 Jul 2014 16:57:37 +0800 Subject: [PATCH 016/120] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Detect=20Engine?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orm/db_alias.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orm/db_alias.go b/orm/db_alias.go index 816441a6..13b34aa8 100644 --- a/orm/db_alias.go +++ b/orm/db_alias.go @@ -140,7 +140,7 @@ func detectTZ(al *alias) { if engine != "" { al.Engine = engine } else { - engine = "INNODB" + al.Engine = "INNODB" } case DR_Sqlite: From 2933d1fedd3430fb6fbf56a6aafce6736c29084d Mon Sep 17 00:00:00 2001 From: reterVision Date: Sat, 5 Jul 2014 22:27:31 +0800 Subject: [PATCH 017/120] Make redis cache timeout not trivial. - Instead of using HASH for all the caches, use HASH + normal KEYs. - HASH being used as a collection of all KEYs, this is useful when application wants to clear all keys. --- cache/cache.go | 8 ++-- cache/redis/redis.go | 43 ++++++++++++++++----- cache/redis/redis_test.go | 81 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 cache/redis/redis_test.go diff --git a/cache/cache.go b/cache/cache.go index c4baeba3..acb42043 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -35,11 +35,11 @@ type Cache interface { Incr(key string) error // decrease cached int value by key, as a counter. Decr(key string) error - // check cached value is existed or not. + // check if cached value exists or not. IsExist(key string) bool // clear all cache. ClearAll() error - // start gc routine via config string setting. + // start gc routine based on config string settings. StartAndGC(config string) error } @@ -58,13 +58,13 @@ func Register(name string, adapter Cache) { adapters[name] = adapter } -// Create a new cache driver by adapter and config string. +// Create a new cache driver by adapter name and config string. // config need to be correct JSON as string: {"interval":360}. // it will start gc automatically. func NewCache(adapterName, config string) (Cache, error) { adapter, ok := adapters[adapterName] if !ok { - return nil, fmt.Errorf("cache: unknown adaptername %q (forgotten import?)", adapterName) + return nil, fmt.Errorf("cache: unknown adapter name %q (forgot to import?)", adapterName) } err := adapter.StartAndGC(config) if err != nil { diff --git a/cache/redis/redis.go b/cache/redis/redis.go index b532ca85..6b66f34a 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -47,7 +47,7 @@ func (rc *RedisCache) do(commandName string, args ...interface{}) (reply interfa // Get cache from redis. func (rc *RedisCache) Get(key string) interface{} { - v, err := rc.do("HGET", rc.key, key) + v, err := rc.do("GET", key) if err != nil { return nil } @@ -56,43 +56,66 @@ func (rc *RedisCache) Get(key string) interface{} { } // put cache to redis. -// timeout is ignored. func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error { - _, err := rc.do("HSET", rc.key, key, val) + _, err := rc.do("HSET", rc.key, key, true) + if err != nil { + return nil + } + _, err = rc.do("SET", key, val) + if err != nil { + return nil + } + _, err = rc.do("EXPIRE", key, timeout) return err } // delete cache in redis. func (rc *RedisCache) Delete(key string) error { - _, err := rc.do("HDEL", rc.key, key) + _, err := rc.do("DEL", key) + if err != nil { + return nil + } + _, err = rc.do("HDEL", rc.key, key) return err } -// check cache exist in redis. +// check cache's existence in redis. func (rc *RedisCache) IsExist(key string) bool { - v, err := redis.Bool(rc.do("HEXISTS", rc.key, key)) + v, err := redis.Bool(rc.do("EXISTS", key)) if err != nil { return false } - + if v == false { + _, err := rc.do("HDEL", rc.key, key) + if err != nil { + return false + } + } return v } // increase counter in redis. func (rc *RedisCache) Incr(key string) error { - _, err := redis.Bool(rc.do("HINCRBY", rc.key, key, 1)) + _, err := redis.Bool(rc.do("INCRBY", key, 1)) return err } // decrease counter in redis. func (rc *RedisCache) Decr(key string) error { - _, err := redis.Bool(rc.do("HINCRBY", rc.key, key, -1)) + _, err := redis.Bool(rc.do("INCRBY", key, -1)) return err } // clean all cache in redis. delete this redis collection. func (rc *RedisCache) ClearAll() error { - _, err := rc.do("DEL", rc.key) + cachedKeys, err := redis.Strings(rc.do("HKEYS", rc.key)) + for _, str := range cachedKeys { + _, err := rc.do("DEL", str) + if err != nil { + return nil + } + } + _, err = rc.do("DEL", rc.key) return err } diff --git a/cache/redis/redis_test.go b/cache/redis/redis_test.go new file mode 100644 index 00000000..fc751d03 --- /dev/null +++ b/cache/redis/redis_test.go @@ -0,0 +1,81 @@ +// Beego (http://beego.me/) + +// @description beego is an open-source, high-performance web framework for the Go programming language. + +// @link http://github.com/astaxie/beego for the canonical source repository + +// @license http://github.com/astaxie/beego/blob/master/LICENSE + +// @authors astaxie + +package cache + +import ( + "testing" + "time" + + "github.com/beego/redigo/redis" + + "github.com/astaxie/beego/cache" +) + +func TestRedisCache(t *testing.T) { + bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`) + if err != nil { + t.Error("init err") + } + if err = bm.Put("astaxie", 1, 10); err != nil { + t.Error("set Error", err) + } + if !bm.IsExist("astaxie") { + t.Error("check err") + } + + time.Sleep(10 * time.Second) + + if bm.IsExist("astaxie") { + t.Error("check err") + } + if err = bm.Put("astaxie", 1, 10); err != nil { + t.Error("set Error", err) + } + + if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 { + t.Error("get err") + } + + if err = bm.Incr("astaxie"); err != nil { + t.Error("Incr Error", err) + } + + if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 { + t.Error("get err") + } + + if err = bm.Decr("astaxie"); err != nil { + t.Error("Decr Error", err) + } + + if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 { + t.Error("get err") + } + bm.Delete("astaxie") + if bm.IsExist("astaxie") { + t.Error("delete err") + } + //test string + if err = bm.Put("astaxie", "author", 10); err != nil { + t.Error("set Error", err) + } + if !bm.IsExist("astaxie") { + t.Error("check err") + } + + if v, _ := redis.String(bm.Get("astaxie"), err); v != "author" { + t.Error("get err") + } + // test clear all + if err = bm.ClearAll(); err != nil { + t.Error("clear all err") + } +} From b6c4e27a75202322052312ab23c13f78e8cf7887 Mon Sep 17 00:00:00 2001 From: reterVision Date: Sat, 5 Jul 2014 22:30:51 +0800 Subject: [PATCH 018/120] Adjust the action order in Put function. --- cache/redis/redis.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 6b66f34a..d9ff221f 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -57,11 +57,11 @@ func (rc *RedisCache) Get(key string) interface{} { // put cache to redis. func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error { - _, err := rc.do("HSET", rc.key, key, true) + _, err := rc.do("SET", key, val) if err != nil { return nil } - _, err = rc.do("SET", key, val) + _, err = rc.do("HSET", rc.key, key, true) if err != nil { return nil } From 3bb4d6f0133dbe526e1917bebe2dc7a98ced6384 Mon Sep 17 00:00:00 2001 From: Christoph Portmann Date: Tue, 8 Jul 2014 23:20:55 +0300 Subject: [PATCH 019/120] beego/context: Fix ignored Header in case SetStatus has been called before --- context/output.go | 9 ++++++++- router.go | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/context/output.go b/context/output.go index b46c6a2d..8f59c94d 100644 --- a/context/output.go +++ b/context/output.go @@ -71,6 +71,14 @@ func (output *BeegoOutput) Body(content []byte) { } else { output.Header("Content-Length", strconv.Itoa(len(content))) } + + // Write status code if it has been set manually + // Set it to 0 afterwards to prevent "multiple response.WriteHeader calls" + if output.Status != 0 { + output.Context.ResponseWriter.WriteHeader(output.Status) + output.Status = 0 + } + output_writer.Write(content) switch output_writer.(type) { case *gzip.Writer: @@ -270,7 +278,6 @@ func (output *BeegoOutput) ContentType(ext string) { // SetStatus sets response status code. // It writes response header directly. func (output *BeegoOutput) SetStatus(status int) { - output.Context.ResponseWriter.WriteHeader(status) output.Status = status } diff --git a/router.go b/router.go index e43e55fe..eba65c51 100644 --- a/router.go +++ b/router.go @@ -762,6 +762,11 @@ Admin: Info("beego:" + r.URL.Path + " 404" + " +" + timeend.String()) } } + + // Call WriteHeader if status code has been set changed + if context.Output.Status != 0 { + w.writer.WriteHeader(context.Output.Status) + } } func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) { From 19c3a5b41c86713c3c59185e9c290409aefa1286 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 9 Jul 2014 09:38:36 +0800 Subject: [PATCH 020/120] beego: improve the router debug infomation --- router.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/router.go b/router.go index eba65c51..ba0d0b60 100644 --- a/router.go +++ b/router.go @@ -756,11 +756,13 @@ Admin: } if RunMode == "dev" { + var devinfo string if findrouter { - Info("beego: router defined " + routerInfo.pattern + " " + r.URL.Path + " +" + timeend.String()) + devinfo = fmt.Sprintf("| % -10s| % -16s | % -10s | % -40s | % -10s | % -40s |", "beego", timeend.String(), r.Method, r.URL.Path, "match", routerInfo.pattern) } else { - Info("beego:" + r.URL.Path + " 404" + " +" + timeend.String()) + devinfo = fmt.Sprintf("| % -10s| % -16s | % -10s | % -40s | % -10s |", "beego", timeend.String(), r.Method, r.URL.Path, "notmatch") } + Info(devinfo) } // Call WriteHeader if status code has been set changed From 007db805be6b221cba7232f112f41bd2df5b144c Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 10 Jul 2014 13:04:18 +0800 Subject: [PATCH 021/120] code style simplify --- cache/cache.go | 11 ++++++----- cache/conv.go | 42 +++++++++++++++--------------------------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 123c5417..c6a9da47 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -51,7 +51,7 @@ func Register(name string, adapter Cache) { if adapter == nil { panic("cache: Register adapter is nil") } - if _, dup := adapters[name]; dup { + if _, ok := adapters[name]; ok { panic("cache: Register called twice for adapter " + name) } adapters[name] = adapter @@ -60,14 +60,15 @@ func Register(name string, adapter Cache) { // Create a new cache driver by adapter name and config string. // config need to be correct JSON as string: {"interval":360}. // it will start gc automatically. -func NewCache(adapterName, config string) (Cache, error) { +func NewCache(adapterName, config string) (adapter Cache, e error) { adapter, ok := adapters[adapterName] if !ok { - return nil, fmt.Errorf("cache: unknown adapter name %q (forgot to import?)", adapterName) + e = fmt.Errorf("cache: unknown adapter name %q (forgot to import?)", adapterName) + return } err := adapter.StartAndGC(config) if err != nil { - return nil, err + adapter = nil } - return adapter, nil + return } diff --git a/cache/conv.go b/cache/conv.go index 7f06992c..57167706 100644 --- a/cache/conv.go +++ b/cache/conv.go @@ -22,12 +22,11 @@ func GetString(v interface{}) string { case []byte: return string(result) default: - if v == nil { - return "" - } else { + if v != nil { return fmt.Sprintf("%v", result) } } + return "" } // convert interface to int. @@ -40,12 +39,9 @@ func GetInt(v interface{}) int { case int64: return int(result) default: - d := GetString(v) - if d != "" { - value, err := strconv.Atoi(d) - if err == nil { - return value - } + if d := GetString(v); d != "" { + value, _ := strconv.Atoi(d) + return value } } return 0 @@ -61,12 +57,10 @@ func GetInt64(v interface{}) int64 { case int64: return result default: - d := GetString(v) - if d != "" { - result, err := strconv.ParseInt(d, 10, 64) - if err == nil { - return result - } + + if d := GetString(v); d != "" { + value, _ := strconv.ParseInt(d, 10, 64) + return value } } return 0 @@ -78,12 +72,9 @@ func GetFloat64(v interface{}) float64 { case float64: return result default: - d := GetString(v) - if d != "" { - value, err := strconv.ParseFloat(d, 64) - if err == nil { - return value - } + if d := GetString(v); d != "" { + value, _ := strconv.ParseFloat(d, 64) + return value } } return 0 @@ -95,12 +86,9 @@ func GetBool(v interface{}) bool { case bool: return result default: - d := GetString(v) - if d != "" { - result, err := strconv.ParseBool(d) - if err == nil { - return result - } + if d := GetString(v); d != "" { + value, _ := strconv.ParseBool(d) + return value } } return false From 8683ee7c6778060a40b6f63b192ae49214c2b054 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 10 Jul 2014 13:28:54 +0800 Subject: [PATCH 022/120] code style simplify --- cache/file.go | 126 ++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 75 deletions(-) diff --git a/cache/file.go b/cache/file.go index dd9fd843..dec68f87 100644 --- a/cache/file.go +++ b/cache/file.go @@ -60,12 +60,10 @@ func NewFileCache() *FileCache { // Start and begin gc for file cache. // the config need to be like {CachePath:"/cache","FileSuffix":".bin","DirectoryLevel":2,"EmbedExpiry":0} -func (this *FileCache) StartAndGC(config string) error { +func (fc *FileCache) StartAndGC(config string) error { var cfg map[string]string json.Unmarshal([]byte(config), &cfg) - //fmt.Println(cfg) - //fmt.Println(config) if _, ok := cfg["CachePath"]; !ok { cfg["CachePath"] = FileCachePath } @@ -78,69 +76,53 @@ func (this *FileCache) StartAndGC(config string) error { if _, ok := cfg["EmbedExpiry"]; !ok { cfg["EmbedExpiry"] = strconv.FormatInt(FileCacheEmbedExpiry, 10) } - this.CachePath = cfg["CachePath"] - this.FileSuffix = cfg["FileSuffix"] - this.DirectoryLevel, _ = strconv.Atoi(cfg["DirectoryLevel"]) - this.EmbedExpiry, _ = strconv.Atoi(cfg["EmbedExpiry"]) + fc.CachePath = cfg["CachePath"] + fc.FileSuffix = cfg["FileSuffix"] + fc.DirectoryLevel, _ = strconv.Atoi(cfg["DirectoryLevel"]) + fc.EmbedExpiry, _ = strconv.Atoi(cfg["EmbedExpiry"]) - this.Init() + fc.Init() return nil } // Init will make new dir for file cache if not exist. -func (this *FileCache) Init() { +func (fc *FileCache) Init() { app := filepath.Dir(os.Args[0]) - this.CachePath = filepath.Join(app, this.CachePath) - ok, err := exists(this.CachePath) - if err != nil { // print error - //fmt.Println(err) + fc.CachePath = filepath.Join(app, fc.CachePath) + if ok, _ := exists(fc.CachePath); !ok { // todo : error handle + _ = os.MkdirAll(fc.CachePath, os.ModePerm) // todo : error handle } - if !ok { - if err = os.Mkdir(this.CachePath, os.ModePerm); err != nil { - //fmt.Println(err); - } - } - //fmt.Println(this.getCacheFileName("123456")); } // get cached file name. it's md5 encoded. -func (this *FileCache) getCacheFileName(key string) string { +func (fc *FileCache) getCacheFileName(key string) string { m := md5.New() io.WriteString(m, key) keyMd5 := hex.EncodeToString(m.Sum(nil)) - cachePath := this.CachePath - //fmt.Println("cachepath : " , cachePath) - //fmt.Println("md5" , keyMd5); - switch this.DirectoryLevel { + cachePath := fc.CachePath + switch fc.DirectoryLevel { case 2: cachePath = filepath.Join(cachePath, keyMd5[0:2], keyMd5[2:4]) case 1: cachePath = filepath.Join(cachePath, keyMd5[0:2]) } - ok, err := exists(cachePath) - if err != nil { - //fmt.Println(err) + if ok, _ := exists(cachePath); !ok { // todo : error handle + _ = os.MkdirAll(cachePath, os.ModePerm) // todo : error handle } - if !ok { - if err = os.MkdirAll(cachePath, os.ModePerm); err != nil { - //fmt.Println(err); - } - } - return filepath.Join(cachePath, fmt.Sprintf("%s%s", keyMd5, this.FileSuffix)) + + return filepath.Join(cachePath, fmt.Sprintf("%s%s", keyMd5, fc.FileSuffix)) } // Get value from file cache. // if non-exist or expired, return empty string. -func (this *FileCache) Get(key string) interface{} { - filename := this.getCacheFileName(key) - filedata, err := File_get_contents(filename) - //fmt.Println("get length:" , len(filedata)); +func (fc *FileCache) Get(key string) interface{} { + fileData, err := File_get_contents(fc.getCacheFileName(key)) if err != nil { return "" } var to FileCacheItem - Gob_decode(filedata, &to) + Gob_decode(fileData, &to) if to.Expired < time.Now().Unix() { return "" } @@ -150,29 +132,26 @@ func (this *FileCache) Get(key string) interface{} { // Put value into file cache. // timeout means how long to keep this file, unit of ms. // if timeout equals FileCacheEmbedExpiry(default is 0), cache this item forever. -func (this *FileCache) Put(key string, val interface{}, timeout int64) error { +func (fc *FileCache) Put(key string, val interface{}, timeout int64) error { gob.Register(val) - filename := this.getCacheFileName(key) - var item FileCacheItem - item.Data = val + item := FileCacheItem{Data:val} if timeout == FileCacheEmbedExpiry { - item.Expired = time.Now().Unix() + (86400 * 365 * 10) // ten years + item.Expired = time.Now().Unix()+(86400*365*10) // ten years } else { - item.Expired = time.Now().Unix() + timeout + item.Expired = time.Now().Unix()+timeout } item.Lastaccess = time.Now().Unix() data, err := Gob_encode(item) if err != nil { return err } - err = File_put_contents(filename, data) - return err + return File_put_contents(fc.getCacheFileName(key), data) } // Delete file cache value. -func (this *FileCache) Delete(key string) error { - filename := this.getCacheFileName(key) +func (fc *FileCache) Delete(key string) error { + filename := fc.getCacheFileName(key) if ok, _ := exists(filename); ok { return os.Remove(filename) } @@ -180,44 +159,41 @@ func (this *FileCache) Delete(key string) error { } // Increase cached int value. -// this value is saving forever unless Delete. -func (this *FileCache) Incr(key string) error { - data := this.Get(key) +// fc value is saving forever unless Delete. +func (fc *FileCache) Incr(key string) error { + data := fc.Get(key) var incr int - //fmt.Println(reflect.TypeOf(data).Name()) if reflect.TypeOf(data).Name() != "int" { incr = 0 } else { - incr = data.(int) + 1 + incr = data.(int)+1 } - this.Put(key, incr, FileCacheEmbedExpiry) + fc.Put(key, incr, FileCacheEmbedExpiry) return nil } // Decrease cached int value. -func (this *FileCache) Decr(key string) error { - data := this.Get(key) +func (fc *FileCache) Decr(key string) error { + data := fc.Get(key) var decr int if reflect.TypeOf(data).Name() != "int" || data.(int)-1 <= 0 { decr = 0 } else { - decr = data.(int) - 1 + decr = data.(int)-1 } - this.Put(key, decr, FileCacheEmbedExpiry) + fc.Put(key, decr, FileCacheEmbedExpiry) return nil } // Check value is exist. -func (this *FileCache) IsExist(key string) bool { - filename := this.getCacheFileName(key) - ret, _ := exists(filename) +func (fc *FileCache) IsExist(key string) bool { + ret, _ := exists(fc.getCacheFileName(key)) return ret } // Clean cached files. // not implemented. -func (this *FileCache) ClearAll() error { - //this.CachePath +func (fc *FileCache) ClearAll() error { return nil } @@ -235,22 +211,22 @@ func exists(path string) (bool, error) { // Get bytes to file. // if non-exist, create this file. -func File_get_contents(filename string) ([]byte, error) { - f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, os.ModePerm) - if err != nil { - return []byte(""), err +func File_get_contents(filename string) (data []byte, e error) { + f, e := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, os.ModePerm) + if e != nil { + return } defer f.Close() - stat, err := f.Stat() - if err != nil { - return []byte(""), err + stat, e := f.Stat() + if e != nil { + return } - data := make([]byte, stat.Size()) - result, err := f.Read(data) - if int64(result) == stat.Size() { - return data, err + data = make([]byte, stat.Size()) + result, e := f.Read(data) + if e != nil || int64(result) != stat.Size() { + return nil, e } - return []byte(""), err + return } // Put bytes to file. From 0b1b121db8818678d41d97d15269f3819a54650b Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 10 Jul 2014 13:38:05 +0800 Subject: [PATCH 023/120] code style simplify --- cache/file.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cache/file.go b/cache/file.go index dec68f87..b4af2211 100644 --- a/cache/file.go +++ b/cache/file.go @@ -135,11 +135,11 @@ func (fc *FileCache) Get(key string) interface{} { func (fc *FileCache) Put(key string, val interface{}, timeout int64) error { gob.Register(val) - item := FileCacheItem{Data:val} + item := FileCacheItem{Data: val} if timeout == FileCacheEmbedExpiry { - item.Expired = time.Now().Unix()+(86400*365*10) // ten years + item.Expired = time.Now().Unix() + (86400 * 365 * 10) // ten years } else { - item.Expired = time.Now().Unix()+timeout + item.Expired = time.Now().Unix() + timeout } item.Lastaccess = time.Now().Unix() data, err := Gob_encode(item) @@ -166,7 +166,7 @@ func (fc *FileCache) Incr(key string) error { if reflect.TypeOf(data).Name() != "int" { incr = 0 } else { - incr = data.(int)+1 + incr = data.(int) + 1 } fc.Put(key, incr, FileCacheEmbedExpiry) return nil @@ -179,7 +179,7 @@ func (fc *FileCache) Decr(key string) error { if reflect.TypeOf(data).Name() != "int" || data.(int)-1 <= 0 { decr = 0 } else { - decr = data.(int)-1 + decr = data.(int) - 1 } fc.Put(key, decr, FileCacheEmbedExpiry) return nil From 0ff058bd255a27de4b11e9b539a505281b799f45 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Fri, 11 Jul 2014 10:01:49 +0800 Subject: [PATCH 024/120] code style simplify --- cache/memory.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/cache/memory.go b/cache/memory.go index 68147d96..cc4835c1 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -49,15 +49,14 @@ func NewMemoryCache() *MemoryCache { func (bc *MemoryCache) Get(name string) interface{} { bc.lock.RLock() defer bc.lock.RUnlock() - itm, ok := bc.items[name] - if !ok { - return nil + if itm, ok := bc.items[name]; ok { + if (time.Now().Unix() - itm.Lastaccess.Unix()) > itm.expired { + go bc.Delete(name) + return nil + } + return itm.val } - if (time.Now().Unix() - itm.Lastaccess.Unix()) > itm.expired { - go bc.Delete(name) - return nil - } - return itm.val + return nil } // Put cache to memory. @@ -65,12 +64,11 @@ func (bc *MemoryCache) Get(name string) interface{} { func (bc *MemoryCache) Put(name string, value interface{}, expired int64) error { bc.lock.Lock() defer bc.lock.Unlock() - t := MemoryItem{ + bc.items[name] = &MemoryItem{ val: value, Lastaccess: time.Now(), expired: expired, } - bc.items[name] = &t return nil } @@ -82,8 +80,7 @@ func (bc *MemoryCache) Delete(name string) error { return errors.New("key not exist") } delete(bc.items, name) - _, valid := bc.items[name] - if valid { + if _, ok := bc.items[name]; ok { return errors.New("delete key error") } return nil @@ -214,8 +211,7 @@ func (bc *MemoryCache) item_expired(name string) bool { if !ok { return true } - sec := time.Now().Unix() - itm.Lastaccess.Unix() - if sec >= itm.expired { + if time.Now().Unix()-itm.Lastaccess.Unix() >= itm.expired { delete(bc.items, name) return true } From 7d09ac252ac2064cdb76351868c7b294fcbea1c2 Mon Sep 17 00:00:00 2001 From: "Frederic G. MARAND" Date: Fri, 11 Jul 2014 11:15:34 +0200 Subject: [PATCH 025/120] Issue #682: convert logs package to RFC5424 logging levels. --- logs/conn.go | 2 +- logs/conn_test.go | 2 +- logs/console.go | 16 ++++--- logs/console_test.go | 37 +++++++++------ logs/file.go | 2 +- logs/file_test.go | 41 +++++++++------- logs/log.go | 109 +++++++++++++++++++++++++++++++------------ logs/smtp.go | 2 +- 8 files changed, 138 insertions(+), 73 deletions(-) diff --git a/logs/conn.go b/logs/conn.go index e7b0464f..b7255b5c 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -48,7 +48,7 @@ func (c *ConnWriter) Init(jsonconfig string) error { // write message in connection. // if connection is down, try to re-connect. func (c *ConnWriter) WriteMsg(msg string, level int) error { - if level < c.Level { + if level > c.Level { return nil } if c.neddedConnectOnMsg() { diff --git a/logs/conn_test.go b/logs/conn_test.go index 3108ca15..4e200424 100644 --- a/logs/conn_test.go +++ b/logs/conn_test.go @@ -16,5 +16,5 @@ import ( func TestConn(t *testing.T) { log := NewLogger(1000) log.SetLogger("conn", `{"net":"tcp","addr":":7020"}`) - log.Info("info") + log.Informational("informational") } diff --git a/logs/console.go b/logs/console.go index e552c92d..96a34c0f 100644 --- a/logs/console.go +++ b/logs/console.go @@ -27,12 +27,14 @@ func NewBrush(color string) Brush { } var colors = []Brush{ - NewBrush("1;36"), // Trace cyan - NewBrush("1;34"), // Debug blue - NewBrush("1;32"), // Info green - NewBrush("1;33"), // Warn yellow + NewBrush("1;37"), // Emergency white + NewBrush("1;36"), // Alert cyan + NewBrush("1;35"), // Critical magenta NewBrush("1;31"), // Error red - NewBrush("1;35"), // Critical purple + NewBrush("1;33"), // Warning yellow + NewBrush("1;32"), // Notice green + NewBrush("1;34"), // Informational green + NewBrush("1;30"), // Debug black } // ConsoleWriter implements LoggerInterface and writes messages to terminal. @@ -45,7 +47,7 @@ type ConsoleWriter struct { func NewConsole() LoggerInterface { cw := new(ConsoleWriter) cw.lg = log.New(os.Stdout, "", log.Ldate|log.Ltime) - cw.Level = LevelTrace + cw.Level = LevelDebug return cw } @@ -64,7 +66,7 @@ func (c *ConsoleWriter) Init(jsonconfig string) error { // write message in console. func (c *ConsoleWriter) WriteMsg(msg string, level int) error { - if level < c.Level { + if level > c.Level { return nil } if goos := runtime.GOOS; goos == "windows" { diff --git a/logs/console_test.go b/logs/console_test.go index fe08d4f8..8b775baa 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -13,22 +13,29 @@ import ( "testing" ) +// Try each log level in decreasing order of priority. +func testConsoleCalls(bl *BeeLogger) { + bl.Emergency("emergency") + bl.Alert("alert") + bl.Critical("critical") + bl.Error("error") + bl.Warning("warning") + bl.Notice("notice") + bl.Informational("informational") + bl.Debug("debug") +} + +// Test console logging by visually comparing the lines being output with and +// without a log level specification. func TestConsole(t *testing.T) { - log := NewLogger(10000) - log.EnableFuncCallDepth(true) - log.SetLogger("console", "") - log.Trace("trace") - log.Info("info") - log.Warn("warning") - log.Debug("debug") - log.Critical("critical") + log1 := NewLogger(10000) + log1.EnableFuncCallDepth(true) + log1.SetLogger("console", "") + testConsoleCalls(log1) + log2 := NewLogger(100) - log2.SetLogger("console", `{"level":1}`) - log.Trace("trace") - log.Info("info") - log.Warn("warning") - log.Debug("debug") - log.Critical("critical") + log2.SetLogger("console", `{"level":3}`) + testConsoleCalls(log2) } func BenchmarkConsole(b *testing.B) { @@ -36,6 +43,6 @@ func BenchmarkConsole(b *testing.B) { log.EnableFuncCallDepth(true) log.SetLogger("console", "") for i := 0; i < b.N; i++ { - log.Trace("trace") + log.Debug("debug") } } diff --git a/logs/file.go b/logs/file.go index 512df983..2d371a1e 100644 --- a/logs/file.go +++ b/logs/file.go @@ -141,7 +141,7 @@ func (w *FileLogWriter) docheck(size int) { // write logger message into file. func (w *FileLogWriter) WriteMsg(msg string, level int) error { - if level < w.Level { + if level > w.Level { return nil } n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] " diff --git a/logs/file_test.go b/logs/file_test.go index bc88d607..66ebb01c 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -13,6 +13,7 @@ import ( "bufio" "fmt" "os" + "strconv" "testing" "time" ) @@ -20,12 +21,14 @@ import ( func TestFile(t *testing.T) { log := NewLogger(10000) log.SetLogger("file", `{"filename":"test.log"}`) - log.Trace("test") - log.Info("info") log.Debug("debug") - log.Warn("warning") + log.Informational("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) f, err := os.Open("test.log") if err != nil { @@ -42,21 +45,24 @@ func TestFile(t *testing.T) { linenum++ } } - if linenum != 6 { - t.Fatal(linenum, "not line 6") + var expected = LevelDebug + 1 + if linenum != expected { + t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") } os.Remove("test.log") } func TestFile2(t *testing.T) { log := NewLogger(10000) - log.SetLogger("file", `{"filename":"test2.log","level":2}`) - log.Trace("test") - log.Info("info") + log.SetLogger("file", fmt.Sprintf(`{"filename":"test2.log","level":%d}`, LevelError)) log.Debug("debug") - log.Warn("warning") + log.Info("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) f, err := os.Open("test2.log") if err != nil { @@ -73,8 +79,9 @@ func TestFile2(t *testing.T) { linenum++ } } - if linenum != 4 { - t.Fatal(linenum, "not line 4") + var expected = LevelError + 1 + if linenum != expected { + t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") } os.Remove("test2.log") } @@ -82,17 +89,19 @@ func TestFile2(t *testing.T) { func TestFileRotate(t *testing.T) { log := NewLogger(10000) log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`) - log.Trace("test") - log.Info("info") log.Debug("debug") - log.Warn("warning") + log.Info("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) rotatename := "test3.log" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) b, err := exists(rotatename) if !b || err != nil { - t.Fatal("rotate not gen") + t.Fatal("rotate not generated") } os.Remove(rotatename) os.Remove("test3.log") @@ -113,7 +122,7 @@ func BenchmarkFile(b *testing.B) { log := NewLogger(100000) log.SetLogger("file", `{"filename":"test4.log"}`) for i := 0; i < b.N; i++ { - log.Trace("trace") + log.Debug("debug") } os.Remove("test4.log") } diff --git a/logs/log.go b/logs/log.go index b62105ec..bb737bfe 100644 --- a/logs/log.go +++ b/logs/log.go @@ -16,14 +16,25 @@ import ( "sync" ) +// RFC5424 log message levels. const ( - // log message levels - LevelTrace = iota - LevelDebug - LevelInfo - LevelWarn - LevelError + LevelEmergency = iota + LevelAlert LevelCritical + LevelError + LevelWarning + LevelNotice + LevelInformational + LevelDebug +) + +// Legacy loglevel constants to ensure backwards compatibility. +// +// Deprecated: will be removed in 1.5.0. +const ( + LevelInfo = LevelInformational + LevelTrace = LevelDebug + LevelWarn = LevelWarning ) type loggerType func() LoggerInterface @@ -72,6 +83,7 @@ type logMsg struct { // if the buffering chan is full, logger adapters write to file or other way. func NewLogger(channellen int64) *BeeLogger { bl := new(BeeLogger) + bl.level = LevelDebug bl.loggerFuncCallDepth = 2 bl.msg = make(chan *logMsg, channellen) bl.outputs = make(map[string]LoggerInterface) @@ -113,7 +125,7 @@ func (bl *BeeLogger) DelLogger(adaptername string) error { } func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { - if bl.level > loglevel { + if loglevel > bl.level { return nil } lm := new(logMsg) @@ -133,8 +145,10 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { return nil } -// set log message level. -// if message level (such as LevelTrace) is less than logger level (such as LevelWarn), ignore message. +// Set log message level. +// +// If message level (such as LevelDebug) is higher than logger level (such as LevelWarning), +// log providers will not even be sent the message. func (bl *BeeLogger) SetLevel(l int) { bl.level = l } @@ -162,40 +176,73 @@ func (bl *BeeLogger) startLogger() { } } -// log trace level message. -func (bl *BeeLogger) Trace(format string, v ...interface{}) { - msg := fmt.Sprintf("[T] "+format, v...) - bl.writerMsg(LevelTrace, msg) -} - -// log debug level message. -func (bl *BeeLogger) Debug(format string, v ...interface{}) { +// Log EMERGENCY level message. +func (bl *BeeLogger) Emergency(format string, v ...interface{}) { msg := fmt.Sprintf("[D] "+format, v...) - bl.writerMsg(LevelDebug, msg) + bl.writerMsg(LevelEmergency, msg) } -// log info level message. -func (bl *BeeLogger) Info(format string, v ...interface{}) { - msg := fmt.Sprintf("[I] "+format, v...) - bl.writerMsg(LevelInfo, msg) +// Log ALERT level message. +func (bl *BeeLogger) Alert(format string, v ...interface{}) { + msg := fmt.Sprintf("[D] "+format, v...) + bl.writerMsg(LevelAlert, msg) } -// log warn level message. -func (bl *BeeLogger) Warn(format string, v ...interface{}) { - msg := fmt.Sprintf("[W] "+format, v...) - bl.writerMsg(LevelWarn, msg) +// Log CRITICAL level message. +func (bl *BeeLogger) Critical(format string, v ...interface{}) { + msg := fmt.Sprintf("[C] "+format, v...) + bl.writerMsg(LevelCritical, msg) } -// log error level message. +// Log ERROR level message. func (bl *BeeLogger) Error(format string, v ...interface{}) { msg := fmt.Sprintf("[E] "+format, v...) bl.writerMsg(LevelError, msg) } -// log critical level message. -func (bl *BeeLogger) Critical(format string, v ...interface{}) { - msg := fmt.Sprintf("[C] "+format, v...) - bl.writerMsg(LevelCritical, msg) +// Log WARNING level message. +func (bl *BeeLogger) Warning(format string, v ...interface{}) { + msg := fmt.Sprintf("[W] "+format, v...) + bl.writerMsg(LevelWarning, msg) +} + +// Log NOTICE level message. +func (bl *BeeLogger) Notice(format string, v ...interface{}) { + msg := fmt.Sprintf("[W] "+format, v...) + bl.writerMsg(LevelNotice, msg) +} + +// Log INFORMATIONAL level message. +func (bl *BeeLogger) Informational(format string, v ...interface{}) { + msg := fmt.Sprintf("[I] "+format, v...) + bl.writerMsg(LevelInformational, msg) +} + +// Log DEBUG level message. +func (bl *BeeLogger) Debug(format string, v ...interface{}) { + msg := fmt.Sprintf("[D] "+format, v...) + bl.writerMsg(LevelDebug, msg) +} + +// Log WARN level message. +// +// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. +func (bl *BeeLogger) Warn(format string, v ...interface{}) { + bl.Warning(format, v...) +} + +// Log INFO level message. +// +// Deprecated: compatibility alias for Informational(), Will be removed in 1.5.0. +func (bl *BeeLogger) Info(format string, v ...interface{}) { + bl.Informational(format, v...) +} + +// Log TRACE level message. +// +// Deprecated: compatibility alias for Debug(), Will be removed in 1.5.0. +func (bl *BeeLogger) Trace(format string, v ...interface{}) { + bl.Debug(format, v...) } // flush all chan data. diff --git a/logs/smtp.go b/logs/smtp.go index b45b2fbb..d492a61a 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -57,7 +57,7 @@ func (s *SmtpWriter) Init(jsonconfig string) error { // write message in smtp writer. // it will send an email with subject and only this message. func (s *SmtpWriter) WriteMsg(msg string, level int) error { - if level < s.Level { + if level > s.Level { return nil } From a906bf1174dd79d6817fb1688d1e3f4a12e37069 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 12 Jul 2014 09:52:15 +0800 Subject: [PATCH 026/120] code style simplify --- cache/memcache/memcache.go | 80 +++++++++++++++----------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index a7c9f197..2cb478b9 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package cache +package memcache import ( "encoding/json" @@ -20,7 +20,7 @@ import ( // Memcache adapter. type MemcacheCache struct { - c *memcache.Connection + conn *memcache.Connection conninfo string } @@ -31,32 +31,23 @@ func NewMemCache() *MemcacheCache { // get value from memcache. func (rc *MemcacheCache) Get(key string) interface{} { - if rc.c == nil { - var err error - rc.c, err = rc.connectInit() - if err != nil { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { return err } } - v, err := rc.c.Get(key) - if err != nil { - return nil + if v, err := rc.conn.Get(key); err == nil { + if len(v) > 0 { + return string(v[0].Value) + } } - var contain interface{} - if len(v) > 0 { - contain = string(v[0].Value) - } else { - contain = nil - } - return contain + return nil } // put value to memcache. only support string. func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error { - if rc.c == nil { - var err error - rc.c, err = rc.connectInit() - if err != nil { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { return err } } @@ -64,7 +55,7 @@ func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error { if !ok { return errors.New("val must string") } - stored, err := rc.c.Set(key, 0, uint64(timeout), []byte(v)) + stored, err := rc.conn.Set(key, 0, uint64(timeout), []byte(v)) if err == nil && stored == false { return errors.New("stored fail") } @@ -73,60 +64,52 @@ func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error { // delete value in memcache. func (rc *MemcacheCache) Delete(key string) error { - if rc.c == nil { - var err error - rc.c, err = rc.connectInit() - if err != nil { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { return err } } - _, err := rc.c.Delete(key) + _, err := rc.conn.Delete(key) return err } // [Not Support] // increase counter. -func (rc *MemcacheCache) Incr(key string) error { +func (rc *MemcacheCache) Incr(_ string) error { return errors.New("not support in memcache") } // [Not Support] // decrease counter. -func (rc *MemcacheCache) Decr(key string) error { +func (rc *MemcacheCache) Decr(_ string) error { return errors.New("not support in memcache") } // check value exists in memcache. func (rc *MemcacheCache) IsExist(key string) bool { - if rc.c == nil { - var err error - rc.c, err = rc.connectInit() - if err != nil { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { return false } } - v, err := rc.c.Get(key) + v, err := rc.conn.Get(key) if err != nil { return false } if len(v) == 0 { return false - } else { - return true } + return true } // clear all cached in memcache. func (rc *MemcacheCache) ClearAll() error { - if rc.c == nil { - var err error - rc.c, err = rc.connectInit() - if err != nil { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { return err } } - err := rc.c.FlushAll() - return err + return rc.conn.FlushAll() } // start memcache adapter. @@ -139,23 +122,22 @@ func (rc *MemcacheCache) StartAndGC(config string) error { return errors.New("config has no conn key") } rc.conninfo = cf["conn"] - var err error - if rc.c != nil { - rc.c, err = rc.connectInit() - if err != nil { - return errors.New("dial tcp conn error") + if rc.conn == nil { + if err := rc.connectInit(); err != nil { + return err } } return nil } // connect to memcache and keep the connection. -func (rc *MemcacheCache) connectInit() (*memcache.Connection, error) { +func (rc *MemcacheCache) connectInit() error { c, err := memcache.Connect(rc.conninfo) if err != nil { - return nil, err + return err } - return c, nil + rc.conn = c + return nil } func init() { From 0e3e22efbea4eab1ae3b373339fc4ef26114595b Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 12 Jul 2014 09:57:43 +0800 Subject: [PATCH 027/120] merge update --- logs/conn.go | 2 +- logs/conn_test.go | 2 +- logs/console.go | 16 ++++--- logs/console_test.go | 37 +++++++++------ logs/file.go | 2 +- logs/file_test.go | 41 +++++++++------- logs/log.go | 109 +++++++++++++++++++++++++++++++------------ logs/smtp.go | 2 +- 8 files changed, 138 insertions(+), 73 deletions(-) diff --git a/logs/conn.go b/logs/conn.go index e7b0464f..b7255b5c 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -48,7 +48,7 @@ func (c *ConnWriter) Init(jsonconfig string) error { // write message in connection. // if connection is down, try to re-connect. func (c *ConnWriter) WriteMsg(msg string, level int) error { - if level < c.Level { + if level > c.Level { return nil } if c.neddedConnectOnMsg() { diff --git a/logs/conn_test.go b/logs/conn_test.go index 3108ca15..4e200424 100644 --- a/logs/conn_test.go +++ b/logs/conn_test.go @@ -16,5 +16,5 @@ import ( func TestConn(t *testing.T) { log := NewLogger(1000) log.SetLogger("conn", `{"net":"tcp","addr":":7020"}`) - log.Info("info") + log.Informational("informational") } diff --git a/logs/console.go b/logs/console.go index e552c92d..96a34c0f 100644 --- a/logs/console.go +++ b/logs/console.go @@ -27,12 +27,14 @@ func NewBrush(color string) Brush { } var colors = []Brush{ - NewBrush("1;36"), // Trace cyan - NewBrush("1;34"), // Debug blue - NewBrush("1;32"), // Info green - NewBrush("1;33"), // Warn yellow + NewBrush("1;37"), // Emergency white + NewBrush("1;36"), // Alert cyan + NewBrush("1;35"), // Critical magenta NewBrush("1;31"), // Error red - NewBrush("1;35"), // Critical purple + NewBrush("1;33"), // Warning yellow + NewBrush("1;32"), // Notice green + NewBrush("1;34"), // Informational green + NewBrush("1;30"), // Debug black } // ConsoleWriter implements LoggerInterface and writes messages to terminal. @@ -45,7 +47,7 @@ type ConsoleWriter struct { func NewConsole() LoggerInterface { cw := new(ConsoleWriter) cw.lg = log.New(os.Stdout, "", log.Ldate|log.Ltime) - cw.Level = LevelTrace + cw.Level = LevelDebug return cw } @@ -64,7 +66,7 @@ func (c *ConsoleWriter) Init(jsonconfig string) error { // write message in console. func (c *ConsoleWriter) WriteMsg(msg string, level int) error { - if level < c.Level { + if level > c.Level { return nil } if goos := runtime.GOOS; goos == "windows" { diff --git a/logs/console_test.go b/logs/console_test.go index fe08d4f8..8b775baa 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -13,22 +13,29 @@ import ( "testing" ) +// Try each log level in decreasing order of priority. +func testConsoleCalls(bl *BeeLogger) { + bl.Emergency("emergency") + bl.Alert("alert") + bl.Critical("critical") + bl.Error("error") + bl.Warning("warning") + bl.Notice("notice") + bl.Informational("informational") + bl.Debug("debug") +} + +// Test console logging by visually comparing the lines being output with and +// without a log level specification. func TestConsole(t *testing.T) { - log := NewLogger(10000) - log.EnableFuncCallDepth(true) - log.SetLogger("console", "") - log.Trace("trace") - log.Info("info") - log.Warn("warning") - log.Debug("debug") - log.Critical("critical") + log1 := NewLogger(10000) + log1.EnableFuncCallDepth(true) + log1.SetLogger("console", "") + testConsoleCalls(log1) + log2 := NewLogger(100) - log2.SetLogger("console", `{"level":1}`) - log.Trace("trace") - log.Info("info") - log.Warn("warning") - log.Debug("debug") - log.Critical("critical") + log2.SetLogger("console", `{"level":3}`) + testConsoleCalls(log2) } func BenchmarkConsole(b *testing.B) { @@ -36,6 +43,6 @@ func BenchmarkConsole(b *testing.B) { log.EnableFuncCallDepth(true) log.SetLogger("console", "") for i := 0; i < b.N; i++ { - log.Trace("trace") + log.Debug("debug") } } diff --git a/logs/file.go b/logs/file.go index 512df983..2d371a1e 100644 --- a/logs/file.go +++ b/logs/file.go @@ -141,7 +141,7 @@ func (w *FileLogWriter) docheck(size int) { // write logger message into file. func (w *FileLogWriter) WriteMsg(msg string, level int) error { - if level < w.Level { + if level > w.Level { return nil } n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] " diff --git a/logs/file_test.go b/logs/file_test.go index bc88d607..66ebb01c 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -13,6 +13,7 @@ import ( "bufio" "fmt" "os" + "strconv" "testing" "time" ) @@ -20,12 +21,14 @@ import ( func TestFile(t *testing.T) { log := NewLogger(10000) log.SetLogger("file", `{"filename":"test.log"}`) - log.Trace("test") - log.Info("info") log.Debug("debug") - log.Warn("warning") + log.Informational("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) f, err := os.Open("test.log") if err != nil { @@ -42,21 +45,24 @@ func TestFile(t *testing.T) { linenum++ } } - if linenum != 6 { - t.Fatal(linenum, "not line 6") + var expected = LevelDebug + 1 + if linenum != expected { + t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") } os.Remove("test.log") } func TestFile2(t *testing.T) { log := NewLogger(10000) - log.SetLogger("file", `{"filename":"test2.log","level":2}`) - log.Trace("test") - log.Info("info") + log.SetLogger("file", fmt.Sprintf(`{"filename":"test2.log","level":%d}`, LevelError)) log.Debug("debug") - log.Warn("warning") + log.Info("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) f, err := os.Open("test2.log") if err != nil { @@ -73,8 +79,9 @@ func TestFile2(t *testing.T) { linenum++ } } - if linenum != 4 { - t.Fatal(linenum, "not line 4") + var expected = LevelError + 1 + if linenum != expected { + t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") } os.Remove("test2.log") } @@ -82,17 +89,19 @@ func TestFile2(t *testing.T) { func TestFileRotate(t *testing.T) { log := NewLogger(10000) log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`) - log.Trace("test") - log.Info("info") log.Debug("debug") - log.Warn("warning") + log.Info("info") + log.Notice("notice") + log.Warning("warning") log.Error("error") + log.Alert("alert") log.Critical("critical") + log.Emergency("emergency") time.Sleep(time.Second * 4) rotatename := "test3.log" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) b, err := exists(rotatename) if !b || err != nil { - t.Fatal("rotate not gen") + t.Fatal("rotate not generated") } os.Remove(rotatename) os.Remove("test3.log") @@ -113,7 +122,7 @@ func BenchmarkFile(b *testing.B) { log := NewLogger(100000) log.SetLogger("file", `{"filename":"test4.log"}`) for i := 0; i < b.N; i++ { - log.Trace("trace") + log.Debug("debug") } os.Remove("test4.log") } diff --git a/logs/log.go b/logs/log.go index b62105ec..bb737bfe 100644 --- a/logs/log.go +++ b/logs/log.go @@ -16,14 +16,25 @@ import ( "sync" ) +// RFC5424 log message levels. const ( - // log message levels - LevelTrace = iota - LevelDebug - LevelInfo - LevelWarn - LevelError + LevelEmergency = iota + LevelAlert LevelCritical + LevelError + LevelWarning + LevelNotice + LevelInformational + LevelDebug +) + +// Legacy loglevel constants to ensure backwards compatibility. +// +// Deprecated: will be removed in 1.5.0. +const ( + LevelInfo = LevelInformational + LevelTrace = LevelDebug + LevelWarn = LevelWarning ) type loggerType func() LoggerInterface @@ -72,6 +83,7 @@ type logMsg struct { // if the buffering chan is full, logger adapters write to file or other way. func NewLogger(channellen int64) *BeeLogger { bl := new(BeeLogger) + bl.level = LevelDebug bl.loggerFuncCallDepth = 2 bl.msg = make(chan *logMsg, channellen) bl.outputs = make(map[string]LoggerInterface) @@ -113,7 +125,7 @@ func (bl *BeeLogger) DelLogger(adaptername string) error { } func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { - if bl.level > loglevel { + if loglevel > bl.level { return nil } lm := new(logMsg) @@ -133,8 +145,10 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { return nil } -// set log message level. -// if message level (such as LevelTrace) is less than logger level (such as LevelWarn), ignore message. +// Set log message level. +// +// If message level (such as LevelDebug) is higher than logger level (such as LevelWarning), +// log providers will not even be sent the message. func (bl *BeeLogger) SetLevel(l int) { bl.level = l } @@ -162,40 +176,73 @@ func (bl *BeeLogger) startLogger() { } } -// log trace level message. -func (bl *BeeLogger) Trace(format string, v ...interface{}) { - msg := fmt.Sprintf("[T] "+format, v...) - bl.writerMsg(LevelTrace, msg) -} - -// log debug level message. -func (bl *BeeLogger) Debug(format string, v ...interface{}) { +// Log EMERGENCY level message. +func (bl *BeeLogger) Emergency(format string, v ...interface{}) { msg := fmt.Sprintf("[D] "+format, v...) - bl.writerMsg(LevelDebug, msg) + bl.writerMsg(LevelEmergency, msg) } -// log info level message. -func (bl *BeeLogger) Info(format string, v ...interface{}) { - msg := fmt.Sprintf("[I] "+format, v...) - bl.writerMsg(LevelInfo, msg) +// Log ALERT level message. +func (bl *BeeLogger) Alert(format string, v ...interface{}) { + msg := fmt.Sprintf("[D] "+format, v...) + bl.writerMsg(LevelAlert, msg) } -// log warn level message. -func (bl *BeeLogger) Warn(format string, v ...interface{}) { - msg := fmt.Sprintf("[W] "+format, v...) - bl.writerMsg(LevelWarn, msg) +// Log CRITICAL level message. +func (bl *BeeLogger) Critical(format string, v ...interface{}) { + msg := fmt.Sprintf("[C] "+format, v...) + bl.writerMsg(LevelCritical, msg) } -// log error level message. +// Log ERROR level message. func (bl *BeeLogger) Error(format string, v ...interface{}) { msg := fmt.Sprintf("[E] "+format, v...) bl.writerMsg(LevelError, msg) } -// log critical level message. -func (bl *BeeLogger) Critical(format string, v ...interface{}) { - msg := fmt.Sprintf("[C] "+format, v...) - bl.writerMsg(LevelCritical, msg) +// Log WARNING level message. +func (bl *BeeLogger) Warning(format string, v ...interface{}) { + msg := fmt.Sprintf("[W] "+format, v...) + bl.writerMsg(LevelWarning, msg) +} + +// Log NOTICE level message. +func (bl *BeeLogger) Notice(format string, v ...interface{}) { + msg := fmt.Sprintf("[W] "+format, v...) + bl.writerMsg(LevelNotice, msg) +} + +// Log INFORMATIONAL level message. +func (bl *BeeLogger) Informational(format string, v ...interface{}) { + msg := fmt.Sprintf("[I] "+format, v...) + bl.writerMsg(LevelInformational, msg) +} + +// Log DEBUG level message. +func (bl *BeeLogger) Debug(format string, v ...interface{}) { + msg := fmt.Sprintf("[D] "+format, v...) + bl.writerMsg(LevelDebug, msg) +} + +// Log WARN level message. +// +// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. +func (bl *BeeLogger) Warn(format string, v ...interface{}) { + bl.Warning(format, v...) +} + +// Log INFO level message. +// +// Deprecated: compatibility alias for Informational(), Will be removed in 1.5.0. +func (bl *BeeLogger) Info(format string, v ...interface{}) { + bl.Informational(format, v...) +} + +// Log TRACE level message. +// +// Deprecated: compatibility alias for Debug(), Will be removed in 1.5.0. +func (bl *BeeLogger) Trace(format string, v ...interface{}) { + bl.Debug(format, v...) } // flush all chan data. diff --git a/logs/smtp.go b/logs/smtp.go index b45b2fbb..d492a61a 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -57,7 +57,7 @@ func (s *SmtpWriter) Init(jsonconfig string) error { // write message in smtp writer. // it will send an email with subject and only this message. func (s *SmtpWriter) WriteMsg(msg string, level int) error { - if level < s.Level { + if level > s.Level { return nil } From 77c40e6f7be6486c8d17614e20d6b78f0e1da3ae Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 12 Jul 2014 15:51:47 +0800 Subject: [PATCH 028/120] code style simplify --- cache/redis/redis.go | 56 +++++++++++++++++---------------------- cache/redis/redis_test.go | 14 +++++----- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/cache/redis/redis.go b/cache/redis/redis.go index c62fccee..1cb359e8 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package cache +package redis import ( "encoding/json" @@ -46,23 +46,21 @@ func (rc *RedisCache) do(commandName string, args ...interface{}) (reply interfa // Get cache from redis. func (rc *RedisCache) Get(key string) interface{} { - v, err := rc.do("GET", key) - if err != nil { - return nil + if v, err := rc.do("GET", key); err == nil { + return v } - - return v + return nil } // put cache to redis. func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error { - _, err := rc.do("SET", key, val) - if err != nil { - return nil + var err error + if _, err = rc.do("SET", key, val); err != nil { + return err } - _, err = rc.do("HSET", rc.key, key, true) - if err != nil { - return nil + + if _, err = rc.do("HSET", rc.key, key, true); err != nil { + return err } _, err = rc.do("EXPIRE", key, timeout) return err @@ -70,9 +68,9 @@ func (rc *RedisCache) Put(key string, val interface{}, timeout int64) error { // delete cache in redis. func (rc *RedisCache) Delete(key string) error { - _, err := rc.do("DEL", key) - if err != nil { - return nil + var err error + if _, err = rc.do("DEL", key); err != nil { + return err } _, err = rc.do("HDEL", rc.key, key) return err @@ -85,8 +83,7 @@ func (rc *RedisCache) IsExist(key string) bool { return false } if v == false { - _, err := rc.do("HDEL", rc.key, key) - if err != nil { + if _, err = rc.do("HDEL", rc.key, key); err != nil { return false } } @@ -108,10 +105,12 @@ func (rc *RedisCache) Decr(key string) error { // clean all cache in redis. delete this redis collection. func (rc *RedisCache) ClearAll() error { cachedKeys, err := redis.Strings(rc.do("HKEYS", rc.key)) + if err != nil { + return err + } for _, str := range cachedKeys { - _, err := rc.do("DEL", str) - if err != nil { - return nil + if _, err = rc.do("DEL", str); err != nil { + return err } } _, err = rc.do("DEL", rc.key) @@ -140,26 +139,21 @@ func (rc *RedisCache) StartAndGC(config string) error { c := rc.p.Get() defer c.Close() - if err := c.Err(); err != nil { - return err - } - return nil + return c.Err() } // connect to redis. func (rc *RedisCache) connectInit() { + dialFunc := func() (c redis.Conn, err error) { + c, err = redis.Dial("tcp", rc.conninfo) + return + } // initialize a new pool rc.p = &redis.Pool{ MaxIdle: 3, IdleTimeout: 180 * time.Second, - Dial: func() (redis.Conn, error) { - c, err := redis.Dial("tcp", rc.conninfo) - if err != nil { - return nil, err - } - return c, nil - }, + Dial: dialFunc, } } diff --git a/cache/redis/redis_test.go b/cache/redis/redis_test.go index fc751d03..de80d9f6 100644 --- a/cache/redis/redis_test.go +++ b/cache/redis/redis_test.go @@ -8,7 +8,7 @@ // @authors astaxie -package cache +package redis import ( "testing" @@ -20,7 +20,7 @@ import ( ) func TestRedisCache(t *testing.T) { - bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`) + bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`) if err != nil { t.Error("init err") } @@ -48,7 +48,7 @@ func TestRedisCache(t *testing.T) { t.Error("Incr Error", err) } - if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 { + if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 { t.Error("get err") } @@ -74,8 +74,8 @@ func TestRedisCache(t *testing.T) { if v, _ := redis.String(bm.Get("astaxie"), err); v != "author" { t.Error("get err") } - // test clear all - if err = bm.ClearAll(); err != nil { - t.Error("clear all err") - } + // test clear all + if err = bm.ClearAll(); err != nil { + t.Error("clear all err") + } } From 20e05a39080ca81ebe6083b45288e43e9878637a Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 12 Jul 2014 16:03:14 +0800 Subject: [PATCH 029/120] code style simplify --- config/config.go | 2 +- config/fake.go | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index 8e719562..61e33061 100644 --- a/config/config.go +++ b/config/config.go @@ -39,7 +39,7 @@ func Register(name string, adapter Config) { if adapter == nil { panic("config: Register adapter is nil") } - if _, dup := adapters[name]; dup { + if _, ok := adapters[name]; ok { panic("config: Register called twice for adapter " + name) } adapters[name] = adapter diff --git a/config/fake.go b/config/fake.go index dba1a470..561dccca 100644 --- a/config/fake.go +++ b/config/fake.go @@ -20,13 +20,11 @@ type fakeConfigContainer struct { } func (c *fakeConfigContainer) getData(key string) string { - key = strings.ToLower(key) - return c.data[key] + return c.data[strings.ToLower(key)] } func (c *fakeConfigContainer) Set(key, val string) error { - key = strings.ToLower(key) - c.data[key] = val + c.data[strings.ToLower(key)] = val return nil } @@ -55,8 +53,7 @@ func (c *fakeConfigContainer) Float(key string) (float64, error) { } func (c *fakeConfigContainer) DIY(key string) (interface{}, error) { - key = strings.ToLower(key) - if v, ok := c.data[key]; ok { + if v, ok := c.data[strings.ToLower(key)]; ok { return v, nil } return nil, errors.New("key not find") From 9457e61a0c87be90aa8777f38dad23ab0fb2896f Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sat, 12 Jul 2014 22:12:06 +0800 Subject: [PATCH 030/120] code style simplify --- config/ini.go | 89 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/config/ini.go b/config/ini.go index ba3fd23a..f8b9d01b 100644 --- a/config/ini.go +++ b/config/ini.go @@ -83,8 +83,7 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) { } if bytes.HasPrefix(line, sectionStart) && bytes.HasSuffix(line, sectionEnd) { - section = string(line[1 : len(line)-1]) - section = strings.ToLower(section) // section name case insensitive + section = strings.ToLower(string(line[1 : len(line)-1])) // section name case insensitive if comment.Len() > 0 { cfg.sectionComment[section] = comment.String() comment.Reset() @@ -92,23 +91,24 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) { if _, ok := cfg.data[section]; !ok { cfg.data[section] = make(map[string]string) } - } else { - if _, ok := cfg.data[section]; !ok { - cfg.data[section] = make(map[string]string) - } - keyval := bytes.SplitN(line, bEqual, 2) - val := bytes.TrimSpace(keyval[1]) - if bytes.HasPrefix(val, bDQuote) { - val = bytes.Trim(val, `"`) - } + continue + } - key := string(bytes.TrimSpace(keyval[0])) // key name case insensitive - key = strings.ToLower(key) - cfg.data[section][key] = string(val) - if comment.Len() > 0 { - cfg.keycomment[section+"."+key] = comment.String() - comment.Reset() - } + if _, ok := cfg.data[section]; !ok { + cfg.data[section] = make(map[string]string) + } + keyValue := bytes.SplitN(line, bEqual, 2) + val := bytes.TrimSpace(keyValue[1]) + if bytes.HasPrefix(val, bDQuote) { + val = bytes.Trim(val, `"`) + } + + key := string(bytes.TrimSpace(keyValue[0])) // key name case insensitive + key = strings.ToLower(key) + cfg.data[section][key] = string(val) + if comment.Len() > 0 { + cfg.keyComment[section+"."+key] = comment.String() + comment.Reset() } } @@ -121,38 +121,34 @@ type IniConfigContainer struct { filename string data map[string]map[string]string // section=> key:val sectionComment map[string]string // section : comment - keycomment map[string]string // id: []{comment, key...}; id 1 is for main comment. + keyComment map[string]string // id: []{comment, key...}; id 1 is for main comment. sync.RWMutex } // Bool returns the boolean value for a given key. func (c *IniConfigContainer) Bool(key string) (bool, error) { - key = strings.ToLower(key) - return strconv.ParseBool(c.getdata(key)) + return strconv.ParseBool(c.getdata(strings.ToLower(key))) } // Int returns the integer value for a given key. func (c *IniConfigContainer) Int(key string) (int, error) { - key = strings.ToLower(key) - return strconv.Atoi(c.getdata(key)) + return strconv.Atoi(c.getdata(strings.ToLower(key))) } // Int64 returns the int64 value for a given key. func (c *IniConfigContainer) Int64(key string) (int64, error) { - key = strings.ToLower(key) - return strconv.ParseInt(c.getdata(key), 10, 64) + return strconv.ParseInt(c.getdata(strings.ToLower(key)), 10, 64) } // Float returns the float value for a given key. func (c *IniConfigContainer) Float(key string) (float64, error) { - key = strings.ToLower(key) - return strconv.ParseFloat(c.getdata(key), 64) + return strconv.ParseFloat(c.getdata(strings.ToLower(key)), 64) } // String returns the string value for a given key. func (c *IniConfigContainer) String(key string) string { key = strings.ToLower(key) - return c.getdata(key) + return c.getdata(strings.ToLower(key)) } // Strings returns the []string value for a given key. @@ -170,16 +166,19 @@ func (c *IniConfigContainer) Set(key, value string) error { return errors.New("key is empty") } - var section, k string - key = strings.ToLower(key) - sectionkey := strings.Split(key, "::") - if len(sectionkey) >= 2 { - section = sectionkey[0] - k = sectionkey[1] + var ( + section, k string + sectionKey []string = strings.Split(key, "::") + ) + + if len(sectionKey) >= 2 { + section = sectionKey[0] + k = sectionKey[1] } else { section = DEFAULT_SECTION - k = sectionkey[0] + k = sectionKey[0] } + if _, ok := c.data[section]; !ok { c.data[section] = make(map[string]string) } @@ -189,8 +188,7 @@ func (c *IniConfigContainer) Set(key, value string) error { // DIY returns the raw value by a given key. func (c *IniConfigContainer) DIY(key string) (v interface{}, err error) { - key = strings.ToLower(key) - if v, ok := c.data[key]; ok { + if v, ok := c.data[strings.ToLower(key)]; ok { return v, nil } return v, errors.New("key not find") @@ -204,18 +202,19 @@ func (c *IniConfigContainer) getdata(key string) string { return "" } - var section, k string - key = strings.ToLower(key) - sectionkey := strings.Split(key, "::") - if len(sectionkey) >= 2 { - section = sectionkey[0] - k = sectionkey[1] + var ( + section, k string + sectionKey []string = strings.Split(key, "::") + ) + if len(sectionKey) >= 2 { + section = sectionKey[0] + k = sectionKey[1] } else { section = DEFAULT_SECTION - k = sectionkey[0] + k = sectionKey[0] } if v, ok := c.data[section]; ok { - if vv, o := v[k]; o { + if vv, ok2 := v[k]; ok2 { return vv } } From 9d0ad3f97457859ec168df11fab485d5581bc7e1 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Sun, 13 Jul 2014 18:11:13 +0800 Subject: [PATCH 031/120] code style simplify --- config/ini.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ini.go b/config/ini.go index f8b9d01b..262f688b 100644 --- a/config/ini.go +++ b/config/ini.go @@ -214,7 +214,7 @@ func (c *IniConfigContainer) getdata(key string) string { k = sectionKey[0] } if v, ok := c.data[section]; ok { - if vv, ok2 := v[k]; ok2 { + if vv, ok := v[k]; ok { return vv } } From e52386b52dbc12a647a73533ed63d087c3112573 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Tue, 15 Jul 2014 10:01:26 +0800 Subject: [PATCH 032/120] code style simplify --- config/json.go | 67 ++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/config/json.go b/config/json.go index 332280f4..dbab41b0 100644 --- a/config/json.go +++ b/config/json.go @@ -29,13 +29,13 @@ func (js *JsonConfig) Parse(filename string) (ConfigContainer, error) { return nil, err } defer file.Close() - x := &JsonConfigContainer{ - data: make(map[string]interface{}), - } content, err := ioutil.ReadAll(file) if err != nil { return nil, err } + x := &JsonConfigContainer{ + data: make(map[string]interface{}), + } err = json.Unmarshal(content, &x.data) if err != nil { var wrappingArray []interface{} @@ -61,12 +61,10 @@ func (c *JsonConfigContainer) Bool(key string) (bool, error) { if val != nil { if v, ok := val.(bool); ok { return v, nil - } else { - return false, errors.New("not bool value") } - } else { - return false, errors.New("not exist key:" + key) + return false, errors.New("not bool value") } + return false, errors.New("not exist key:" + key) } // Int returns the integer value for a given key. @@ -75,12 +73,10 @@ func (c *JsonConfigContainer) Int(key string) (int, error) { if val != nil { if v, ok := val.(float64); ok { return int(v), nil - } else { - return 0, errors.New("not int value") } - } else { - return 0, errors.New("not exist key:" + key) + return 0, errors.New("not int value") } + return 0, errors.New("not exist key:" + key) } // Int64 returns the int64 value for a given key. @@ -89,12 +85,10 @@ func (c *JsonConfigContainer) Int64(key string) (int64, error) { if val != nil { if v, ok := val.(float64); ok { return int64(v), nil - } else { - return 0, errors.New("not int64 value") } - } else { - return 0, errors.New("not exist key:" + key) + return 0, errors.New("not int64 value") } + return 0, errors.New("not exist key:" + key) } // Float returns the float value for a given key. @@ -103,12 +97,10 @@ func (c *JsonConfigContainer) Float(key string) (float64, error) { if val != nil { if v, ok := val.(float64); ok { return v, nil - } else { - return 0.0, errors.New("not float64 value") } - } else { - return 0.0, errors.New("not exist key:" + key) + return 0.0, errors.New("not float64 value") } + return 0.0, errors.New("not exist key:" + key) } // String returns the string value for a given key. @@ -117,12 +109,9 @@ func (c *JsonConfigContainer) String(key string) string { if val != nil { if v, ok := val.(string); ok { return v - } else { - return "" } - } else { - return "" } + return "" } // Strings returns the []string value for a given key. @@ -143,9 +132,8 @@ func (c *JsonConfigContainer) DIY(key string) (v interface{}, err error) { val := c.getdata(key) if val != nil { return val, nil - } else { - return nil, errors.New("not exist key") } + return nil, errors.New("not exist key") } // section.key or key @@ -155,24 +143,21 @@ func (c *JsonConfigContainer) getdata(key string) interface{} { if len(key) == 0 { return nil } - sectionkey := strings.Split(key, "::") - if len(sectionkey) >= 2 { - cruval, ok := c.data[sectionkey[0]] - if !ok { - return nil - } - for _, key := range sectionkey[1:] { - if v, ok := cruval.(map[string]interface{}); !ok { - return nil - } else if cruval, ok = v[key]; !ok { - return nil + sectionKey := strings.Split(key, "::") + if len(sectionKey) >= 2 { + if curValue, ok := c.data[sectionKey[0]]; ok { + for _, key := range sectionKey[1:] { + if v, ok := curValue.(map[string]interface{}); ok { + if v2, ok := v[key]; ok { + return v2 + } + } } } - return cruval - } else { - if v, ok := c.data[key]; ok { - return v - } + return nil + } + if v, ok := c.data[key]; ok { + return v } return nil } From e6d6419a6557385470ec6c9d9afc1cbe06f2b178 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 16 Jul 2014 22:27:53 +0800 Subject: [PATCH 033/120] beego: static file support robots.txt --- staticfile.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/staticfile.go b/staticfile.go index 52ab6dc4..7fa03b54 100644 --- a/staticfile.go +++ b/staticfile.go @@ -27,11 +27,14 @@ func serverStaticRouter(ctx *context.Context) { if len(prefix) == 0 { continue } - if requestPath == "/favicon.ico" { + if requestPath == "/favicon.ico" || requestPath == "/robots.txt" { file := path.Join(staticDir, requestPath) if utils.FileExists(file) { http.ServeFile(ctx.ResponseWriter, ctx.Request, file) return + } else { + http.NotFound(ctx.ResponseWriter, ctx.Request) + return } } if strings.HasPrefix(requestPath, prefix) { From 1858f3073b97822a3e827be7258d052d19a6485f Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 16 Jul 2014 23:05:38 +0800 Subject: [PATCH 034/120] session: fix #688 --- session/couchbase/sess_couchbase.go | 6 ------ session/memcache/sess_memcache.go | 5 ----- session/redis/sess_redis.go | 6 ------ 3 files changed, 17 deletions(-) diff --git a/session/couchbase/sess_couchbase.go b/session/couchbase/sess_couchbase.go index 7d15654d..8066e338 100644 --- a/session/couchbase/sess_couchbase.go +++ b/session/couchbase/sess_couchbase.go @@ -75,12 +75,6 @@ func (cs *CouchbaseSessionStore) SessionID() string { func (cs *CouchbaseSessionStore) SessionRelease(w http.ResponseWriter) { defer cs.b.Close() - // if rs.values is empty, return directly - if len(cs.values) < 1 { - cs.b.Delete(cs.sid) - return - } - bo, err := session.EncodeGob(cs.values) if err != nil { return diff --git a/session/memcache/sess_memcache.go b/session/memcache/sess_memcache.go index 8712743a..0175b6ba 100644 --- a/session/memcache/sess_memcache.go +++ b/session/memcache/sess_memcache.go @@ -72,11 +72,6 @@ func (rs *MemcacheSessionStore) SessionID() string { // save session values to redis func (rs *MemcacheSessionStore) SessionRelease(w http.ResponseWriter) { defer rs.c.Close() - // if rs.values is empty, return directly - if len(rs.values) < 1 { - rs.c.Delete(rs.sid) - return - } b, err := session.EncodeGob(rs.values) if err != nil { diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index 13527f15..8368dbc0 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -81,12 +81,6 @@ func (rs *RedisSessionStore) SessionRelease(w http.ResponseWriter) { c := rs.p.Get() defer c.Close() - // if rs.values is empty, return directly - if len(rs.values) < 1 { - c.Do("DEL", rs.sid) - return - } - b, err := session.EncodeGob(rs.values) if err != nil { return From f733b5707a9b746b5aa1201f0bef316c8890f15c Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 17 Jul 2014 15:49:40 +0800 Subject: [PATCH 035/120] code style simplify --- config/json.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/config/json.go b/config/json.go index dbab41b0..97e4c2f9 100644 --- a/config/json.go +++ b/config/json.go @@ -145,12 +145,14 @@ func (c *JsonConfigContainer) getdata(key string) interface{} { } sectionKey := strings.Split(key, "::") if len(sectionKey) >= 2 { - if curValue, ok := c.data[sectionKey[0]]; ok { - for _, key := range sectionKey[1:] { - if v, ok := curValue.(map[string]interface{}); ok { - if v2, ok := v[key]; ok { - return v2 - } + curValue, ok := c.data[sectionKey[0]] + if !ok { + return nil + } + for _, key := range sectionKey[1:] { + if v, ok := curValue.(map[string]interface{}); ok { + if v2, ok := v[key]; ok { + return v2 } } } From 84da1c924a7cec1d2db2de77e018692f32ca31d3 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 17 Jul 2014 15:56:06 +0800 Subject: [PATCH 036/120] code style simplify --- config/json.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/json.go b/config/json.go index 97e4c2f9..12b92e7d 100644 --- a/config/json.go +++ b/config/json.go @@ -57,7 +57,7 @@ type JsonConfigContainer struct { // Bool returns the boolean value for a given key. func (c *JsonConfigContainer) Bool(key string) (bool, error) { - val := c.getdata(key) + val := c.getData(key) if val != nil { if v, ok := val.(bool); ok { return v, nil @@ -69,7 +69,7 @@ func (c *JsonConfigContainer) Bool(key string) (bool, error) { // Int returns the integer value for a given key. func (c *JsonConfigContainer) Int(key string) (int, error) { - val := c.getdata(key) + val := c.getData(key) if val != nil { if v, ok := val.(float64); ok { return int(v), nil @@ -81,7 +81,7 @@ func (c *JsonConfigContainer) Int(key string) (int, error) { // Int64 returns the int64 value for a given key. func (c *JsonConfigContainer) Int64(key string) (int64, error) { - val := c.getdata(key) + val := c.getData(key) if val != nil { if v, ok := val.(float64); ok { return int64(v), nil @@ -93,7 +93,7 @@ func (c *JsonConfigContainer) Int64(key string) (int64, error) { // Float returns the float value for a given key. func (c *JsonConfigContainer) Float(key string) (float64, error) { - val := c.getdata(key) + val := c.getData(key) if val != nil { if v, ok := val.(float64); ok { return v, nil @@ -105,7 +105,7 @@ func (c *JsonConfigContainer) Float(key string) (float64, error) { // String returns the string value for a given key. func (c *JsonConfigContainer) String(key string) string { - val := c.getdata(key) + val := c.getData(key) if val != nil { if v, ok := val.(string); ok { return v @@ -129,7 +129,7 @@ func (c *JsonConfigContainer) Set(key, val string) error { // DIY returns the raw value by a given key. func (c *JsonConfigContainer) DIY(key string) (v interface{}, err error) { - val := c.getdata(key) + val := c.getData(key) if val != nil { return val, nil } @@ -137,7 +137,7 @@ func (c *JsonConfigContainer) DIY(key string) (v interface{}, err error) { } // section.key or key -func (c *JsonConfigContainer) getdata(key string) interface{} { +func (c *JsonConfigContainer) getData(key string) interface{} { c.RLock() defer c.RUnlock() if len(key) == 0 { From 69094b2786ffdedba42d721c0366de335fe8631d Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 17 Jul 2014 16:05:17 +0800 Subject: [PATCH 037/120] remove koding link --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 776e5c2d..a5b30a88 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,4 @@ More info [beego.me](http://beego.me) ## LICENSE beego is licensed under the Apache Licence, Version 2.0 -(http://www.apache.org/licenses/LICENSE-2.0.html). - -[![Clone in Koding](http://learn.koding.com/btn/clone_d.png)][koding] -[koding]: https://koding.com/Teamwork?import=https://github.com/astaxie/beego/archive/master.zip&c=git1 \ No newline at end of file +(http://www.apache.org/licenses/LICENSE-2.0.html). \ No newline at end of file From a6ced64441303fb35ad24728f997026469481e27 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 17 Jul 2014 16:22:41 +0800 Subject: [PATCH 038/120] code style simplify --- config/xml/xml.go | 14 +++++++------- config/xml/xml_test.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/xml/xml.go b/config/xml/xml.go index fbd15190..5345f69c 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package config +package xml import ( "errors" @@ -24,27 +24,27 @@ import ( // XmlConfig is a xml config parser and implements Config interface. // xml configurations should be included in tag. // only support key/value pair as value as each item. -type XMLConfig struct { -} +type XMLConfig struct{} // Parse returns a ConfigContainer with parsed xml config map. -func (xmls *XMLConfig) Parse(filename string) (config.ConfigContainer, error) { +func (xc *XMLConfig) Parse(filename string) (config.ConfigContainer, error) { file, err := os.Open(filename) if err != nil { return nil, err } defer file.Close() - x := &XMLConfigContainer{ - data: make(map[string]interface{}), - } + + x := &XMLConfigContainer{data: make(map[string]interface{})} content, err := ioutil.ReadAll(file) if err != nil { return nil, err } + d, err := x2j.DocToMap(string(content)) if err != nil { return nil, err } + x.data = d["config"].(map[string]interface{}) return x, nil } diff --git a/config/xml/xml_test.go b/config/xml/xml_test.go index dac1a527..564d6344 100644 --- a/config/xml/xml_test.go +++ b/config/xml/xml_test.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package config +package xml import ( "os" From c372328f8898e42d3ee740e4fe318ddf1c1fb8af Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 17 Jul 2014 16:22:52 +0800 Subject: [PATCH 039/120] code style simplify --- config/yaml/yaml.go | 39 ++++++++++++++++++--------------------- config/yaml/yaml_test.go | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 5d2d2b84..e948dae2 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package config +package yaml import ( "bytes" @@ -24,39 +24,36 @@ import ( ) // YAMLConfig is a yaml config parser and implements Config interface. -type YAMLConfig struct { -} +type YAMLConfig struct{} // Parse returns a ConfigContainer with parsed yaml config map. -func (yaml *YAMLConfig) Parse(filename string) (config.ConfigContainer, error) { - y := &YAMLConfigContainer{ - data: make(map[string]interface{}), - } +func (yaml *YAMLConfig) Parse(filename string) (y config.ConfigContainer, err error) { cnf, err := ReadYmlReader(filename) if err != nil { - return nil, err + return } - y.data = cnf - return y, nil + y = &YAMLConfigContainer{ + data: cnf, + } + return } // Read yaml file to map. // if json like, use json package, unless goyaml2 package. func ReadYmlReader(path string) (cnf map[string]interface{}, err error) { - err = nil f, err := os.Open(path) if err != nil { return } defer f.Close() - err = nil + buf, err := ioutil.ReadAll(f) if err != nil || len(buf) < 3 { return } if string(buf[0:1]) == "{" { - log.Println("Look lile a Json, try it") + log.Println("Look like a Json, try json umarshal") err = json.Unmarshal(buf, &cnf) if err == nil { log.Println("It is Json Map") @@ -64,19 +61,19 @@ func ReadYmlReader(path string) (cnf map[string]interface{}, err error) { } } - _map, _err := goyaml2.Read(bytes.NewBuffer(buf)) - if _err != nil { - log.Println("Goyaml2 ERR>", string(buf), _err) - //err = goyaml.Unmarshal(buf, &cnf) - err = _err + data, err := goyaml2.Read(bytes.NewBuffer(buf)) + if err != nil { + log.Println("Goyaml2 ERR>", string(buf), err) return } - if _map == nil { + + if data == nil { log.Println("Goyaml2 output nil? Pls report bug\n" + string(buf)) + return } - cnf, ok := _map.(map[string]interface{}) + cnf, ok := data.(map[string]interface{}) if !ok { - log.Println("Not a Map? >> ", string(buf), _map) + log.Println("Not a Map? >> ", string(buf), data) cnf = nil } return diff --git a/config/yaml/yaml_test.go b/config/yaml/yaml_test.go index ca066c72..d960f501 100644 --- a/config/yaml/yaml_test.go +++ b/config/yaml/yaml_test.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package config +package yaml import ( "os" From 38188098c5da845a1b19d744011760f9fc93aecf Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Thu, 17 Jul 2014 16:48:10 +0800 Subject: [PATCH 040/120] fix testing fail --- config/json.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/json.go b/config/json.go index 12b92e7d..7214a686 100644 --- a/config/json.go +++ b/config/json.go @@ -151,12 +151,12 @@ func (c *JsonConfigContainer) getData(key string) interface{} { } for _, key := range sectionKey[1:] { if v, ok := curValue.(map[string]interface{}); ok { - if v2, ok := v[key]; ok { - return v2 + if curValue, ok = v[key]; !ok { + return nil } } } - return nil + return curValue } if v, ok := c.data[key]; ok { return v From d17f107fc4bf5c09d2af70ef4a36737210dcb83a Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 18 Jul 2014 13:29:54 +0800 Subject: [PATCH 041/120] beego: fix #702 auto render --- router.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/router.go b/router.go index ba0d0b60..f66915cb 100644 --- a/router.go +++ b/router.go @@ -720,12 +720,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) } //render template - if !w.started { + if !w.started && context.Output.Status == 0 { if AutoRender { if err := execController.Render(); err != nil { panic(err) } - } } } From 91ee42ceeb9a9b6ff4f4ecfbe1258bd73dcbfe33 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 18 Jul 2014 15:38:29 +0800 Subject: [PATCH 042/120] beego:update the Abort Status --- context/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 8ef8233f..c6517e62 100644 --- a/context/context.go +++ b/context/context.go @@ -42,7 +42,7 @@ func (ctx *Context) Redirect(status int, localurl string) { // if middleware.ErrorMaps exists, panic body. // if middleware.HTTPExceptionMaps exists, panic HTTPException struct with status and body string. func (ctx *Context) Abort(status int, body string) { - ctx.Output.SetStatus(status) + ctx.ResponseWriter.WriteHeader(status) // first panic from ErrorMaps, is is user defined error functions. if _, ok := middleware.ErrorMaps[body]; ok { panic(body) From 6ce55e8884d0a2ed6f7f7f53414b6317eb3c7394 Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 22 Jul 2014 07:21:47 +0200 Subject: [PATCH 043/120] Update smtp.go (develop branch) For mail servers that do not require Authentication we must pass NIL for the SendMail parameter 2 (the auth parameter). Otherwise it fails to send the mail. --- logs/smtp.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/logs/smtp.go b/logs/smtp.go index d492a61a..fa5dc78e 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -54,6 +54,18 @@ func (s *SmtpWriter) Init(jsonconfig string) error { return nil } +func (s *SmtpWriter) GetSmtpAuth(host string) smtp.Auth { + if len(strings.Trim(s.Username, " ")) == 0 && len(strings.Trim(s.Password, " ")) == 0 { + return nil + } + return smtp.PlainAuth( + "", + s.Username, + s.Password, + host, + ) +} + // write message in smtp writer. // it will send an email with subject and only this message. func (s *SmtpWriter) WriteMsg(msg string, level int) error { @@ -64,12 +76,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { hp := strings.Split(s.Host, ":") // Set up authentication information. - auth := smtp.PlainAuth( - "", - s.Username, - s.Password, - hp[0], - ) + auth := s.GetSmtpAuth(hp[0]) + // Connect to the server, authenticate, set the sender and recipient, // and send the email all in one step. content_type := "Content-Type: text/plain" + "; charset=UTF-8" From d7090689e89eba8d44ea3bdbba796b77870ccd2a Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 24 Jul 2014 22:54:56 +0800 Subject: [PATCH 044/120] cache: change the memcache &redis driver change the memcache to the newest --- cache/memcache/memcache.go | 62 ++++++++++++++++++-------------------- cache/redis/redis.go | 2 +- cache/redis/redis_test.go | 2 +- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 2cb478b9..7e8b6a73 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -12,16 +12,17 @@ package memcache import ( "encoding/json" "errors" + "strings" - "github.com/beego/memcache" + "github.com/bradfitz/gomemcache/memcache" "github.com/astaxie/beego/cache" ) // Memcache adapter. type MemcacheCache struct { - conn *memcache.Connection - conninfo string + conn *memcache.Client + conninfo []string } // create new memcache adapter. @@ -36,10 +37,8 @@ func (rc *MemcacheCache) Get(key string) interface{} { return err } } - if v, err := rc.conn.Get(key); err == nil { - if len(v) > 0 { - return string(v[0].Value) - } + if item, err := rc.conn.Get(key); err == nil { + return string(item.Value) } return nil } @@ -55,11 +54,8 @@ func (rc *MemcacheCache) Put(key string, val interface{}, timeout int64) error { if !ok { return errors.New("val must string") } - stored, err := rc.conn.Set(key, 0, uint64(timeout), []byte(v)) - if err == nil && stored == false { - return errors.New("stored fail") - } - return err + item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout)} + return rc.conn.Set(&item) } // delete value in memcache. @@ -69,20 +65,29 @@ func (rc *MemcacheCache) Delete(key string) error { return err } } - _, err := rc.conn.Delete(key) + return rc.conn.Delete(key) +} + +// increase counter. +func (rc *MemcacheCache) Incr(key string) error { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { + return err + } + } + _, err := rc.conn.Increment(key, 1) return err } -// [Not Support] -// increase counter. -func (rc *MemcacheCache) Incr(_ string) error { - return errors.New("not support in memcache") -} - -// [Not Support] // decrease counter. -func (rc *MemcacheCache) Decr(_ string) error { - return errors.New("not support in memcache") +func (rc *MemcacheCache) Decr(key string) error { + if rc.conn == nil { + if err := rc.connectInit(); err != nil { + return err + } + } + _, err := rc.conn.Decrement(key, 1) + return err } // check value exists in memcache. @@ -92,13 +97,10 @@ func (rc *MemcacheCache) IsExist(key string) bool { return false } } - v, err := rc.conn.Get(key) + _, err := rc.conn.Get(key) if err != nil { return false } - if len(v) == 0 { - return false - } return true } @@ -121,7 +123,7 @@ func (rc *MemcacheCache) StartAndGC(config string) error { if _, ok := cf["conn"]; !ok { return errors.New("config has no conn key") } - rc.conninfo = cf["conn"] + rc.conninfo = strings.Split(cf["conn"], ";") if rc.conn == nil { if err := rc.connectInit(); err != nil { return err @@ -132,11 +134,7 @@ func (rc *MemcacheCache) StartAndGC(config string) error { // connect to memcache and keep the connection. func (rc *MemcacheCache) connectInit() error { - c, err := memcache.Connect(rc.conninfo) - if err != nil { - return err - } - rc.conn = c + rc.conn = memcache.New(rc.conninfo...) return nil } diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 1cb359e8..bd9d44c9 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -14,7 +14,7 @@ import ( "errors" "time" - "github.com/beego/redigo/redis" + "github.com/garyburd/redigo/redis" "github.com/astaxie/beego/cache" ) diff --git a/cache/redis/redis_test.go b/cache/redis/redis_test.go index de80d9f6..5128d249 100644 --- a/cache/redis/redis_test.go +++ b/cache/redis/redis_test.go @@ -14,7 +14,7 @@ import ( "testing" "time" - "github.com/beego/redigo/redis" + "github.com/garyburd/redigo/redis" "github.com/astaxie/beego/cache" ) From ee9749d64092885e0af0cba46f57b2043defe512 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 24 Jul 2014 23:12:21 +0800 Subject: [PATCH 045/120] beego:fix #685 move XsrfToken& CheckXsrfCookie to context --- context/context.go | 34 ++++++++++++++++++++++++++++++++++ controller.go | 32 +++++++------------------------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/context/context.go b/context/context.go index c6517e62..90d21c9c 100644 --- a/context/context.go +++ b/context/context.go @@ -20,6 +20,7 @@ import ( "time" "github.com/astaxie/beego/middleware" + "github.com/astaxie/beego/utils" ) // Http request context struct including BeegoInput, BeegoOutput, http.Request and http.ResponseWriter. @@ -29,6 +30,7 @@ type Context struct { Output *BeegoOutput Request *http.Request ResponseWriter http.ResponseWriter + _xsrf_token string } // Redirect does redirection to localurl with http header status code. @@ -113,3 +115,35 @@ func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interf cookie := strings.Join([]string{vs, timestamp, sig}, "|") ctx.Output.Cookie(name, cookie, others...) } + +// XsrfToken creates a xsrf token string and returns. +func (ctx *Context) XsrfToken(key string, expire int64) string { + if ctx._xsrf_token == "" { + token, ok := ctx.GetSecureCookie(key, "_xsrf") + if !ok { + token = string(utils.RandomCreateBytes(32)) + ctx.SetSecureCookie(key, "_xsrf", token, expire) + } + ctx._xsrf_token = token + } + return ctx._xsrf_token +} + +// CheckXsrfCookie checks xsrf token in this request is valid or not. +// the token can provided in request header "X-Xsrftoken" and "X-CsrfToken" +// or in form field value named as "_xsrf". +func (ctx *Context) CheckXsrfCookie() bool { + token := ctx.Input.Query("_xsrf") + if token == "" { + token = ctx.Request.Header.Get("X-Xsrftoken") + } + if token == "" { + token = ctx.Request.Header.Get("X-Csrftoken") + } + if token == "" { + ctx.Abort(403, "'_xsrf' argument missing from POST") + } else if ctx._xsrf_token != token { + ctx.Abort(403, "XSRF cookie does not match POST argument") + } + return true +} diff --git a/controller.go b/controller.go index f486bc36..782d8731 100644 --- a/controller.go +++ b/controller.go @@ -25,7 +25,6 @@ import ( "github.com/astaxie/beego/context" "github.com/astaxie/beego/session" - "github.com/astaxie/beego/utils" ) //commonly used mime-types @@ -477,18 +476,13 @@ func (c *Controller) SetSecureCookie(Secret, name, value string, others ...inter // XsrfToken creates a xsrf token string and returns. func (c *Controller) XsrfToken() string { if c._xsrf_token == "" { - token, ok := c.GetSecureCookie(XSRFKEY, "_xsrf") - if !ok { - var expire int64 - if c.XSRFExpire > 0 { - expire = int64(c.XSRFExpire) - } else { - expire = int64(XSRFExpire) - } - token = string(utils.RandomCreateBytes(32)) - c.SetSecureCookie(XSRFKEY, "_xsrf", token, expire) + var expire int64 + if c.XSRFExpire > 0 { + expire = int64(c.XSRFExpire) + } else { + expire = int64(XSRFExpire) } - c._xsrf_token = token + c._xsrf_token = c.Ctx.XsrfToken(XSRFKEY, expire) } return c._xsrf_token } @@ -500,19 +494,7 @@ func (c *Controller) CheckXsrfCookie() bool { if !c.EnableXSRF { return true } - token := c.GetString("_xsrf") - if token == "" { - token = c.Ctx.Request.Header.Get("X-Xsrftoken") - } - if token == "" { - token = c.Ctx.Request.Header.Get("X-Csrftoken") - } - if token == "" { - c.Ctx.Abort(403, "'_xsrf' argument missing from POST") - } else if c._xsrf_token != token { - c.Ctx.Abort(403, "XSRF cookie does not match POST argument") - } - return true + return c.Ctx.CheckXsrfCookie() } // XsrfFormHtml writes an input field contains xsrf token value. From e7fcb824c1c9de556f29f922b1a49dff2309668e Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 26 Jul 2014 23:25:51 +0800 Subject: [PATCH 046/120] utils: fix the safemap Items --- utils/safemap.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/safemap.go b/utils/safemap.go index 27c63eba..e99aceee 100644 --- a/utils/safemap.go +++ b/utils/safemap.go @@ -72,5 +72,9 @@ func (m *BeeMap) Delete(k interface{}) { func (m *BeeMap) Items() map[interface{}]interface{} { m.lock.RLock() defer m.lock.RUnlock() - return m.bm + r := make(map[interface{}]interface{}) + for k, v := range m.bm { + r[k] = v + } + return r } From 7ddd20340bfdb07e530656276b7370ceead3c318 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 26 Jul 2014 23:25:59 +0800 Subject: [PATCH 047/120] orm: delete the old docs --- orm/docs/zh/Cmd.md | 43 ---- orm/docs/zh/CustomFields.md | 38 ---- orm/docs/zh/Models.md | 288 ------------------------- orm/docs/zh/Models.sql | 83 -------- orm/docs/zh/Object.md | 59 ------ orm/docs/zh/Orm.md | 316 --------------------------- orm/docs/zh/Query.md | 411 ------------------------------------ orm/docs/zh/README.md | 40 ---- orm/docs/zh/Raw.md | 116 ---------- orm/docs/zh/Test.md | 34 --- orm/docs/zh/Transaction.md | 17 -- 11 files changed, 1445 deletions(-) delete mode 100644 orm/docs/zh/Cmd.md delete mode 100644 orm/docs/zh/CustomFields.md delete mode 100644 orm/docs/zh/Models.md delete mode 100644 orm/docs/zh/Models.sql delete mode 100644 orm/docs/zh/Object.md delete mode 100644 orm/docs/zh/Orm.md delete mode 100644 orm/docs/zh/Query.md delete mode 100644 orm/docs/zh/README.md delete mode 100644 orm/docs/zh/Raw.md delete mode 100644 orm/docs/zh/Test.md delete mode 100644 orm/docs/zh/Transaction.md diff --git a/orm/docs/zh/Cmd.md b/orm/docs/zh/Cmd.md deleted file mode 100644 index 932cb1c6..00000000 --- a/orm/docs/zh/Cmd.md +++ /dev/null @@ -1,43 +0,0 @@ -## 命令模式 - -注册模型与数据库以后,调用 RunCommand 执行 orm 命令 - -```go -func main() { - // orm.RegisterModel... - // orm.RegisterDataBase... - ... - orm.RunCommand() -} -``` - -```bash -go build main.go -./main orm -# 直接执行可以显示帮助 -# 如果你的程序可以支持的话,直接运行 go run main.go orm 也是一样的效果 -``` - -## 自动建表 - -```bash -./main orm syncdb -h -Usage of orm command: syncdb: - -db="default": DataBase alias name - -force=false: drop tables before create - -v=false: verbose info -``` - -使用 `-force=1` 可以 drop table 后再建表 - -使用 `-v` 可以查看执行的 sql 语句 - -## 打印建表SQL - -```bash -./main orm sqlall -h -Usage of orm command: syncdb: - -db="default": DataBase alias name -``` - -默认使用别名为 default 的数据库 diff --git a/orm/docs/zh/CustomFields.md b/orm/docs/zh/CustomFields.md deleted file mode 100644 index 3a3c835c..00000000 --- a/orm/docs/zh/CustomFields.md +++ /dev/null @@ -1,38 +0,0 @@ -## Custom Fields - - TypeBooleanField = 1 << iota - - // string - TypeCharField - - // string - TypeTextField - - // time.Time - TypeDateField - // time.Time - TypeDateTimeField - - // int16 - TypeSmallIntegerField - // int32 - TypeIntegerField - // int64 - TypeBigIntegerField - // uint16 - TypePositiveSmallIntegerField - // uint32 - TypePositiveIntegerField - // uint64 - TypePositiveBigIntegerField - - // float64 - TypeFloatField - // float64 - TypeDecimalField - - RelForeignKey - RelOneToOne - RelManyToMany - RelReverseOne - RelReverseMany \ No newline at end of file diff --git a/orm/docs/zh/Models.md b/orm/docs/zh/Models.md deleted file mode 100644 index c8263822..00000000 --- a/orm/docs/zh/Models.md +++ /dev/null @@ -1,288 +0,0 @@ -## 模型定义 - -复杂的模型定义不是必须的,此功能用作数据库数据转换和[自动建表](Cmd.md#自动建表) - -默认的表名使用驼峰转蛇形,比如 AuthUser -> auth_user - -**自定义表名** - -```go -type User struct { - Id int - Name string -} - -func (u *User) TableName() string { - return "auth_user" -} -``` - -如果[前缀设置](Orm.md#registermodelwithprefix)为`prefix_`那么表名为:prefix_auth_user - -## Struct Tag 设置参数 -```go -orm:"null;rel(fk)" -``` - -多个设置间使用 `;` 分隔,设置的值如果是多个,使用 `,` 分隔。 - -#### 忽略字段 - -设置 `-` 即可忽略 struct 中的字段 - -```go -type User struct { -... - AnyField string `orm:"-"` -... -``` - -#### auto - -当 Field 类型为 int, int32, int64 时,可以设置字段为自增健 - -当模型定义里没有主键时,符合上述类型且名称为 `Id` 的 Field 将被视为自增健。 - -#### pk - -设置为主键,适用于自定义其他类型为主键 - -#### null - -数据库表默认为 `NOT NULL`,设置 null 代表 `ALLOW NULL` - -#### blank - -设置 string 类型的字段允许为空,否则 clean 会返回错误 - -#### index - -为字段增加索引 - -#### unique - -为字段增加 unique 键 - -#### column - -为字段设置 db 字段的名称 -```go -Name `orm:"column(user_name)"` -``` -#### default - -为字段设置默认值,类型必须符合 -```go -type User struct { - ... - Status int `orm:"default(1)"` -``` -#### size - -string 类型字段默认为 varchar(255) - -设置 size 以后,db type 将使用 varchar(size) - -```go -Title string `orm:"size(60)"` -``` -#### digits / decimals - -设置 float32, float64 类型的浮点精度 -```go -Money float64 `orm:"digits(12);decimals(4)"` -``` -总长度 12 小数点后 4 位 eg: `99999999.9999` - -#### auto_now / auto_now_add -```go -Created time.Time `auto_now_add` -Updated time.Time `auto_now` -``` -* auto_now 每次 model 保存时都会对时间自动更新 -* auto_now_add 第一次保存时才设置时间 - -对于批量的 update 此设置是不生效的 - -#### type - -设置为 date 时,time.Time 字段的对应 db 类型使用 date - -```go -Created time.Time `orm:"auto_now_add;type(date)"` -``` - -设置为 text 时,string 字段对应的 db 类型使用 text - -```go -Content string `orm:"type(text)"` -``` - -## 表关系设置 - -#### rel / reverse - -**RelOneToOne**: -```go -type User struct { - ... - Profile *Profile `orm:"null;rel(one);on_delete(set_null)"` -``` -对应的反向关系 **RelReverseOne**: -```go -type Profile struct { - ... - User *User `orm:"reverse(one)" json:"-"` -``` -**RelForeignKey**: -```go -type Post struct { - ... - User*User `orm:"rel(fk)"` // RelForeignKey relation -``` -对应的反向关系 **RelReverseMany**: -```go -type User struct { - ... - Posts []*Post `orm:"reverse(many)" json:"-"` // fk 的反向关系 -``` -**RelManyToMany**: -```go -type Post struct { - ... - Tags []*Tag `orm:"rel(m2m)"` // ManyToMany relation -``` -对应的反向关系 **RelReverseMany**: -```go -type Tag struct { - ... - Posts []*Post `orm:"reverse(many)" json:"-"` -``` -#### rel_table / rel_through - -此设置针对 `orm:"rel(m2m)"` 的关系字段 - - rel_table 设置自动生成的 m2m 关系表的名称 - rel_through 如果要在 m2m 关系中使用自定义的 m2m 关系表 - 通过这个设置其名称,格式为 pkg.path.ModelName - eg: app.models.PostTagRel - PostTagRel 表需要有到 Post 和 Tag 的关系 - -当设置 rel_table 时会忽略 rel_through - -#### on_delete - -设置对应的 rel 关系删除时,如何处理关系字段。 - - cascade 级联删除(默认值) - set_null 设置为 NULL,需要设置 null = true - set_default 设置为默认值,需要设置 default 值 - do_nothing 什么也不做,忽略 - -```go -type User struct { - ... - Profile *Profile `orm:"null;rel(one);on_delete(set_null)"` -... -type Profile struct { - ... - User *User `orm:"reverse(one)" json:"-"` - -// 删除 Profile 时将设置 User.Profile 的数据库字段为 NULL -``` - - -## 模型字段与数据库类型的对应 - -在此列出 orm 推荐的对应数据库类型,自动建表功能也会以此为标准。 - -默认所有的字段都是 **NOT NULL** - -#### MySQL - -| go |mysql -| :--- | :--- -| int, int32, int64 - 设置 auto 或者名称为 `Id` 时 | integer AUTO_INCREMENT -| bool | bool -| string - 默认为 size 255 | varchar(size) -| string - 设置 type(text) 时 | longtext -| time.Time - 设置 type 为 date 时 | date -| time.TIme | datetime -| byte | tinyint unsigned -| rune | integer -| int | integer -| int8 | tinyint -| int16 | smallint -| int32 | integer -| int64 | bigint -| uint | integer unsigned -| uint8 | tinyint unsigned -| uint16 | smallint unsigned -| uint32 | integer unsigned -| uint64 | bigint unsigned -| float32 | double precision -| float64 | double precision -| float64 - 设置 digits, decimals 时 | numeric(digits, decimals) - -#### Sqlite3 - -| go | sqlite3 -| :--- | :--- -| int, int32, int64 - 设置 auto 或者名称为 `Id` 时 | integer AUTOINCREMENT -| bool | bool -| string - 默认为 size 255 | varchar(size) -| string - 设置 type(text) 时 | text -| time.Time - 设置 type 为 date 时 | date -| time.TIme | datetime -| byte | tinyint unsigned -| rune | integer -| int | integer -| int8 | tinyint -| int16 | smallint -| int32 | integer -| int64 | bigint -| uint | integer unsigned -| uint8 | tinyint unsigned -| uint16 | smallint unsigned -| uint32 | integer unsigned -| uint64 | bigint unsigned -| float32 | real -| float64 | real -| float64 - 设置 digits, decimals 时 | decimal - -#### PostgreSQL - -| go | postgres -| :--- | :--- -| int, int32, int64 - 设置 auto 或者名称为 `Id` 时 | serial -| bool | bool -| string - 默认为 size 255 | varchar(size) -| string - 设置 type(text) 时 | text -| time.Time - 设置 type 为 date 时 | date -| time.TIme | timestamp with time zone -| byte | smallint CHECK("column" >= 0 AND "column" <= 255) -| rune | integer -| int | integer -| int8 | smallint CHECK("column" >= -127 AND "column" <= 128) -| int16 | smallint -| int32 | integer -| int64 | bigint -| uint | bigint CHECK("column" >= 0) -| uint8 | smallint CHECK("column" >= 0 AND "column" <= 255) -| uint16 | integer CHECK("column" >= 0) -| uint32 | bigint CHECK("column" >= 0) -| uint64 | bigint CHECK("column" >= 0) -| float32 | double precision -| float64 | double precision -| float64 - 设置 digits, decimals 时 | numeric(digits, decimals) - - -## 关系型字段 - -其字段类型取决于对应的主键。 - -* RelForeignKey -* RelOneToOne -* RelManyToMany -* RelReverseOne -* RelReverseMany \ No newline at end of file diff --git a/orm/docs/zh/Models.sql b/orm/docs/zh/Models.sql deleted file mode 100644 index 2d9d5ce0..00000000 --- a/orm/docs/zh/Models.sql +++ /dev/null @@ -1,83 +0,0 @@ -SET NAMES utf8; -SET FOREIGN_KEY_CHECKS = 0; - --- ---------------------------- --- Table structure for `comment` --- ---------------------------- -DROP TABLE IF EXISTS `comment`; -CREATE TABLE `comment` ( - `id` int(11) NOT NULL, - `post_id` bigint(200) NOT NULL, - `content` longtext NOT NULL, - `parent_id` int(11) DEFAULT NULL, - `status` smallint(4) NOT NULL, - `created` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Table structure for `post` --- ---------------------------- -DROP TABLE IF EXISTS `post`; -CREATE TABLE `post` ( - `id` int(11) NOT NULL, - `user_id` int(11) NOT NULL, - `title` varchar(60) NOT NULL, - `content` longtext NOT NULL, - `created` datetime NOT NULL, - `updated` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Table structure for `post_tag_rel` --- ---------------------------- -DROP TABLE IF EXISTS `post_tag_rel`; -CREATE TABLE `post_tag_rel` ( - `id` int(11) NOT NULL, - `post_id` int(11) NOT NULL, - `tag_id` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Table structure for `tag` --- ---------------------------- -DROP TABLE IF EXISTS `tag`; -CREATE TABLE `tag` ( - `id` int(11) NOT NULL, - `name` varchar(30) NOT NULL, - `status` smallint(4) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Table structure for `user` --- ---------------------------- -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `user_name` varchar(30) NOT NULL, - `email` varchar(100) NOT NULL, - `password` varchar(30) NOT NULL, - `status` smallint(4) NOT NULL, - `is_staff` tinyint(1) NOT NULL, - `is_active` tinyint(1) NOT NULL, - `created` date NOT NULL, - `updated` datetime NOT NULL, - `profile_id` int(11) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Table structure for `profile` --- ---------------------------- -DROP TABLE IF EXISTS `profile`; -CREATE TABLE `profile` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `age` smallint(4) NOT NULL, - `money` double NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -SET FOREIGN_KEY_CHECKS = 1; diff --git a/orm/docs/zh/Object.md b/orm/docs/zh/Object.md deleted file mode 100644 index f1a2e0e1..00000000 --- a/orm/docs/zh/Object.md +++ /dev/null @@ -1,59 +0,0 @@ -## 对象的CRUD操作 - -对 object 操作简单的三个方法 Read / Insert / Update / Delete -```go -o := orm.NewOrm() -user := new(User) -user.Name = "slene" - -fmt.Println(o.Insert(user)) - -user.Name = "Your" -fmt.Println(o.Update(user)) -fmt.Println(o.Read(user)) -fmt.Println(o.Delete(user)) -``` -### Read -```go -o := orm.NewOrm() -user := User{Id: 1} - -err = o.Read(&user) - -if err == sql.ErrNoRows { - fmt.Println("查询不到") -} else if err == orm.ErrMissPK { - fmt.Println("找不到主键") -} else { - fmt.Println(user.Id, user.Name) -} -``` -### Insert -```go -o := orm.NewOrm() -var user User -user.Name = "slene" -user.IsActive = true - -fmt.Println(o.Insert(&user)) -fmt.Println(user.Id) -``` -创建后会自动对 auto 的 field 赋值 - -### Update -```go -o := orm.NewOrm() -user := User{Id: 1} -if o.Read(&user) == nil { - user.Name = "MyName" - o.Update(&user) -} -``` -### Delete -```go -o := orm.NewOrm() -o.Delete(&User{Id: 1}) -``` -Delete 操作会对反向关系进行操作,此例中 Post 拥有一个到 User 的外键。删除 User 的时候。如果 on_delete 设置为默认的级联操作,将删除对应的 Post - -删除以后会清除 auto field 的值 diff --git a/orm/docs/zh/Orm.md b/orm/docs/zh/Orm.md deleted file mode 100644 index 6d3b6b06..00000000 --- a/orm/docs/zh/Orm.md +++ /dev/null @@ -1,316 +0,0 @@ -## Orm 使用方法 - -beego/orm 的使用例子 - -后文例子如无特殊说明都以这个为基础。 - -##### models.go: - -```go -package main - -import ( - "github.com/astaxie/beego/orm" -) - -type User struct { - Id int - Name string - Profile *Profile `orm:"rel(one)"` // OneToOne relation -} - -type Profile struct { - Id int - Age int16 - User *User `orm:"reverse(one)"` // 设置反向关系(可选) -} - -func init() { - // 需要在init中注册定义的model - orm.RegisterModel(new(User), new(Profile)) -} -``` - -##### main.go - -```go -package main - -import ( - "fmt" - "github.com/astaxie/beego/orm" - _ "github.com/go-sql-driver/mysql" -) - -func init() { - orm.RegisterDriver("mysql", orm.DR_MySQL) - - orm.RegisterDataBase("default", "mysql", "root:root@/orm_test?charset=utf8", 30) -} - -func main() { - o := orm.NewOrm() - o.Using("default") // 默认使用 default,你可以指定为其他数据库 - - profile := new(Profile) - profile.Age = 30 - - user := new(User) - user.Profile = profile - user.Name = "slene" - - fmt.Println(o.Insert(profile)) - fmt.Println(o.Insert(user)) -} -``` - -## 数据库的设置 - -目前 orm 支持三种数据库,以下为测试过的 driver - -将你需要使用的 driver 加入 import 中 - -```go -import ( - _ "github.com/go-sql-driver/mysql" - _ "github.com/lib/pq" - _ "github.com/mattn/go-sqlite3" -) -``` - -#### RegisterDriver - -三种默认数据库类型 - -```go -orm.DR_MySQL -orm.DR_Sqlite -orm.DR_Postgres -``` - -```go -// 参数1 driverName -// 参数2 数据库类型 -// 这个用来设置 driverName 对应的数据库类型 -// mysql / sqlite3 / postgres 这三种是默认已经注册过的,所以可以无需设置 -orm.RegisterDriver("mymysql", orm.DR_MySQL) -``` - -#### RegisterDataBase - -orm 必须注册一个别名为 `default` 的数据库,作为默认使用。 - -```go -// 参数1 数据库的别名,用来在orm中切换数据库使用 -// 参数2 driverName -// 参数3 对应的链接字符串 -// 参数4 设置最大的空闲连接数,使用 golang 自己的连接池 -orm.RegisterDataBase("default", "mysql", "root:root@/orm_test?charset=utf8", 30) -``` - -#### 时区设置 - -orm 默认使用 time.Local 本地时区 - -* 作用于 orm 自动创建的时间 -* 从数据库中取回的时间转换成 orm 本地时间 - -如果需要的话,你也可以进行更改 - -```go -// 设置为 UTC 时间 -orm.DefaultTimeLoc = time.UTC -``` - -orm 在进行 RegisterDataBase 的同时,会获取数据库使用的时区,然后在 time.Time 类型存取的时做相应转换,以匹配时间系统,从而保证时间不会出错。 - -**注意:** 鉴于 Sqlite3 的设计,存取默认都为 UTC 时间 - -## 注册模型 - -如果使用 orm.QuerySeter 进行高级查询的话,这个是必须的。 - -反之,如果只使用 Raw 查询和 map struct,是无需这一步的。您可以去查看 [Raw SQL 查询](Raw.md) - -#### RegisterModel - -将你定义的 Model 进行注册,最佳设计是有单独的 models.go 文件,在他的 init 函数中进行注册。 - - -迷你版 models.go -```go -package main - -import "github.com/astaxie/beego/orm" - -type User struct { - Id int - Name string -} - -func init(){ - orm.RegisterModel(new(User)) -} -``` - -RegisterModel 也可以同时注册多个 model - -```go -orm.RegisterModel(new(User), new(Profile), new(Post)) -``` - -详细的 struct 定义请查看文档 [模型定义](Models.md) - -#### RegisterModelWithPrefix - -使用表名前缀 - -```go -orm.RegisterModelWithPrefix("prefix_", new(User)) -``` - -创建后的表名为 prefix_user - -## ORM 接口使用 - -使用 orm 必然接触的 Ormer 接口,我们来熟悉一下 - -```go -var o Ormer -o = orm.NewOrm() // 创建一个 Ormer -// NewOrm 的同时会执行 orm.BootStrap (整个 app 只执行一次),用以验证模型之间的定义并缓存。 -``` - -* type Ormer interface { - * [Read(Modeler) error](Object.md#read) - * [Insert(Modeler) (int64, error)](Object.md#insert) - * [Update(Modeler) (int64, error)](Object.md#update) - * [Delete(Modeler) (int64, error)](Object.md#delete) - * [M2mAdd(Modeler, string, ...interface{}) (int64, error)](Object.md#m2madd) - * [M2mDel(Modeler, string, ...interface{}) (int64, error)](Object.md#m2mdel) - * [LoadRel(Modeler, string) (int64, error)](Object.md#loadRel) - * [QueryTable(interface{}) QuerySeter](#querytable) - * [Using(string) error](#using) - * [Begin() error](Transaction.md) - * [Commit() error](Transaction.md) - * [Rollback() error](Transaction.md) - * [Raw(string, ...interface{}) RawSeter](#raw) - * [Driver() Driver](#driver) -* } - - -#### QueryTable - -传入表名,或者 Modeler 对象,返回一个 [QuerySeter](Query.md#queryseter) - -```go -o := orm.NewOrm() -var qs QuerySeter -qs = o.QueryTable("user") -// 如果表没有定义过,会立刻 panic -``` - -#### Using - -切换为其他数据库 - -```go -orm.RegisterDataBase("db1", "mysql", "root:root@/orm_db2?charset=utf8", 30) -orm.RegisterDataBase("db2", "sqlite3", "data.db", 30) - -o1 := orm.NewOrm() -o1.Using("db1") - -o2 := orm.NewOrm() -o2.Using("db2") - -// 切换为其他数据库以后 -// 这个 Ormer 对象的其下的 api 调用都将使用这个数据库 - -``` - -默认使用 `default` 数据库,无需调用 Using - -#### Raw - -使用 sql 语句直接进行操作 - -Raw 函数,返回一个 [RawSeter](Raw.md) 用以对设置的 sql 语句和参数进行操作 - -```go -o := NewOrm() -var r RawSeter -r = o.Raw("UPDATE user SET name = ? WHERE name = ?", "testing", "slene") -``` - -#### Driver - -返回当前 orm 使用的 db 信息 - -```go -type Driver interface { - Name() string - Type() DriverType -} -``` - -```go -orm.RegisterDataBase("db1", "mysql", "root:root@/orm_db2?charset=utf8", 30) -orm.RegisterDataBase("db2", "sqlite3", "data.db", 30) - -o1 := orm.NewOrm() -o1.Using("db1") -dr := o1.Driver() -fmt.Println(dr.Name() == "db1") // true -fmt.Println(dr.Type() == orm.DR_MySQL) // true - -o2 := orm.NewOrm() -o2.Using("db2") -dr = o2.Driver() -fmt.Println(dr.Name() == "db2") // true -fmt.Println(dr.Type() == orm.DR_Sqlite) // true - -``` - -## 调试模式打印查询语句 - -简单的设置 Debug 为 true 打印查询的语句 - -可能存在性能问题,不建议使用在产品模式 - -```go -func main() { - orm.Debug = true -... -``` - -默认使用 os.Stderr 输出日志信息 - -改变输出到你自己的 io.Writer - -```go -var w io.Writer -... -// 设置为你的 io.Writer -... -orm.DebugLog = orm.NewLog(w) -``` - -日志格式 - -```go -[ORM] - 时间 - [Queries/数据库名] - [执行操作/执行时间] - [SQL语句] - 使用标点 `,` 分隔的参数列表 - 打印遇到的错误 -``` - -```go -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.4ms] - [INSERT INTO `user` (`name`) VALUES (?)] - `slene` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.5ms] - [UPDATE `user` SET `name` = ? WHERE `id` = ?] - `astaxie`, `14` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [db.QueryRow / 0.4ms] - [SELECT `id`, `name` FROM `user` WHERE `id` = ?] - `14` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.4ms] - [INSERT INTO `post` (`user_id`,`title`,`content`) VALUES (?, ?, ?)] - `14`, `beego orm`, `powerful amazing` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Query / 0.4ms] - [SELECT T1.`name` `User__Name`, T0.`user_id` `User`, T1.`id` `User__Id` FROM `post` T0 INNER JOIN `user` T1 ON T1.`id` = T0.`user_id` WHERE T0.`id` = ? LIMIT 1000] - `68` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.4ms] - [DELETE FROM `user` WHERE `id` = ?] - `14` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Query / 0.3ms] - [SELECT T0.`id` FROM `post` T0 WHERE T0.`user_id` IN (?) ] - `14` -[ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.4ms] - [DELETE FROM `post` WHERE `id` IN (?)] - `68` -``` - -日志内容包括 **所有的数据库操作**,事务,Prepare,等 diff --git a/orm/docs/zh/Query.md b/orm/docs/zh/Query.md deleted file mode 100644 index cfc4073c..00000000 --- a/orm/docs/zh/Query.md +++ /dev/null @@ -1,411 +0,0 @@ -## 高级查询 - -orm 以 **QuerySeter** 来组织查询,每个返回 **QuerySeter** 的方法都会获得一个新的 **QuerySeter** 对象。 - -基本使用方法: -```go -o := orm.NewOrm() - -// 获取 QuerySeter 对象,user 为表名 -qs := o.QueryTable("user") - -// 也可以直接使用对象作为表名 -user := new(User) -qs = o.QueryTable(user) // 返回 QuerySeter -``` -## expr - -QuerySeter 中用于描述字段和 sql 操作符,使用简单的 expr 查询方法 - -字段组合的前后顺序依照表的关系,比如 User 表拥有 Profile 的外键,那么对 User 表查询对应的 Profile.Age 为条件,则使用 `Profile__Age` 注意,字段的分隔符号使用双下划线 `__`,除了描述字段, expr 的尾部可以增加操作符以执行对应的 sql 操作。比如 `Profile__Age__gt` 代表 Profile.Age > 18 的条件查询。 - -注释后面将描述对应的 sql 语句,仅仅是描述 expr 的类似结果,并不代表实际生成的语句。 -```go -qs.Filter("id", 1) // WHERE id = 1 -qs.Filter("profile__age", 18) // WHERE profile.age = 18 -qs.Filter("Profile__Age", 18) // 使用字段名和Field名都是允许的 -qs.Filter("profile__age", 18) // WHERE profile.age = 18 -qs.Filter("profile__age__gt", 18) // WHERE profile.age > 18 -qs.Filter("profile__age__gte", 18) // WHERE profile.age >= 18 -qs.Filter("profile__age__in", 18, 20) // WHERE profile.age IN (18, 20) - -qs.Filter("profile__age__in", 18, 20).Exclude("profile__lt", 1000) -// WHERE profile.age IN (18, 20) AND NOT profile_id < 1000 -``` -## Operators - -当前支持的操作符号: - -* [exact](#exact) / [iexact](#iexact) 等于 -* [contains](#contains) / [icontains](#icontains) 包含 -* [gt / gte](#gt / gte) 大于 / 大于等于 -* [lt / lte](#lt / lte) 小于 / 小于等于 -* [startswith](#startswith) / [istartswith](#istartswith) 以...起始 -* [endswith](#endswith) / [iendswith](#iendswith) 以...结束 -* [in](#in) -* [isnull](#isnull) - -后面以 `i` 开头的表示:大小写不敏感 - -#### exact - -Filter / Exclude / Condition expr 的默认值 -```go -qs.Filter("name", "slene") // WHERE name = 'slene' -qs.Filter("name__exact", "slene") // WHERE name = 'slene' -// 使用 = 匹配,大小写是否敏感取决于数据表使用的 collation -qs.Filter("profile", nil) // WHERE profile_id IS NULL -``` -#### iexact -```go -qs.Filter("name__iexact", "slene") -// WHERE name LIKE 'slene' -// 大小写不敏感,匹配任意 'Slene' 'sLENE' -``` -#### contains -```go -qs.Filter("name__contains", "slene") -// WHERE name LIKE BINARY '%slene%' -// 大小写敏感, 匹配包含 slene 的字符 -``` -#### icontains -```go -qs.Filter("name__icontains", "slene") -// WHERE name LIKE '%slene%' -// 大小写不敏感, 匹配任意 'im Slene', 'im sLENE' -``` -#### in -```go -qs.Filter("profile__age__in", 17, 18, 19, 20) -// WHERE profile.age IN (17, 18, 19, 20) -``` -#### gt / gte -```go -qs.Filter("profile__age__gt", 17) -// WHERE profile.age > 17 - -qs.Filter("profile__age__gte", 18) -// WHERE profile.age >= 18 -``` -#### lt / lte -```go -qs.Filter("profile__age__lt", 17) -// WHERE profile.age < 17 - -qs.Filter("profile__age__lte", 18) -// WHERE profile.age <= 18 -``` -#### startswith -```go -qs.Filter("name__startswith", "slene") -// WHERE name LIKE BINARY 'slene%' -// 大小写敏感, 匹配以 'slene' 起始的字符串 -``` -#### istartswith -```go -qs.Filter("name__istartswith", "slene") -// WHERE name LIKE 'slene%' -// 大小写不敏感, 匹配任意以 'slene', 'Slene' 起始的字符串 -``` -#### endswith -```go -qs.Filter("name__endswith", "slene") -// WHERE name LIKE BINARY '%slene' -// 大小写敏感, 匹配以 'slene' 结束的字符串 -``` -#### iendswith -```go -qs.Filter("name__startswith", "slene") -// WHERE name LIKE '%slene' -// 大小写不敏感, 匹配任意以 'slene', 'Slene' 结束的字符串 -``` -#### isnull -```go -qs.Filter("profile__isnull", true) -qs.Filter("profile_id__isnull", true) -// WHERE profile_id IS NULL - -qs.Filter("profile__isnull", false) -// WHERE profile_id IS NOT NULL -``` -## 高级查询接口使用 - -QuerySeter 是高级查询使用的接口,我们来熟悉下他的接口方法 - -* type QuerySeter interface { - * [Filter(string, ...interface{}) QuerySeter](#filter) - * [Exclude(string, ...interface{}) QuerySeter](#exclude) - * [SetCond(*Condition) QuerySeter](#setcond) - * [Limit(int, ...int64) QuerySeter](#limit) - * [Offset(int64) QuerySeter](#offset) - * [OrderBy(...string) QuerySeter](#orderby) - * [RelatedSel(...interface{}) QuerySeter](#relatedsel) - * [Count() (int64, error)](#count) - * [Update(Params) (int64, error)](#update) - * [Delete() (int64, error)](#delete) - * [PrepareInsert() (Inserter, error)](#prepareinsert) - * [All(interface{}) (int64, error)](#all) - * [One(Modeler) error](#one) - * [Values(*[]Params, ...string) (int64, error)](#values) - * [ValuesList(*[]ParamsList, ...string) (int64, error)](#valueslist) - * [ValuesFlat(*ParamsList, string) (int64, error)](#valuesflat) -* } - -* 每个返回 QuerySeter 的 api 调用时都会新建一个 QuerySeter,不影响之前创建的。 - -* 高级查询使用 Filter 和 Exclude 来做常用的条件查询。囊括两种清晰的过滤规则:包含, 排除 - -#### Filter - -用来过滤查询结果,起到 **包含条件** 的作用 - -多个 Filter 之间使用 `AND` 连接 -```go -qs.Filter("profile__isnull", true).Filter("name", "slene") -// WHERE profile_id IS NULL AND name = 'slene' -``` - -#### Exclude - -用来过滤查询结果,起到 **排除条件** 的作用 - -使用 `NOT` 排除条件 - -多个 Exclude 之间使用 `AND` 连接 -```go -qs.Exclude("profile__isnull", true).Filter("name", "slene") -// WHERE NOT profile_id IS NULL AND name = 'slene' -``` - -#### SetCond - -自定义条件表达式 - -```go -cond := NewCondition() -cond1 := cond.And("profile__isnull", false).AndNot("status__in", 1).Or("profile__age__gt", 2000) - -qs := orm.QueryTable("user") -qs = qs.SetCond(cond1) -// WHERE ... AND ... AND NOT ... OR ... - -cond2 := cond.AndCond(cond1).OrCond(cond.And("name", "slene")) -qs = qs.SetCond(cond2).Count() -// WHERE (... AND ... AND NOT ... OR ...) OR ( ... ) -``` - -#### Limit - -限制最大返回数据行数,第二个参数可以设置 `Offset` -```go -var DefaultRowsLimit = 1000 // orm 默认的 limit 值为 1000 - -// 默认情况下 select 查询的最大行数为 1000 -// LIMIT 1000 - -qs.Limit(10) -// LIMIT 10 - -qs.Limit(10, 20) -// LIMIT 10 OFFSET 20 - -qs.Limit(-1) -// no limit - -qs.Limit(-1, 100) -// LIMIT 18446744073709551615 OFFSET 100 -// 18446744073709551615 是 1<<64 - 1 用来指定无 limit 限制 但有 offset 偏移的情况 -``` - -#### Offset - -设置 偏移行数 -```go -qs.Offset(20) -// LIMIT 1000 OFFSET 20 -``` - -#### OrderBy - -参数使用 **expr** - -在 expr 前使用减号 `-` 表示 `DESC` 的排列 -```go -qs.OrderBy("id", "-profile__age") -// ORDER BY id ASC, profile.age DESC - -qs.OrderBy("-profile__age", "profile") -// ORDER BY profile.age DESC, profile_id ASC -``` - -#### RelatedSel - -关系查询,参数使用 **expr** -```go -var DefaultRelsDepth = 5 // 默认情况下直接调用 RelatedSel 将进行最大 5 层的关系查询 - -qs := o.QueryTable("post") - -qs.RelateSel() -// INNER JOIN user ... LEFT OUTER JOIN profile ... - -qs.RelateSel("user") -// INNER JOIN user ... -// 设置 expr 只对设置的字段进行关系查询 - -// 对设置 null 属性的 Field 将使用 LEFT OUTER JOIN -``` - -#### Count -依据当前的查询条件,返回结果行数 -```go -cnt, err := o.QueryTable("user").Count() // SELECT COUNT(*) FROM USER -fmt.Printf("Count Num: %s, %s", cnt, err) -``` - -#### Update -依据当前查询条件,进行批量更新操作 -```go -num, err := o.QueryTable("user").Filter("name", "slene").Update(orm.Params{ - "name": "astaxie", -}) -fmt.Printf("Affected Num: %s, %s", num, err) -// SET name = "astaixe" WHERE name = "slene" -``` - -#### Delete -依据当前查询条件,进行批量删除操作 -```go -num, err := o.QueryTable("user").Filter("name", "slene").Delete() -fmt.Printf("Affected Num: %s, %s", num, err) -// DELETE FROM user WHERE name = "slene" -``` - -#### PrepareInsert - -用于一次 prepare 多次 insert 插入,以提高批量插入的速度。 - -```go -var users []*User -... -qs := o.QueryTable("user") -i, _ := qs.PrepareInsert() -for _, user := range users { - id, err := i.Insert(user) - if err != nil { - ... - } -} -// PREPARE INSERT INTO user (`name`, ...) VALUES (?, ...) -// EXECUTE INSERT INTO user (`name`, ...) VALUES ("slene", ...) -// EXECUTE ... -// ... -i.Close() // 别忘记关闭 statement -``` - -#### All -返回对应的结果集对象 -```go -var users []*User -num, err := o.QueryTable("user").Filter("name", "slene").All(&users) -fmt.Printf("Returned Rows Num: %s, %s", num, err) -``` - -#### One - -尝试返回单条记录 - -```go -var user *User -err := o.QueryTable("user").Filter("name", "slene").One(&user) -if err == orm.ErrMultiRows { - // 多条的时候报错 - fmt.Printf("Returned Multi Rows Not One") -} -if err == orm.ErrNoRows { - // 没有找到记录 - fmt.Printf("Not row found") -} -``` - -#### Values -返回结果集的 key => value 值 - -key 为 Model 里的 Field name,value 的值 以 string 保存 - -```go -var maps []orm.Params -num, err := o.QueryTable("user").Values(&maps) -if err != nil { - fmt.Printf("Result Nums: %d\n", num) - for _, m := range maps { - fmt.Println(m["Id"], m["Name"]) - } -} -``` - -返回指定的 Field 数据 - -**TODO**: 暂不支持级联查询 **RelatedSel** 直接返回 Values - -但可以直接指定 expr 级联返回需要的数据 - -```go -var maps []orm.Params -num, err := o.QueryTable("user").Values(&maps, "id", "name", "profile", "profile__age") -if err != nil { - fmt.Printf("Result Nums: %d\n", num) - for _, m := range maps { - fmt.Println(m["Id"], m["Name"], m["Profile"], m["Profile__Age"]) - // map 中的数据都是展开的,没有复杂的嵌套 - } -} -``` - -#### ValuesList - -顾名思义,返回的结果集以slice存储 - -结果的排列与 Model 中定义的 Field 顺序一致 - -返回的每个元素值以 string 保存 - -```go -var lists []orm.ParamsList -num, err := o.QueryTable("user").ValuesList(&lists) -if err != nil { - fmt.Printf("Result Nums: %d\n", num) - for _, row := range lists { - fmt.Println(row) - } -} -``` - -当然也可以指定 expr 返回指定的 Field - -```go -var lists []orm.ParamsList -num, err := o.QueryTable("user").ValuesList(&lists, "name", "profile__age") -if err != nil { - fmt.Printf("Result Nums: %d\n", num) - for _, row := range lists { - fmt.Printf("Name: %s, Age: %s\m", row[0], row[1]) - } -} -``` - -#### ValuesFlat - -只返回特定的 Field 值,讲结果集展开到单个 slice 里 - -```go -var list orm.ParamsList -num, err := o.QueryTable("user").ValuesFlat(&list, "name") -if err != nil { - fmt.Printf("Result Nums: %d\n", num) - fmt.Printf("All User Names: %s", strings.Join(list, ", ") -} -``` - - - diff --git a/orm/docs/zh/README.md b/orm/docs/zh/README.md deleted file mode 100644 index e01c8cad..00000000 --- a/orm/docs/zh/README.md +++ /dev/null @@ -1,40 +0,0 @@ -最新文档请查看 beedoc - -* [中文](http://beego.me/docs/Models_Overview?lang=zh) -* [English](http://beego.me/docs/Models_Overview?lang=en) - -## 文档目录 - -1. [Orm 使用方法](Orm.md) - - [数据库的设置](Orm.md#数据库的设置) - * [驱动类型设置](Orm.md#registerdriver) - * [参数设置](Orm.md#registerdatabase) - * [时区设置](Orm.md#时区设置) - - [注册模型](Orm.md#注册模型) - - [ORM 接口使用](Orm.md#orm-接口使用) - - [调试模式打印查询语句](Orm.md#调试模式打印查询语句) -2. [对象的CRUD操作](Object.md) -3. [高级查询](Query.md) - - [使用的表达式语法](Query.md#expr) - - [支持的操作符号](Query.md#operators) - - [高级查询接口使用](Query.md#高级查询接口使用) -4. [使用SQL语句进行查询](Raw.md) -5. [事务处理](Transaction.md) -6. [模型定义](Models.md) - - [Struct Tag 设置参数](Models.md#struct-tag-设置参数) - - [表关系设置](Models.md#表关系设置) - - [模型字段与数据库类型的对应](Models.md#模型字段与数据库类型的对应) -7. [命令模式](Cmd.md) - - [自动建表](Cmd.md#自动建表) - - [打印建表SQL](Cmd.md#打印建表sql) -8. [Test ORM](Test.md) -9. Custom Fields -10. Faq - - -### 文档更新记录 - -* 2013-08-20: 这里不再更新,最新文档在 beedoc, [中文](http://beego.me/docs/Models_Overview?lang=zh) / [English](http://beego.me/docs/Models_Overview?lang=en) -* 2013-08-19: 增加[自动建表](Cmd.md#自动建表)功能 -* 2013-08-13: ORM 的 [时区设置](Orm.md#时区设置) -* 2013-08-13: [模型字段与数据库类型的对应](Models.md#模型字段与数据库类型的对应) 推荐的数据库对应使用的类型 diff --git a/orm/docs/zh/Raw.md b/orm/docs/zh/Raw.md deleted file mode 100644 index 0d571edf..00000000 --- a/orm/docs/zh/Raw.md +++ /dev/null @@ -1,116 +0,0 @@ -## 使用SQL语句进行查询 - -* 使用 Raw SQL 查询,无需使用 ORM 表定义 -* 多数据库,都可直接使用占位符号 `?`,自动转换 -* 查询时的参数,支持使用 Model Struct 和 Slice, Array - -```go -ids := []int{1, 2, 3} -p.Raw("SELECT name FROM user WHERE id IN (?, ?, ?)", ids) -``` - -创建一个 **RawSeter** - -```go -o := NewOrm() -var r RawSeter -r = o.Raw("UPDATE user SET name = ? WHERE name = ?", "testing", "slene") -``` - -* type RawSeter interface { - * [Exec() (int64, error)](#exec) - * [QueryRow(...interface{}) error](#queryrow) - * [QueryRows(...interface{}) (int64, error)](#queryrows) - * [SetArgs(...interface{}) RawSeter](#setargs) - * [Values(*[]Params) (int64, error)](#values) - * [ValuesList(*[]ParamsList) (int64, error)](#valueslist) - * [ValuesFlat(*ParamsList) (int64, error)](#valuesflat) - * [Prepare() (RawPreparer, error)](#prepare) -* } - -#### Exec - -执行sql语句 - -```go -num, err := r.Exec() -``` - -#### QueryRow - -TODO - -#### QueryRows - -TODO - -#### SetArgs - -改变 Raw(sql, args...) 中的 args 参数,返回一个新的 RawSeter - -用于单条 sql 语句,重复利用,替换参数然后执行。 - -```go -num, err := r.SetArgs("arg1", "arg2").Exec() -num, err := r.SetArgs("arg1", "arg2").Exec() -... -``` -#### Values / ValuesList / ValuesFlat - -Raw SQL 查询获得的结果集 Value 为 `string` 类型,NULL 字段的值为空 `` - -#### Values - - -返回结果集的 key => value 值 - -```go -var maps []orm.Params -num, err = o.Raw("SELECT user_name FROM user WHERE status = ?", 1).Values(&maps) -if err == nil && num > 0 { - fmt.Println(maps[0]["user_name"]) // slene -} -``` - -#### ValuesList - -返回结果集 slice - -```go -var lists []orm.ParamsList -num, err = o.Raw("SELECT user_name FROM user WHERE status = ?", 1).ValuesList(&lists) -if err == nil && num > 0 { - fmt.Println(lists[0][0]) // slene -} -``` - -#### ValuesFlat - -返回单一字段的平铺 slice 数据 - -```go -var list orm.ParamsList -num, err = o.Raw("SELECT id FROM user WHERE id < ?", 10).ValuesList(&list) -if err == nil && num > 0 { - fmt.Println(list) // []{"1","2","3",...} -} -``` - -#### Prepare - -用于一次 prepare 多次 exec,以提高批量执行的速度。 - -```go -p, err := o.Raw("UPDATE user SET name = ? WHERE name = ?").Prepare() -num, err := p.Exec("testing", "slene") -num, err = p.Exec("testing", "astaxie") -... -... -p.Close() // 别忘记关闭 statement -``` - -## FAQ - -1. 我的 app 需要支持多类型数据库,如何在使用 Raw SQL 的时候判断当前使用的数据库类型。 - -使用 Ormer 的 [Driver方法](Orm.md#driver) 可以进行判断 diff --git a/orm/docs/zh/Test.md b/orm/docs/zh/Test.md deleted file mode 100644 index c2146336..00000000 --- a/orm/docs/zh/Test.md +++ /dev/null @@ -1,34 +0,0 @@ -## Test ORM - -测试代码参见 - -```bash -models_test.go // 表定义 -orm_test.go // 测试用例 -``` - -#### MySQL -```bash -mysql -u root -e 'create database orm_test;' -export ORM_DRIVER=mysql -export ORM_SOURCE="root:@/orm_test?charset=utf8" -go test -v github.com/astaxie/beego/orm -``` - - -#### Sqlite3 -```bash -touch /path/to/orm_test.db -export ORM_DRIVER=sqlite3 -export ORM_SOURCE=/path/to/orm_test.db -go test -v github.com/astaxie/beego/orm -``` - - -#### PostgreSQL -```bash -psql -c 'create database orm_test;' -U postgres -export ORM_DRIVER=postgres -export ORM_SOURCE="user=postgres dbname=orm_test sslmode=disable" -go test -v github.com/astaxie/beego/orm -``` \ No newline at end of file diff --git a/orm/docs/zh/Transaction.md b/orm/docs/zh/Transaction.md deleted file mode 100644 index 51172c09..00000000 --- a/orm/docs/zh/Transaction.md +++ /dev/null @@ -1,17 +0,0 @@ -## 事务处理 - -orm 可以简单的进行事务操作 - -```go -o := NewOrm() -err := o.Begin() -// 事务处理过程 -... -... -// 此过程中的所有使用 o Ormer 对象的查询都在事务处理范围内 -if SomeError { - err = o.Rollback() -} else { - err = o.Commit() -} -``` From a804d242d96a6e85e9d02984accea35bd3e14ac3 Mon Sep 17 00:00:00 2001 From: stansun Date: Sun, 27 Jul 2014 07:13:17 -0400 Subject: [PATCH 048/120] revise a comment If it gets a msg from the buffer chan, it will write the message to outputs. --- logs/log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logs/log.go b/logs/log.go index bb737bfe..8e6c0308 100644 --- a/logs/log.go +++ b/logs/log.go @@ -164,7 +164,7 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) { } // start logger chan reading. -// when chan is full, write logs. +// when chan is not empty, write logs. func (bl *BeeLogger) startLogger() { for { select { From daf8b1101ff32363218efc3cd69f3d7715bab574 Mon Sep 17 00:00:00 2001 From: Kevin Fourie Date: Tue, 29 Jul 2014 15:05:04 +0200 Subject: [PATCH 049/120] Fixed docs: HasErrors is a method not a variable --- validation/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validation/README.md b/validation/README.md index 4bb5b416..e0c30df7 100644 --- a/validation/README.md +++ b/validation/README.md @@ -33,7 +33,7 @@ Direct Use: valid.Required(u.Name, "name") valid.MaxSize(u.Name, 15, "nameMax") valid.Range(u.Age, 0, 140, "age") - if valid.HasErrors { + if valid.HasErrors() { // validation does not pass // print invalid message for _, err := range valid.Errors { From 7a39a3c52ffac33e63c1272f5a7dc11e89b68500 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 1 Aug 2014 16:46:49 +0800 Subject: [PATCH 050/120] middleware: error page set the content-type --- middleware/error.go | 1 + 1 file changed, 1 insertion(+) diff --git a/middleware/error.go b/middleware/error.go index 743180cb..49ed1673 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -314,6 +314,7 @@ func Exception(errcode string, w http.ResponseWriter, r *http.Request, msg strin if err != nil { isint = 500 } + w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(isint) h(w, r) return From 0836b9e13fb1fdf45feadf69d5ab3e5829dcfb18 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 1 Aug 2014 17:03:28 +0800 Subject: [PATCH 051/120] fix #718 --- app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.go b/app.go index cc7f218e..64bafde8 100644 --- a/app.go +++ b/app.go @@ -69,6 +69,7 @@ func (app *App) Run() { if EnableHttpTLS { go func() { + time.Sleep(20 * time.Microsecond) if HttpsPort != 0 { app.Server.Addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort) } @@ -83,6 +84,7 @@ func (app *App) Run() { if EnableHttpListen { go func() { + app.Server.Addr = addr err := app.Server.ListenAndServe() if err != nil { BeeLogger.Critical("ListenAndServe: ", err) From bbd31131a4264063eada8c32849f4eaae70eca7d Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 2 Aug 2014 10:11:45 +0800 Subject: [PATCH 052/120] beego:parse judge weather the commentsRouter exist --- parser.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parser.go b/parser.go index f8818295..1356f6ae 100644 --- a/parser.go +++ b/parser.go @@ -159,6 +159,9 @@ func genRouterCode() { } func compareFile(pkgRealpath string) bool { + if !utils.FileExists(path.Join(AppPath, "routers", "commentsRouter.go")) { + return true + } if utils.FileExists(path.Join(AppPath, lastupdateFilename)) { content, err := ioutil.ReadFile(path.Join(AppPath, lastupdateFilename)) if err != nil { From 289f050c047112e7569082da0e93c7c49a86a5d4 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 2 Aug 2014 10:12:03 +0800 Subject: [PATCH 053/120] cache: fix comments the return err --- cache/cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/cache.go b/cache/cache.go index acb42043..fda5d8c3 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -17,7 +17,7 @@ import ( // Cache interface contains all behaviors for cache adapter. // usage: // cache.Register("file",cache.NewFileCache()) // this operation is run in init method of file.go. -// c := cache.NewCache("file","{....}") +// c,err := cache.NewCache("file","{....}") // c.Put("key",value,3600) // v := c.Get("key") // From 22ba252c8f5778509868136f463bc27cbe5a8906 Mon Sep 17 00:00:00 2001 From: Stan Sun Date: Sat, 2 Aug 2014 17:54:57 +0800 Subject: [PATCH 054/120] fix the comment of SliceIntersect The implementations of SliceDiff and SliceIntersect are the same. However, the comments of them are opposite. The former is (slice1 - slice2) while the latter is (slice2- slice1) --- utils/slice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/slice.go b/utils/slice.go index 6092e79a..323c02fd 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -101,7 +101,7 @@ func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{}) { return } -// SliceIntersect returns diff slice of slice2 - slice1. +// SliceIntersect returns diff slice of slice1 - slice2. func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{}) { for _, v := range slice1 { if !InSliceIface(v, slice2) { From 474a16a7a00243c3ae5a0c224a6ee27d58e096c6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 15:31:27 +0800 Subject: [PATCH 055/120] beego: improve the static file server --- beego.go | 4 ---- router.go | 12 +++++++++++- staticfile.go | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/beego.go b/beego.go index 05737a88..8dbed61b 100644 --- a/beego.go +++ b/beego.go @@ -383,10 +383,6 @@ func initBeforeHttpRun() { middleware.AppName = AppName middleware.RegisterErrorHandler() - for u, _ := range StaticDir { - Get(u, serverStaticRouter) - Get(u+"/*", serverStaticRouter) - } if EnableDocs { Get("/docs", serverDocs) Get("/docs/*", serverDocs) diff --git a/router.go b/router.go index f66915cb..254e8cd7 100644 --- a/router.go +++ b/router.go @@ -32,7 +32,8 @@ import ( const ( // default filter execution points - BeforeRouter = iota + BeforeStatic = iota + BeforeRouter BeforeExec AfterExec FinishRouter @@ -577,6 +578,15 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) return false } + if do_filter(BeforeStatic) { + goto Admin + } + + serverStaticRouter(context) + if w.started { + goto Admin + } + // session init if SessionOn { context.Input.CruSession = GlobalSessions.SessionStart(w, r) diff --git a/staticfile.go b/staticfile.go index 7fa03b54..1881b711 100644 --- a/staticfile.go +++ b/staticfile.go @@ -22,6 +22,9 @@ import ( ) func serverStaticRouter(ctx *context.Context) { + if ctx.Input.Method() != "GET" && ctx.Input.Method() != "HEAD" { + return + } requestPath := path.Clean(ctx.Input.Request.URL.Path) for prefix, staticDir := range StaticDir { if len(prefix) == 0 { From d7a5281bda6ab38f7d9338f3f163aec2f64de0b3 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 16:21:06 +0800 Subject: [PATCH 056/120] session: support cookie domain --- beego.go | 1 + config.go | 1 + session/session.go | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/beego.go b/beego.go index 8dbed61b..c993cfe0 100644 --- a/beego.go +++ b/beego.go @@ -362,6 +362,7 @@ func initBeforeHttpRun() { `"sessionIDHashFunc":"` + SessionHashFunc + `",` + `"sessionIDHashKey":"` + SessionHashKey + `",` + `"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` + + `"domain":` + SessionDomain + `,` + `"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}` } GlobalSessions, err = session.NewManager(SessionProvider, diff --git a/config.go b/config.go index 55290cd5..98109779 100644 --- a/config.go +++ b/config.go @@ -55,6 +55,7 @@ var ( SessionHashKey string // session hash salt string. SessionCookieLifeTime int // the life time of session id in cookie. SessionAutoSetCookie bool // auto setcookie + SessionDomain string // the cookie domain default is empty UseFcgi bool MaxMemory int64 EnableGzip bool // flag of enable gzip diff --git a/session/session.go b/session/session.go index 04ecb986..35d81b6e 100644 --- a/session/session.go +++ b/session/session.go @@ -72,6 +72,7 @@ type managerConfig struct { SessionIDHashKey string `json:"sessionIDHashKey"` CookieLifeTime int `json:"cookieLifeTime"` ProviderConfig string `json:"providerConfig"` + Domain string `json:"domain"` } // Manager contains Provider and its configuration. @@ -134,7 +135,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se Value: url.QueryEscape(sid), Path: "/", HttpOnly: true, - Secure: manager.config.Secure} + Secure: manager.config.Secure, + Domain: manager.config.Domain} if manager.config.CookieLifeTime >= 0 { cookie.MaxAge = manager.config.CookieLifeTime } @@ -153,7 +155,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se Value: url.QueryEscape(sid), Path: "/", HttpOnly: true, - Secure: manager.config.Secure} + Secure: manager.config.Secure, + Domain: manager.config.Domain} if manager.config.CookieLifeTime >= 0 { cookie.MaxAge = manager.config.CookieLifeTime } @@ -208,6 +211,7 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque Path: "/", HttpOnly: true, Secure: manager.config.Secure, + Domain: manager.config.Domain, } } else { oldsid, _ := url.QueryUnescape(cookie.Value) From 885c0678ff368a5fd577c3822ffdf15b51f02965 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 16:21:34 +0800 Subject: [PATCH 057/120] move filter wrong http method --- router.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/router.go b/router.go index 254e8cd7..d24241e6 100644 --- a/router.go +++ b/router.go @@ -578,6 +578,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) return false } + // filter wrong httpmethod + if _, ok := HTTPMETHOD[r.Method]; !ok { + http.Error(w, "Method Not Allowed", 405) + goto Admin + } + + // filter for static file if do_filter(BeforeStatic) { goto Admin } @@ -595,11 +602,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) }() } - if _, ok := HTTPMETHOD[r.Method]; !ok { - http.Error(w, "Method Not Allowed", 405) - goto Admin - } - if r.Method != "GET" && r.Method != "HEAD" { if CopyRequestBody && !context.Input.IsUpload() { context.Input.CopyBody() From 1fb24aca3442415decf428369f7155cd683766c8 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 17:34:52 +0800 Subject: [PATCH 058/120] beego: commentsrouter use the workPath fix #708 --- parser.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parser.go b/parser.go index 35382741..a4ae4d17 100644 --- a/parser.go +++ b/parser.go @@ -114,7 +114,7 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat } func genRouterCode() { - os.Mkdir(path.Join(AppPath, "routers"), 0755) + os.Mkdir(path.Join(workPath, "routers"), 0755) Info("generate router from comments") var globalinfo string for k, cList := range genInfoList { @@ -148,7 +148,7 @@ func genRouterCode() { } } if globalinfo != "" { - f, err := os.Create(path.Join(AppPath, "routers", "commentsRouter.go")) + f, err := os.Create(path.Join(workPath, "routers", "commentsRouter.go")) if err != nil { panic(err) } @@ -158,8 +158,8 @@ func genRouterCode() { } func compareFile(pkgRealpath string) bool { - if utils.FileExists(path.Join(AppPath, lastupdateFilename)) { - content, err := ioutil.ReadFile(path.Join(AppPath, lastupdateFilename)) + if utils.FileExists(path.Join(workPath, lastupdateFilename)) { + content, err := ioutil.ReadFile(path.Join(workPath, lastupdateFilename)) if err != nil { return true } @@ -187,7 +187,7 @@ func savetoFile(pkgRealpath string) { if err != nil { return } - ioutil.WriteFile(path.Join(AppPath, lastupdateFilename), d, os.ModePerm) + ioutil.WriteFile(path.Join(workPath, lastupdateFilename), d, os.ModePerm) } func getpathTime(pkgRealpath string) (lastupdate int64, err error) { From 3f7ecea0890cca03fa6ed38118f58fcb8928248e Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 20:52:11 +0800 Subject: [PATCH 059/120] beego: Display function move from toolbox to utils --- {toolbox => utils}/debug.go | 2 +- {toolbox => utils}/debug_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename {toolbox => utils}/debug.go (99%) rename {toolbox => utils}/debug_test.go (97%) diff --git a/toolbox/debug.go b/utils/debug.go similarity index 99% rename from toolbox/debug.go rename to utils/debug.go index 3b0ee803..972b2c5b 100644 --- a/toolbox/debug.go +++ b/utils/debug.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package toolbox +package utils import ( "bytes" diff --git a/toolbox/debug_test.go b/utils/debug_test.go similarity index 97% rename from toolbox/debug_test.go rename to utils/debug_test.go index 08f0661f..40598551 100644 --- a/toolbox/debug_test.go +++ b/utils/debug_test.go @@ -7,7 +7,7 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie -package toolbox +package utils import ( "testing" From c0d3cc6fc5b166efbc2a053fd868b9955a9ffb4f Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 5 Aug 2014 08:55:46 +0800 Subject: [PATCH 060/120] beego: fix the domain string --- beego.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beego.go b/beego.go index c993cfe0..ffedcc68 100644 --- a/beego.go +++ b/beego.go @@ -362,7 +362,7 @@ func initBeforeHttpRun() { `"sessionIDHashFunc":"` + SessionHashFunc + `",` + `"sessionIDHashKey":"` + SessionHashKey + `",` + `"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` + - `"domain":` + SessionDomain + `,` + + `"domain":"` + SessionDomain + `",` + `"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}` } GlobalSessions, err = session.NewManager(SessionProvider, From 2c420573d4f72aae8a559ab80220a3cf6c249394 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 5 Aug 2014 08:56:04 +0800 Subject: [PATCH 061/120] fix #703 --- parser.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index 01df2c4a..0d3f6b84 100644 --- a/parser.go +++ b/parser.go @@ -65,7 +65,9 @@ func parserPkg(pkgRealpath, pkgpath string) error { for _, d := range fl.Decls { switch specDecl := d.(type) { case *ast.FuncDecl: - parserComments(specDecl.Doc, specDecl.Name.String(), fmt.Sprint(specDecl.Recv.List[0].Type.(*ast.StarExpr).X), pkgpath) + if specDecl.Recv != nil { + parserComments(specDecl.Doc, specDecl.Name.String(), fmt.Sprint(specDecl.Recv.List[0].Type.(*ast.StarExpr).X), pkgpath) + } } } } From ea6982fceaffb3e460771bc2a5c5e7f2379de9a5 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 5 Aug 2014 23:52:06 +0800 Subject: [PATCH 062/120] beego: template fund when the start> len(bt) --- templatefunc.go | 3 +++ templatefunc_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/templatefunc.go b/templatefunc.go index da1ebc56..f72017e1 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -27,6 +27,9 @@ func Substr(s string, start, length int) string { if start < 0 { start = 0 } + if start > len(bt) { + start = start % len(bt) + } var end int if (start + length) > (len(bt) - 1) { end = len(bt) diff --git a/templatefunc_test.go b/templatefunc_test.go index fabbb431..49807f12 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -25,6 +25,9 @@ func TestSubstr(t *testing.T) { if Substr(s, 0, 100) != "012345" { t.Error("should be equal") } + if Substr(s, 12, 100) != "012345" { + t.Error("should be equal") + } } func TestHtml2str(t *testing.T) { From df8c73b23ae0c3acde551b5805a99ca21d284997 Mon Sep 17 00:00:00 2001 From: Alexey Sharov Date: Thu, 7 Aug 2014 12:09:09 +0700 Subject: [PATCH 063/120] improve null pointer panic message --- .gitignore | 1 + orm/models_utils.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 482e34b1..39ae5706 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea .DS_Store *.swp *.swo diff --git a/orm/models_utils.go b/orm/models_utils.go index bf331fed..f58685d2 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -132,6 +132,9 @@ func getFieldType(val reflect.Value) (ft int, err error) { case reflect.String: ft = TypeCharField default: + if elm == nil { + panic(fmt.Errorf("%s is nil pointer, may be miss setting tag", val)) + } switch elm.Interface().(type) { case sql.NullInt64: ft = TypeBigIntegerField From 1f6c5599aaa3475cfdabeb3005c08f4d31c52eda Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 7 Aug 2014 16:30:28 +0800 Subject: [PATCH 064/120] migration: version 1 --- migration/migration.go | 187 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 migration/migration.go diff --git a/migration/migration.go b/migration/migration.go new file mode 100644 index 00000000..8cb0ce5d --- /dev/null +++ b/migration/migration.go @@ -0,0 +1,187 @@ +// Beego (http://beego.me/) +// +// @description beego is an open-source, high-performance web framework for the Go programming language. +// +// @link http://github.com/astaxie/beego for the canonical source repository +// +// @license http://github.com/astaxie/beego/blob/master/LICENSE +// +// @authors astaxie +package migration + +import ( + "errors" + "sort" + "time" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/orm" +) + +// const the data format for the bee generate migration datatype +const M_DATE_FORMAT = "20060102_150405" + +// Migrationer is an interface for all Migration struct +type Migrationer interface { + Up() + Down() + Exec() error + GetCreated() int64 +} + +var migrationMap map[string]Migrationer + +func init() { + migrationMap = make(map[string]Migrationer) +} + +// the basic type which will implement the basic type +type Migration struct { + sqls []string + Created string +} + +// implement in the Inheritance struct for upgrade +func (m *Migration) Up() { + +} + +// implement in the Inheritance struct for down +func (m *Migration) Down() { + +} + +// add sql want to execute +func (m *Migration) Sql(sql string) { + m.sqls = append(m.sqls, sql) +} + +// execute the sql already add in the sql +func (m *Migration) Exec() error { + o := orm.NewOrm() + for _, s := range m.sqls { + beego.Info("exec sql:", s) + r := o.Raw(s) + _, err := r.Exec() + if err != nil { + return err + } + } + return nil +} + +// get the unixtime from the Created +func (m *Migration) GetCreated() int64 { + t, err := time.Parse(M_DATE_FORMAT, m.Created) + if err != nil { + return 0 + } + return t.Unix() +} + +// register the Migration in the map +func Register(name string, m Migrationer) error { + if _, ok := migrationMap[name]; ok { + return errors.New("already exist name:" + name) + } + migrationMap[name] = m + return nil +} + +// upgrate the migration from lasttime +func Upgrade(lasttime int64) error { + sm := sortMap(migrationMap) + i := 0 + for _, v := range sm { + if v.created > lasttime { + beego.Info("start upgrade", v.name) + v.m.Up() + err := v.m.Exec() + if err != nil { + return err + } + beego.Info("end upgrade:", v.name) + i++ + } + } + beego.Info("total success upgrade:", i, " migration") + return nil +} + +//rollback the migration by the name +func Rollback(name string) error { + if v, ok := migrationMap[name]; ok { + beego.Info("start rollback") + v.Down() + err := v.Exec() + if err != nil { + return err + } + beego.Info("end rollback") + return nil + } else { + return errors.New("not exist the migrationMap name:" + name) + } +} + +// reset all migration +// run all migration's down function +func Reset() error { + i := 0 + for k, v := range migrationMap { + beego.Info("start reset:", k) + v.Down() + err := v.Exec() + if err != nil { + return err + } + beego.Info("end reset:", k) + } + beego.Info("total success reset:", i, " migration") + return nil +} + +// first Reset, then Upgrade +func Refresh() error { + err := Reset() + if err != nil { + return err + } + return Upgrade(0) +} + +type dataSlice []data + +type data struct { + created int64 + name string + m Migrationer +} + +// Len is part of sort.Interface. +func (d dataSlice) Len() int { + return len(d) +} + +// Swap is part of sort.Interface. +func (d dataSlice) Swap(i, j int) { + d[i], d[j] = d[j], d[i] +} + +// Less is part of sort.Interface. We use count as the value to sort by +func (d dataSlice) Less(i, j int) bool { + return d[i].created < d[j].created +} + +func sortMap(m map[string]Migrationer) dataSlice { + s := make(dataSlice, 0, len(m)) + for k, v := range m { + d := data{} + d.created = v.GetCreated() + d.name = k + d.m = v + s = append(s, d) + } + sort.Sort(s) + return s +} From 2820f630c82626286ed63348a15706f7b1cd225f Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 7 Aug 2014 17:24:21 +0800 Subject: [PATCH 065/120] config: add more method DefaultString(key string, defaultval string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same. DefaultStrings(key string, defaultval []string) []string //get string slice DefaultInt(key string, defaultval int) int DefaultInt64(key string, defaultval int64) int64 DefaultBool(key string, defaultval bool) bool DefaultFloat(key string, defaultval float64) float64 DIY(key string) (interface{}, error) GetSection(section string) (map[string]string, error) SaveConfigFile(filename string) error --- config/config.go | 19 ++++++ config/fake.go | 56 ++++++++++++++++++ config/ini.go | 137 ++++++++++++++++++++++++++++++++++++++++++++ config/json.go | 98 +++++++++++++++++++++++++++++++ config/xml/xml.go | 99 ++++++++++++++++++++++++++++++++ config/yaml/yaml.go | 94 ++++++++++++++++++++++++++++++ 6 files changed, 503 insertions(+) diff --git a/config/config.go b/config/config.go index 61e33061..744adb4b 100644 --- a/config/config.go +++ b/config/config.go @@ -22,12 +22,21 @@ type ConfigContainer interface { Int64(key string) (int64, error) Bool(key string) (bool, error) Float(key string) (float64, error) + DefaultString(key string, defaultval string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same. + DefaultStrings(key string, defaultval []string) []string //get string slice + DefaultInt(key string, defaultval int) int + DefaultInt64(key string, defaultval int64) int64 + DefaultBool(key string, defaultval bool) bool + DefaultFloat(key string, defaultval float64) float64 DIY(key string) (interface{}, error) + GetSection(section string) (map[string]string, error) + SaveConfigFile(filename string) error } // Config is the adapter interface for parsing config file to get raw data to ConfigContainer. type Config interface { Parse(key string) (ConfigContainer, error) + ParseData(data []byte) (ConfigContainer, error) } var adapters = make(map[string]Config) @@ -54,3 +63,13 @@ func NewConfig(adapterName, fileaname string) (ConfigContainer, error) { } return adapter.Parse(fileaname) } + +// adapterName is ini/json/xml/yaml. +// data is the config data. +func NewConfigData(adapterName string, data []byte) (ConfigContainer, error) { + adapter, ok := adapters[adapterName] + if !ok { + return nil, fmt.Errorf("config: unknown adaptername %q (forgotten import?)", adapterName) + } + return adapter.ParseData(data) +} diff --git a/config/fake.go b/config/fake.go index 561dccca..fec4250d 100644 --- a/config/fake.go +++ b/config/fake.go @@ -32,26 +32,74 @@ func (c *fakeConfigContainer) String(key string) string { return c.getData(key) } +func (c *fakeConfigContainer) DefaultString(key string, defaultval string) string { + if v := c.getData(key); v == "" { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) Strings(key string) []string { return strings.Split(c.getData(key), ";") } +func (c *fakeConfigContainer) DefaultStrings(key string, defaultval []string) []string { + if v := c.Strings(key); len(v) == 0 { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) Int(key string) (int, error) { return strconv.Atoi(c.getData(key)) } +func (c *fakeConfigContainer) DefaultInt(key string, defaultval int) int { + if v, err := c.Int(key); err != nil { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) Int64(key string) (int64, error) { return strconv.ParseInt(c.getData(key), 10, 64) } +func (c *fakeConfigContainer) DefaultInt64(key string, defaultval int64) int64 { + if v, err := c.Int64(key); err != nil { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) Bool(key string) (bool, error) { return strconv.ParseBool(c.getData(key)) } +func (c *fakeConfigContainer) DefaultBool(key string, defaultval bool) bool { + if v, err := c.Bool(key); err != nil { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) Float(key string) (float64, error) { return strconv.ParseFloat(c.getData(key), 64) } +func (c *fakeConfigContainer) DefaultFloat(key string, defaultval float64) float64 { + if v, err := c.Float(key); err != nil { + return defaultval + } else { + return v + } +} + func (c *fakeConfigContainer) DIY(key string) (interface{}, error) { if v, ok := c.data[strings.ToLower(key)]; ok { return v, nil @@ -59,6 +107,14 @@ func (c *fakeConfigContainer) DIY(key string) (interface{}, error) { return nil, errors.New("key not find") } +func (c *fakeConfigContainer) GetSection(section string) (map[string]string, error) { + return nil, errors.New("not implement in the fakeConfigContainer") +} + +func (c *fakeConfigContainer) SaveConfigFile(filename string) error { + return errors.New("not implement in the fakeConfigContainer") +} + var _ ConfigContainer = new(fakeConfigContainer) func NewFakeConfig() ConfigContainer { diff --git a/config/ini.go b/config/ini.go index 262f688b..1a8e1a12 100644 --- a/config/ini.go +++ b/config/ini.go @@ -13,11 +13,15 @@ import ( "bufio" "bytes" "errors" + "fmt" "io" + "io/ioutil" "os" + "path" "strconv" "strings" "sync" + "time" "unicode" ) @@ -30,6 +34,7 @@ var ( bDQuote = []byte{'"'} // quote signal sectionStart = []byte{'['} // section start signal sectionEnd = []byte{']'} // section end signal + lineBreak = "\n" ) // IniConfig implements Config to parse ini file. @@ -115,6 +120,16 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) { return cfg, nil } +func (ini *IniConfig) ParseData(data []byte) (ConfigContainer, error) { + // Save memory data to temporary file + tmpName := path.Join(os.TempDir(), "beego", fmt.Sprintf("%d", time.Now().Nanosecond())) + os.MkdirAll(path.Dir(tmpName), os.ModePerm) + if err := ioutil.WriteFile(tmpName, data, 0655); err != nil { + return nil, err + } + return ini.Parse(tmpName) +} + // A Config represents the ini configuration. // When set and get value, support key as section:name type. type IniConfigContainer struct { @@ -130,32 +145,154 @@ func (c *IniConfigContainer) Bool(key string) (bool, error) { return strconv.ParseBool(c.getdata(strings.ToLower(key))) } +// DefaultBool returns the boolean value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool { + if v, err := c.Bool(key); err != nil { + return defaultval + } else { + return v + } +} + // Int returns the integer value for a given key. func (c *IniConfigContainer) Int(key string) (int, error) { return strconv.Atoi(c.getdata(strings.ToLower(key))) } +// DefaultInt returns the integer value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int { + if v, err := c.Int(key); err != nil { + return defaultval + } else { + return v + } +} + // Int64 returns the int64 value for a given key. func (c *IniConfigContainer) Int64(key string) (int64, error) { return strconv.ParseInt(c.getdata(strings.ToLower(key)), 10, 64) } +// DefaultInt64 returns the int64 value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64 { + if v, err := c.Int64(key); err != nil { + return defaultval + } else { + return v + } +} + // Float returns the float value for a given key. func (c *IniConfigContainer) Float(key string) (float64, error) { return strconv.ParseFloat(c.getdata(strings.ToLower(key)), 64) } +// DefaultFloat returns the float64 value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float64 { + if v, err := c.Float(key); err != nil { + return defaultval + } else { + return v + } +} + // String returns the string value for a given key. func (c *IniConfigContainer) String(key string) string { key = strings.ToLower(key) return c.getdata(strings.ToLower(key)) } +// DefaultString returns the string value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultString(key string, defaultval string) string { + if v := c.String(key); v == "" { + return defaultval + } else { + return v + } +} + // Strings returns the []string value for a given key. func (c *IniConfigContainer) Strings(key string) []string { return strings.Split(c.String(key), ";") } +// DefaultStrings returns the []string value for a given key. +// if err != nil return defaltval +func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []string { + if v := c.Strings(key); len(v) == 0 { + return defaultval + } else { + return v + } +} + +// GetSection returns map for the given section +func (c *IniConfigContainer) GetSection(section string) (map[string]string, error) { + if v, ok := c.data[section]; ok { + return v, nil + } else { + return nil, errors.New("not exist setction") + } +} + +// SaveConfigFile save the config into file +func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) { + // Write configuration file by filename. + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + + buf := bytes.NewBuffer(nil) + for section, dt := range c.data { + // Write section comments. + if v, ok := c.sectionComment[section]; ok { + if _, err = buf.WriteString(string(bNumComment) + v + lineBreak); err != nil { + return err + } + } + + if section != DEFAULT_SECTION { + // Write section name. + if _, err = buf.WriteString(string(sectionStart) + section + string(sectionEnd) + lineBreak); err != nil { + return err + } + } + + for key, val := range dt { + if key != " " { + // Write key comments. + if v, ok := c.keyComment[key]; ok { + if _, err = buf.WriteString(string(bNumComment) + v + lineBreak); err != nil { + return err + } + } + + // Write key and value. + if _, err = buf.WriteString(key + string(bEqual) + val + lineBreak); err != nil { + return err + } + } + } + + // Put a line between sections. + if _, err = buf.WriteString(lineBreak); err != nil { + return err + } + } + + if _, err = buf.WriteTo(f); err != nil { + return err + } + return nil +} + // WriteValue writes a new value for key. // if write to one section, the key need be "section::key". // if the section is not existed, it panics. diff --git a/config/json.go b/config/json.go index 7214a686..0ddca1f0 100644 --- a/config/json.go +++ b/config/json.go @@ -12,10 +12,13 @@ package config import ( "encoding/json" "errors" + "fmt" "io/ioutil" "os" + "path" "strings" "sync" + "time" ) // JsonConfig is a json config parser and implements Config interface. @@ -48,6 +51,16 @@ func (js *JsonConfig) Parse(filename string) (ConfigContainer, error) { return x, nil } +func (js *JsonConfig) ParseData(data []byte) (ConfigContainer, error) { + // Save memory data to temporary file + tmpName := path.Join(os.TempDir(), "beego", fmt.Sprintf("%d", time.Now().Nanosecond())) + os.MkdirAll(path.Dir(tmpName), os.ModePerm) + if err := ioutil.WriteFile(tmpName, data, 0655); err != nil { + return nil, err + } + return js.Parse(tmpName) +} + // A Config represents the json configuration. // Only when get value, support key as section:name type. type JsonConfigContainer struct { @@ -67,6 +80,16 @@ func (c *JsonConfigContainer) Bool(key string) (bool, error) { return false, errors.New("not exist key:" + key) } +// DefaultBool return the bool value if has no error +// otherwise return the defaultval +func (c *JsonConfigContainer) DefaultBool(key string, defaultval bool) bool { + if v, err := c.Bool(key); err != nil { + return defaultval + } else { + return v + } +} + // Int returns the integer value for a given key. func (c *JsonConfigContainer) Int(key string) (int, error) { val := c.getData(key) @@ -79,6 +102,16 @@ func (c *JsonConfigContainer) Int(key string) (int, error) { return 0, errors.New("not exist key:" + key) } +// DefaultInt returns the integer value for a given key. +// if err != nil return defaltval +func (c *JsonConfigContainer) DefaultInt(key string, defaultval int) int { + if v, err := c.Int(key); err != nil { + return defaultval + } else { + return v + } +} + // Int64 returns the int64 value for a given key. func (c *JsonConfigContainer) Int64(key string) (int64, error) { val := c.getData(key) @@ -91,6 +124,16 @@ func (c *JsonConfigContainer) Int64(key string) (int64, error) { return 0, errors.New("not exist key:" + key) } +// DefaultInt64 returns the int64 value for a given key. +// if err != nil return defaltval +func (c *JsonConfigContainer) DefaultInt64(key string, defaultval int64) int64 { + if v, err := c.Int64(key); err != nil { + return defaultval + } else { + return v + } +} + // Float returns the float value for a given key. func (c *JsonConfigContainer) Float(key string) (float64, error) { val := c.getData(key) @@ -103,6 +146,16 @@ func (c *JsonConfigContainer) Float(key string) (float64, error) { return 0.0, errors.New("not exist key:" + key) } +// DefaultFloat returns the float64 value for a given key. +// if err != nil return defaltval +func (c *JsonConfigContainer) DefaultFloat(key string, defaultval float64) float64 { + if v, err := c.Float(key); err != nil { + return defaultval + } else { + return v + } +} + // String returns the string value for a given key. func (c *JsonConfigContainer) String(key string) string { val := c.getData(key) @@ -114,11 +167,56 @@ func (c *JsonConfigContainer) String(key string) string { return "" } +// DefaultString returns the string value for a given key. +// if err != nil return defaltval +func (c *JsonConfigContainer) DefaultString(key string, defaultval string) string { + if v := c.String(key); v == "" { + return defaultval + } else { + return v + } +} + // Strings returns the []string value for a given key. func (c *JsonConfigContainer) Strings(key string) []string { return strings.Split(c.String(key), ";") } +// DefaultStrings returns the []string value for a given key. +// if err != nil return defaltval +func (c *JsonConfigContainer) DefaultStrings(key string, defaultval []string) []string { + if v := c.Strings(key); len(v) == 0 { + return defaultval + } else { + return v + } +} + +// GetSection returns map for the given section +func (c *JsonConfigContainer) GetSection(section string) (map[string]string, error) { + if v, ok := c.data[section]; ok { + return v.(map[string]string), nil + } else { + return nil, errors.New("not exist setction") + } +} + +// SaveConfigFile save the config into file +func (c *JsonConfigContainer) SaveConfigFile(filename string) (err error) { + // Write configuration file by filename. + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + b, err := json.MarshalIndent(c.data, "", " ") + if err != nil { + return err + } + _, err = f.Write(b) + return err +} + // WriteValue writes a new value for key. func (c *JsonConfigContainer) Set(key, val string) error { c.Lock() diff --git a/config/xml/xml.go b/config/xml/xml.go index 5345f69c..6a8494cd 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -10,12 +10,16 @@ package xml import ( + "encoding/xml" "errors" + "fmt" "io/ioutil" "os" + "path" "strconv" "strings" "sync" + "time" "github.com/astaxie/beego/config" "github.com/beego/x2j" @@ -49,6 +53,16 @@ func (xc *XMLConfig) Parse(filename string) (config.ConfigContainer, error) { return x, nil } +func (x *XMLConfig) ParseData(data []byte) (config.ConfigContainer, error) { + // Save memory data to temporary file + tmpName := path.Join(os.TempDir(), "beego", fmt.Sprintf("%d", time.Now().Nanosecond())) + os.MkdirAll(path.Dir(tmpName), os.ModePerm) + if err := ioutil.WriteFile(tmpName, data, 0655); err != nil { + return nil, err + } + return x.Parse(tmpName) +} + // A Config represents the xml configuration. type XMLConfigContainer struct { data map[string]interface{} @@ -60,21 +74,61 @@ func (c *XMLConfigContainer) Bool(key string) (bool, error) { return strconv.ParseBool(c.data[key].(string)) } +// DefaultBool return the bool value if has no error +// otherwise return the defaultval +func (c *XMLConfigContainer) DefaultBool(key string, defaultval bool) bool { + if v, err := c.Bool(key); err != nil { + return defaultval + } else { + return v + } +} + // Int returns the integer value for a given key. func (c *XMLConfigContainer) Int(key string) (int, error) { return strconv.Atoi(c.data[key].(string)) } +// DefaultInt returns the integer value for a given key. +// if err != nil return defaltval +func (c *XMLConfigContainer) DefaultInt(key string, defaultval int) int { + if v, err := c.Int(key); err != nil { + return defaultval + } else { + return v + } +} + // Int64 returns the int64 value for a given key. func (c *XMLConfigContainer) Int64(key string) (int64, error) { return strconv.ParseInt(c.data[key].(string), 10, 64) } +// DefaultInt64 returns the int64 value for a given key. +// if err != nil return defaltval +func (c *XMLConfigContainer) DefaultInt64(key string, defaultval int64) int64 { + if v, err := c.Int64(key); err != nil { + return defaultval + } else { + return v + } +} + // Float returns the float value for a given key. func (c *XMLConfigContainer) Float(key string) (float64, error) { return strconv.ParseFloat(c.data[key].(string), 64) } +// DefaultFloat returns the float64 value for a given key. +// if err != nil return defaltval +func (c *XMLConfigContainer) DefaultFloat(key string, defaultval float64) float64 { + if v, err := c.Float(key); err != nil { + return defaultval + } else { + return v + } +} + // String returns the string value for a given key. func (c *XMLConfigContainer) String(key string) string { if v, ok := c.data[key].(string); ok { @@ -83,11 +137,56 @@ func (c *XMLConfigContainer) String(key string) string { return "" } +// DefaultString returns the string value for a given key. +// if err != nil return defaltval +func (c *XMLConfigContainer) DefaultString(key string, defaultval string) string { + if v := c.String(key); v == "" { + return defaultval + } else { + return v + } +} + // Strings returns the []string value for a given key. func (c *XMLConfigContainer) Strings(key string) []string { return strings.Split(c.String(key), ";") } +// DefaultStrings returns the []string value for a given key. +// if err != nil return defaltval +func (c *XMLConfigContainer) DefaultStrings(key string, defaultval []string) []string { + if v := c.Strings(key); len(v) == 0 { + return defaultval + } else { + return v + } +} + +// GetSection returns map for the given section +func (c *XMLConfigContainer) GetSection(section string) (map[string]string, error) { + if v, ok := c.data[section]; ok { + return v.(map[string]string), nil + } else { + return nil, errors.New("not exist setction") + } +} + +// SaveConfigFile save the config into file +func (c *XMLConfigContainer) SaveConfigFile(filename string) (err error) { + // Write configuration file by filename. + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + b, err := xml.MarshalIndent(c.data, " ", " ") + if err != nil { + return err + } + _, err = f.Write(b) + return err +} + // WriteValue writes a new value for key. func (c *XMLConfigContainer) Set(key, val string) error { c.Lock() diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index e948dae2..89244e34 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -13,11 +13,14 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io/ioutil" "log" "os" + "path" "strings" "sync" + "time" "github.com/astaxie/beego/config" "github.com/beego/goyaml2" @@ -38,6 +41,16 @@ func (yaml *YAMLConfig) Parse(filename string) (y config.ConfigContainer, err er return } +func (yaml *YAMLConfig) ParseData(data []byte) (config.ConfigContainer, error) { + // Save memory data to temporary file + tmpName := path.Join(os.TempDir(), "beego", fmt.Sprintf("%d", time.Now().Nanosecond())) + os.MkdirAll(path.Dir(tmpName), os.ModePerm) + if err := ioutil.WriteFile(tmpName, data, 0655); err != nil { + return nil, err + } + return yaml.Parse(tmpName) +} + // Read yaml file to map. // if json like, use json package, unless goyaml2 package. func ReadYmlReader(path string) (cnf map[string]interface{}, err error) { @@ -93,6 +106,16 @@ func (c *YAMLConfigContainer) Bool(key string) (bool, error) { return false, errors.New("not bool value") } +// DefaultBool return the bool value if has no error +// otherwise return the defaultval +func (c *YAMLConfigContainer) DefaultBool(key string, defaultval bool) bool { + if v, err := c.Bool(key); err != nil { + return defaultval + } else { + return v + } +} + // Int returns the integer value for a given key. func (c *YAMLConfigContainer) Int(key string) (int, error) { if v, ok := c.data[key].(int64); ok { @@ -101,6 +124,16 @@ func (c *YAMLConfigContainer) Int(key string) (int, error) { return 0, errors.New("not int value") } +// DefaultInt returns the integer value for a given key. +// if err != nil return defaltval +func (c *YAMLConfigContainer) DefaultInt(key string, defaultval int) int { + if v, err := c.Int(key); err != nil { + return defaultval + } else { + return v + } +} + // Int64 returns the int64 value for a given key. func (c *YAMLConfigContainer) Int64(key string) (int64, error) { if v, ok := c.data[key].(int64); ok { @@ -109,6 +142,16 @@ func (c *YAMLConfigContainer) Int64(key string) (int64, error) { return 0, errors.New("not bool value") } +// DefaultInt64 returns the int64 value for a given key. +// if err != nil return defaltval +func (c *YAMLConfigContainer) DefaultInt64(key string, defaultval int64) int64 { + if v, err := c.Int64(key); err != nil { + return defaultval + } else { + return v + } +} + // Float returns the float value for a given key. func (c *YAMLConfigContainer) Float(key string) (float64, error) { if v, ok := c.data[key].(float64); ok { @@ -117,6 +160,16 @@ func (c *YAMLConfigContainer) Float(key string) (float64, error) { return 0.0, errors.New("not float64 value") } +// DefaultFloat returns the float64 value for a given key. +// if err != nil return defaltval +func (c *YAMLConfigContainer) DefaultFloat(key string, defaultval float64) float64 { + if v, err := c.Float(key); err != nil { + return defaultval + } else { + return v + } +} + // String returns the string value for a given key. func (c *YAMLConfigContainer) String(key string) string { if v, ok := c.data[key].(string); ok { @@ -125,11 +178,52 @@ func (c *YAMLConfigContainer) String(key string) string { return "" } +// DefaultString returns the string value for a given key. +// if err != nil return defaltval +func (c *YAMLConfigContainer) DefaultString(key string, defaultval string) string { + if v := c.String(key); v == "" { + return defaultval + } else { + return v + } +} + // Strings returns the []string value for a given key. func (c *YAMLConfigContainer) Strings(key string) []string { return strings.Split(c.String(key), ";") } +// DefaultStrings returns the []string value for a given key. +// if err != nil return defaltval +func (c *YAMLConfigContainer) DefaultStrings(key string, defaultval []string) []string { + if v := c.Strings(key); len(v) == 0 { + return defaultval + } else { + return v + } +} + +// GetSection returns map for the given section +func (c *YAMLConfigContainer) GetSection(section string) (map[string]string, error) { + if v, ok := c.data[section]; ok { + return v.(map[string]string), nil + } else { + return nil, errors.New("not exist setction") + } +} + +// SaveConfigFile save the config into file +func (c *YAMLConfigContainer) SaveConfigFile(filename string) (err error) { + // Write configuration file by filename. + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + err = goyaml2.Write(f, c.data) + return err +} + // WriteValue writes a new value for key. func (c *YAMLConfigContainer) Set(key, val string) error { c.Lock() From b1b4dbb0e42306d51969bcaed1c40a8a037ea973 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 8 Aug 2014 12:02:44 +0800 Subject: [PATCH 066/120] fix the nil judge --- cache/README.md | 2 +- orm/models_utils.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cache/README.md b/cache/README.md index c0bfcc59..72d0d1c5 100644 --- a/cache/README.md +++ b/cache/README.md @@ -22,7 +22,7 @@ First you must import it Then init a Cache (example with memory adapter) - bm, err := NewCache("memory", `{"interval":60}`) + bm, err := cache.NewCache("memory", `{"interval":60}`) Use it like this: diff --git a/orm/models_utils.go b/orm/models_utils.go index 975210e2..e7e94a42 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -131,7 +131,7 @@ func getFieldType(val reflect.Value) (ft int, err error) { case reflect.String: ft = TypeCharField default: - if elm == nil { + if elm.IsNil() { panic(fmt.Errorf("%s is nil pointer, may be miss setting tag", val)) } switch elm.Interface().(type) { From 99c03a2b9cd545b237024f3046312eee520b279a Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 8 Aug 2014 13:16:51 +0800 Subject: [PATCH 067/120] fix the nil judge --- orm/models_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orm/models_utils.go b/orm/models_utils.go index e7e94a42..b682040b 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -131,7 +131,7 @@ func getFieldType(val reflect.Value) (ft int, err error) { case reflect.String: ft = TypeCharField default: - if elm.IsNil() { + if elm.Interface() == nil { panic(fmt.Errorf("%s is nil pointer, may be miss setting tag", val)) } switch elm.Interface().(type) { From 2773fda8833351638c51d1b75f7ea1379ecbfb0c Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 8 Aug 2014 16:43:39 +0800 Subject: [PATCH 068/120] session:change the driver from beego to bradfitz --- session/memcache/sess_memcache.go | 96 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/session/memcache/sess_memcache.go b/session/memcache/sess_memcache.go index 0175b6ba..5a1dc6b9 100644 --- a/session/memcache/sess_memcache.go +++ b/session/memcache/sess_memcache.go @@ -11,18 +11,19 @@ package session import ( "net/http" + "strings" "sync" "github.com/astaxie/beego/session" - "github.com/beego/memcache" + "github.com/bradfitz/gomemcache/memcache" ) var mempder = &MemProvider{} +var client *memcache.Client // memcache session store type MemcacheSessionStore struct { - c *memcache.Connection sid string lock sync.RWMutex values map[interface{}]interface{} @@ -71,19 +72,18 @@ func (rs *MemcacheSessionStore) SessionID() string { // save session values to redis func (rs *MemcacheSessionStore) SessionRelease(w http.ResponseWriter) { - defer rs.c.Close() - b, err := session.EncodeGob(rs.values) if err != nil { return } - rs.c.Set(rs.sid, 0, uint64(rs.maxlifetime), b) + item := memcache.Item{Key: rs.sid, Value: b, Expiration: int32(rs.maxlifetime)} + client.Set(&item) } // redis session provider type MemProvider struct { maxlifetime int64 - savePath string + conninfo []string poolsize int password string } @@ -93,46 +93,44 @@ type MemProvider struct { // e.g. 127.0.0.1:9090 func (rp *MemProvider) SessionInit(maxlifetime int64, savePath string) error { rp.maxlifetime = maxlifetime - rp.savePath = savePath + rp.conninfo = strings.Split(savePath, ";") + client = memcache.New(rp.conninfo...) return nil } // read redis session by sid func (rp *MemProvider) SessionRead(sid string) (session.SessionStore, error) { - conn, err := rp.connectInit() + if client == nil { + if err := rp.connectInit(); err != nil { + return nil, err + } + } + item, err := client.Get(sid) if err != nil { return nil, err } - kvs, err := conn.Get(sid) - if err != nil { - return nil, err - } - var contain []byte - if len(kvs) > 0 { - contain = kvs[0].Value - } var kv map[interface{}]interface{} - if len(contain) == 0 { + if len(item.Value) == 0 { kv = make(map[interface{}]interface{}) } else { - kv, err = session.DecodeGob(contain) + kv, err = session.DecodeGob(item.Value) if err != nil { return nil, err } } - rs := &MemcacheSessionStore{c: conn, sid: sid, values: kv, maxlifetime: rp.maxlifetime} + rs := &MemcacheSessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil } // check redis session exist by sid func (rp *MemProvider) SessionExist(sid string) bool { - conn, err := rp.connectInit() - if err != nil { - return false + if client == nil { + if err := rp.connectInit(); err != nil { + return false + } } - defer conn.Close() - if kvs, err := conn.Get(sid); err != nil || len(kvs) == 0 { + if item, err := client.Get(sid); err != nil || len(item.Value) == 0 { return false } else { return true @@ -141,51 +139,64 @@ func (rp *MemProvider) SessionExist(sid string) bool { // generate new sid for redis session func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, error) { - conn, err := rp.connectInit() - if err != nil { - return nil, err + if client == nil { + if err := rp.connectInit(); err != nil { + return nil, err + } } var contain []byte - if kvs, err := conn.Get(sid); err != nil || len(kvs) == 0 { + if item, err := client.Get(sid); err != nil || len(item.Value) == 0 { // oldsid doesn't exists, set the new sid directly // ignore error here, since if it return error // the existed value will be 0 - conn.Set(sid, 0, uint64(rp.maxlifetime), []byte("")) + item.Key = sid + item.Value = []byte("") + item.Expiration = int32(rp.maxlifetime) + client.Set(item) } else { - conn.Delete(oldsid) - conn.Set(sid, 0, uint64(rp.maxlifetime), kvs[0].Value) - contain = kvs[0].Value + client.Delete(oldsid) + item.Key = sid + item.Value = item.Value + item.Expiration = int32(rp.maxlifetime) + client.Set(item) + contain = item.Value } var kv map[interface{}]interface{} if len(contain) == 0 { kv = make(map[interface{}]interface{}) } else { + var err error kv, err = session.DecodeGob(contain) if err != nil { return nil, err } } - rs := &MemcacheSessionStore{c: conn, sid: sid, values: kv, maxlifetime: rp.maxlifetime} + rs := &MemcacheSessionStore{sid: sid, values: kv, maxlifetime: rp.maxlifetime} return rs, nil } // delete redis session by id func (rp *MemProvider) SessionDestroy(sid string) error { - conn, err := rp.connectInit() - if err != nil { - return err + if client == nil { + if err := rp.connectInit(); err != nil { + return err + } } - defer conn.Close() - _, err = conn.Delete(sid) + err := client.Delete(sid) if err != nil { return err } return nil } +func (rp *MemProvider) connectInit() error { + client = memcache.New(rp.conninfo...) + return nil +} + // Impelment method, no used. func (rp *MemProvider) SessionGC() { return @@ -196,15 +207,6 @@ func (rp *MemProvider) SessionAll() int { return 0 } -// connect to memcache and keep the connection. -func (rp *MemProvider) connectInit() (*memcache.Connection, error) { - c, err := memcache.Connect(rp.savePath) - if err != nil { - return nil, err - } - return c, nil -} - func init() { session.Register("memcache", mempder) } From 58ac0d5ea4e8a0a93224d4462dbca80658222df2 Mon Sep 17 00:00:00 2001 From: Francois Date: Sat, 9 Aug 2014 15:35:29 +0200 Subject: [PATCH 069/120] Update captcha.go Captcha must be deleted if the user entered a "challenge" with a different length than the captcha. --- utils/captcha/captcha.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 5354423e..27748f12 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -200,7 +200,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) { key := c.key(id) - if v, ok := c.store.Get(key).([]byte); ok && len(v) == len(challenge) { + if v, ok := c.store.Get(key).([]byte); ok { chars = v } else { return @@ -211,6 +211,9 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) { c.store.Delete(key) }() + if len(chars) != len(challenge) { + return + } // verify challenge for i, c := range chars { if c != challenge[i]-48 { @@ -221,6 +224,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) { return true } + // create a new captcha.Captcha func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha { cpt := &Captcha{} From 3d74a1a436033ca9aa176ec0096d62145c1d46e5 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 11 Aug 2014 22:13:18 +0800 Subject: [PATCH 070/120] make the getconfig public // Getconfig throw the Runmode // [dev] // name = astaixe // IsEnable = false // [prod] // name = slene // IsEnable = true // // usage: // GetConfig("string", "name") // GetConfig("bool", "IsEnable") --- config.go | 95 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/config.go b/config.go index 98109779..802365ee 100644 --- a/config.go +++ b/config.go @@ -184,147 +184,147 @@ func ParseConfig() (err error) { return err } else { - if v, err := getConfig("string", "HttpAddr"); err == nil { + if v, err := GetConfig("string", "HttpAddr"); err == nil { HttpAddr = v.(string) } - if v, err := getConfig("int", "HttpPort"); err == nil { + if v, err := GetConfig("int", "HttpPort"); err == nil { HttpPort = v.(int) } - if v, err := getConfig("bool", "EnableHttpListen"); err == nil { + if v, err := GetConfig("bool", "EnableHttpListen"); err == nil { EnableHttpListen = v.(bool) } - if maxmemory, err := getConfig("int64", "MaxMemory"); err == nil { + if maxmemory, err := GetConfig("int64", "MaxMemory"); err == nil { MaxMemory = maxmemory.(int64) } - if appname, _ := getConfig("string", "AppName"); appname != "" { + if appname, _ := GetConfig("string", "AppName"); appname != "" { AppName = appname.(string) } - if runmode, _ := getConfig("string", "RunMode"); runmode != "" { + if runmode, _ := GetConfig("string", "RunMode"); runmode != "" { RunMode = runmode.(string) } - if autorender, err := getConfig("bool", "AutoRender"); err == nil { + if autorender, err := GetConfig("bool", "AutoRender"); err == nil { AutoRender = autorender.(bool) } - if autorecover, err := getConfig("bool", "RecoverPanic"); err == nil { + if autorecover, err := GetConfig("bool", "RecoverPanic"); err == nil { RecoverPanic = autorecover.(bool) } - if views, _ := getConfig("string", "ViewsPath"); views != "" { + if views, _ := GetConfig("string", "ViewsPath"); views != "" { ViewsPath = views.(string) } - if sessionon, err := getConfig("bool", "SessionOn"); err == nil { + if sessionon, err := GetConfig("bool", "SessionOn"); err == nil { SessionOn = sessionon.(bool) } - if sessProvider, _ := getConfig("string", "SessionProvider"); sessProvider != "" { + if sessProvider, _ := GetConfig("string", "SessionProvider"); sessProvider != "" { SessionProvider = sessProvider.(string) } - if sessName, _ := getConfig("string", "SessionName"); sessName != "" { + if sessName, _ := GetConfig("string", "SessionName"); sessName != "" { SessionName = sessName.(string) } - if sesssavepath, _ := getConfig("string", "SessionSavePath"); sesssavepath != "" { + if sesssavepath, _ := GetConfig("string", "SessionSavePath"); sesssavepath != "" { SessionSavePath = sesssavepath.(string) } - if sesshashfunc, _ := getConfig("string", "SessionHashFunc"); sesshashfunc != "" { + if sesshashfunc, _ := GetConfig("string", "SessionHashFunc"); sesshashfunc != "" { SessionHashFunc = sesshashfunc.(string) } - if sesshashkey, _ := getConfig("string", "SessionHashKey"); sesshashkey != "" { + if sesshashkey, _ := GetConfig("string", "SessionHashKey"); sesshashkey != "" { SessionHashKey = sesshashkey.(string) } - if sessMaxLifeTime, err := getConfig("int64", "SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { + if sessMaxLifeTime, err := GetConfig("int64", "SessionGCMaxLifetime"); err == nil && sessMaxLifeTime != 0 { SessionGCMaxLifetime = sessMaxLifeTime.(int64) } - if sesscookielifetime, err := getConfig("int", "SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { + if sesscookielifetime, err := GetConfig("int", "SessionCookieLifeTime"); err == nil && sesscookielifetime != 0 { SessionCookieLifeTime = sesscookielifetime.(int) } - if usefcgi, err := getConfig("bool", "UseFcgi"); err == nil { + if usefcgi, err := GetConfig("bool", "UseFcgi"); err == nil { UseFcgi = usefcgi.(bool) } - if enablegzip, err := getConfig("bool", "EnableGzip"); err == nil { + if enablegzip, err := GetConfig("bool", "EnableGzip"); err == nil { EnableGzip = enablegzip.(bool) } - if directoryindex, err := getConfig("bool", "DirectoryIndex"); err == nil { + if directoryindex, err := GetConfig("bool", "DirectoryIndex"); err == nil { DirectoryIndex = directoryindex.(bool) } - if timeout, err := getConfig("int64", "HttpServerTimeOut"); err == nil { + if timeout, err := GetConfig("int64", "HttpServerTimeOut"); err == nil { HttpServerTimeOut = timeout.(int64) } - if errorsshow, err := getConfig("bool", "ErrorsShow"); err == nil { + if errorsshow, err := GetConfig("bool", "ErrorsShow"); err == nil { ErrorsShow = errorsshow.(bool) } - if copyrequestbody, err := getConfig("bool", "CopyRequestBody"); err == nil { + if copyrequestbody, err := GetConfig("bool", "CopyRequestBody"); err == nil { CopyRequestBody = copyrequestbody.(bool) } - if xsrfkey, _ := getConfig("string", "XSRFKEY"); xsrfkey != "" { + if xsrfkey, _ := GetConfig("string", "XSRFKEY"); xsrfkey != "" { XSRFKEY = xsrfkey.(string) } - if enablexsrf, err := getConfig("bool", "EnableXSRF"); err == nil { + if enablexsrf, err := GetConfig("bool", "EnableXSRF"); err == nil { EnableXSRF = enablexsrf.(bool) } - if expire, err := getConfig("int", "XSRFExpire"); err == nil { + if expire, err := GetConfig("int", "XSRFExpire"); err == nil { XSRFExpire = expire.(int) } - if tplleft, _ := getConfig("string", "TemplateLeft"); tplleft != "" { + if tplleft, _ := GetConfig("string", "TemplateLeft"); tplleft != "" { TemplateLeft = tplleft.(string) } - if tplright, _ := getConfig("string", "TemplateRight"); tplright != "" { + if tplright, _ := GetConfig("string", "TemplateRight"); tplright != "" { TemplateRight = tplright.(string) } - if httptls, err := getConfig("bool", "EnableHttpTLS"); err == nil { + if httptls, err := GetConfig("bool", "EnableHttpTLS"); err == nil { EnableHttpTLS = httptls.(bool) } - if httpsport, err := getConfig("int", "HttpsPort"); err == nil { + if httpsport, err := GetConfig("int", "HttpsPort"); err == nil { HttpsPort = httpsport.(int) } - if certfile, _ := getConfig("string", "HttpCertFile"); certfile != "" { + if certfile, _ := GetConfig("string", "HttpCertFile"); certfile != "" { HttpCertFile = certfile.(string) } - if keyfile, _ := getConfig("string", "HttpKeyFile"); keyfile != "" { + if keyfile, _ := GetConfig("string", "HttpKeyFile"); keyfile != "" { HttpKeyFile = keyfile.(string) } - if serverName, _ := getConfig("string", "BeegoServerName"); serverName != "" { + if serverName, _ := GetConfig("string", "BeegoServerName"); serverName != "" { BeegoServerName = serverName.(string) } - if flashname, _ := getConfig("string", "FlashName"); flashname != "" { + if flashname, _ := GetConfig("string", "FlashName"); flashname != "" { FlashName = flashname.(string) } - if flashseperator, _ := getConfig("string", "FlashSeperator"); flashseperator != "" { + if flashseperator, _ := GetConfig("string", "FlashSeperator"); flashseperator != "" { FlashSeperator = flashseperator.(string) } - if sd, _ := getConfig("string", "StaticDir"); sd != "" { + if sd, _ := GetConfig("string", "StaticDir"); sd != "" { for k := range StaticDir { delete(StaticDir, k) } @@ -338,7 +338,7 @@ func ParseConfig() (err error) { } } - if sgz, _ := getConfig("string", "StaticExtensionsToGzip"); sgz != "" { + if sgz, _ := GetConfig("string", "StaticExtensionsToGzip"); sgz != "" { extensions := strings.Split(sgz.(string), ",") if len(extensions) > 0 { StaticExtensionsToGzip = []string{} @@ -355,26 +355,37 @@ func ParseConfig() (err error) { } } - if enableadmin, err := getConfig("bool", "EnableAdmin"); err == nil { + if enableadmin, err := GetConfig("bool", "EnableAdmin"); err == nil { EnableAdmin = enableadmin.(bool) } - if adminhttpaddr, _ := getConfig("string", "AdminHttpAddr"); adminhttpaddr != "" { + if adminhttpaddr, _ := GetConfig("string", "AdminHttpAddr"); adminhttpaddr != "" { AdminHttpAddr = adminhttpaddr.(string) } - if adminhttpport, err := getConfig("int", "AdminHttpPort"); err == nil { + if adminhttpport, err := GetConfig("int", "AdminHttpPort"); err == nil { AdminHttpPort = adminhttpport.(int) } - if enabledocs, err := getConfig("bool", "EnableDocs"); err == nil { + if enabledocs, err := GetConfig("bool", "EnableDocs"); err == nil { EnableDocs = enabledocs.(bool) } } return nil } -func getConfig(typ, key string) (interface{}, error) { +// Getconfig throw the Runmode +// [dev] +// name = astaixe +// IsEnable = false +// [prod] +// name = slene +// IsEnable = true +// +// usage: +// GetConfig("string", "name") +// GetConfig("bool", "IsEnable") +func GetConfig(typ, key string) (interface{}, error) { switch typ { case "string": v := AppConfig.String(RunMode + "::" + key) From 7a376c32be8905d8df93802d9716ded5bf69ea11 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 11 Aug 2014 22:13:57 +0800 Subject: [PATCH 071/120] delete forms --- forms/elements/button.go | 15 --- forms/elements/captcha.go | 1 - forms/elements/checkbox.go | 1 - forms/elements/csrf.go | 1 - forms/elements/date.go | 1 - forms/elements/element.go | 232 -------------------------------- forms/elements/email.go | 1 - forms/elements/file.go | 1 - forms/elements/hidden.go | 1 - forms/elements/image.go | 1 - forms/elements/multicheckbox.go | 1 - forms/elements/number.go | 1 - forms/elements/password.go | 1 - forms/elements/radio.go | 1 - forms/elements/range.go | 1 - forms/elements/select.go | 1 - forms/elements/submit.go | 15 --- forms/elements/text.go | 15 --- forms/elements/textarea.go | 15 --- forms/elements/time.go | 1 - forms/elements/url.go | 1 - forms/form.go | 57 -------- forms/form_test.go | 21 --- 23 files changed, 386 deletions(-) delete mode 100644 forms/elements/button.go delete mode 100644 forms/elements/captcha.go delete mode 100644 forms/elements/checkbox.go delete mode 100644 forms/elements/csrf.go delete mode 100644 forms/elements/date.go delete mode 100644 forms/elements/element.go delete mode 100644 forms/elements/email.go delete mode 100644 forms/elements/file.go delete mode 100644 forms/elements/hidden.go delete mode 100644 forms/elements/image.go delete mode 100644 forms/elements/multicheckbox.go delete mode 100644 forms/elements/number.go delete mode 100644 forms/elements/password.go delete mode 100644 forms/elements/radio.go delete mode 100644 forms/elements/range.go delete mode 100644 forms/elements/select.go delete mode 100644 forms/elements/submit.go delete mode 100644 forms/elements/text.go delete mode 100644 forms/elements/textarea.go delete mode 100644 forms/elements/time.go delete mode 100644 forms/elements/url.go delete mode 100644 forms/form.go delete mode 100644 forms/form_test.go diff --git a/forms/elements/button.go b/forms/elements/button.go deleted file mode 100644 index 4a9e5ba6..00000000 --- a/forms/elements/button.go +++ /dev/null @@ -1,15 +0,0 @@ -package elements - -type Button struct { - Element -} - -func NewButton() *Button { - b := &Button{} - b.options = make(map[string]interface{}) - b.attributes = make(map[string]interface{}) - b.labelAttributes = make(map[string]interface{}) - b.labelOptions = make(map[string]interface{}) - b.SetAttribute("type", "button") - return b -} diff --git a/forms/elements/captcha.go b/forms/elements/captcha.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/captcha.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/checkbox.go b/forms/elements/checkbox.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/checkbox.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/csrf.go b/forms/elements/csrf.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/csrf.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/date.go b/forms/elements/date.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/date.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/element.go b/forms/elements/element.go deleted file mode 100644 index ccb914c4..00000000 --- a/forms/elements/element.go +++ /dev/null @@ -1,232 +0,0 @@ -package elements - -type LableInterface interface { - SetLable(label string) - GetLable() (label string) - SetLabelAttributes(labelattrs map[string]interface{}) - GetLabelAttributes() (labelattrs map[string]interface{}) - SetLabelOptions(labelOptions map[string]interface{}) - GetLabelOptions() (labelOptions map[string]interface{}) - ClearLabelOptions() - RemoveLabelOptions(keys []string) - SetLabelOption(key string, val interface{}) - GetLabelOption(key string) (val interface{}) - RemoveLabelOption(key string) - HasLabelOption(key string) bool -} - -type ElementInterface interface { - SetName(name string) - GetName() (name string) - SetOptions(options map[string]interface{}) - SetOption(key string, val interface{}) - GetOptions() (options map[string]interface{}) - GetOption(key string) (val interface{}) - SetAttribute(key string, val interface{}) - GetAttribute(key string) (val interface{}) - RemoveAttribute(key string) - HasAttribute(key string) bool - SetAttributes(attributes map[string]interface{}) - GetAttributes() (attributes map[string]interface{}) - RemoveAttributes(keys []string) - ClearAttributes() - SetValue(val interface{}) - GetValue() (val interface{}) - SetMessages(msg string) - GetMessages() (msg string) - SetValidator(v ValidatorInterface) - Valid(val interface{}) bool - GetMessage() string - LableInterface -} - -type ValidatorInterface interface { - IsValid(val interface{}) bool - GetMessages() (msg string) -} - -type Element struct { - options map[string]interface{} - attributes map[string]interface{} - labelAttributes map[string]interface{} - labelOptions map[string]interface{} - value interface{} - lable string - messages string - validator ValidatorInterface -} - -func (e *Element) SetName(name string) { - e.SetAttribute("name", name) -} - -func (e *Element) GetName() (name string) { - return e.GetAttribute("name").(string) -} - -func (e *Element) SetOptions(options map[string]interface{}) { - if val, ok := options["label"]; ok { - e.SetLable(val.(string)) - } - - if val, ok := options["label_attributes"]; ok { - e.SetLabelAttributes(val.(map[string]interface{})) - } - - if val, ok := options["label_options"]; ok { - e.SetLabelOptions(val.(map[string]interface{})) - } - e.options = options -} - -func (e *Element) SetOption(key string, val interface{}) { - e.options[key] = val -} - -func (e *Element) GetOptions() (options map[string]interface{}) { - return e.options -} - -func (e *Element) GetOption(key string) (val interface{}) { - if val, ok := e.options[key]; ok { - return val - } - return nil -} - -func (e *Element) SetAttribute(key string, val interface{}) { - e.attributes[key] = val -} - -func (e *Element) GetAttribute(key string) (val interface{}) { - if val, ok := e.attributes[key]; ok { - return val - } - return nil -} - -func (e *Element) RemoveAttribute(key string) { - delete(e.attributes, key) -} - -func (e *Element) HasAttribute(key string) bool { - if _, ok := e.attributes[key]; ok { - return true - } - return false -} - -func (e *Element) SetAttributes(attributes map[string]interface{}) { - for key, val := range attributes { - e.SetAttribute(key, val) - } -} - -func (e *Element) GetAttributes() (attributes map[string]interface{}) { - return e.attributes -} - -func (e *Element) RemoveAttributes(keys []string) { - for _, key := range keys { - e.RemoveAttribute(key) - } -} - -func (e *Element) ClearAttributes() { - e.attributes = make(map[string]interface{}) -} - -func (e *Element) SetValue(val interface{}) { - e.value = val -} - -func (e *Element) GetValue() (val interface{}) { - return e.value -} - -func (e *Element) SetLable(label string) { - e.lable = label -} - -func (e *Element) GetLable() (label string) { - return e.lable -} - -func (e *Element) SetLabelAttributes(labelattrs map[string]interface{}) { - e.labelAttributes = labelattrs -} - -func (e *Element) GetLabelAttributes() (labelattrs map[string]interface{}) { - return e.labelAttributes -} - -func (e *Element) SetLabelOptions(labelOptions map[string]interface{}) { - for key, val := range labelOptions { - e.SetLabelOption(key, val) - } -} - -func (e *Element) GetLabelOptions() (labelOptions map[string]interface{}) { - return e.labelOptions -} - -func (e *Element) ClearLabelOptions() { - e.labelOptions = make(map[string]interface{}) -} - -func (e *Element) RemoveLabelOptions(keys []string) { - for _, key := range keys { - e.RemoveLabelOption(key) - } -} - -func (e *Element) SetLabelOption(key string, val interface{}) { - e.labelOptions[key] = val -} - -func (e *Element) GetLabelOption(key string) (val interface{}) { - if v, ok := e.labelOptions[key]; ok { - return v - } - return nil -} - -func (e *Element) RemoveLabelOption(key string) { - delete(e.labelOptions, key) -} - -func (e *Element) HasLabelOption(key string) bool { - if _, ok := e.labelOptions[key]; ok { - return true - } - return false -} - -func (e *Element) SetMessages(msg string) { - e.messages = msg -} - -func (e *Element) GetMessages() (msg string) { - return e.messages -} - -func (e *Element) SetValidator(v ValidatorInterface) { - e.validator = v -} - -func (e *Element) Valid(val interface{}) bool { - if e.validator == nil { - return true - } - if e.validator.IsValid(val) { - return true - } - return false -} - -func (e *Element) GetMessage() string { - if e.validator == nil { - return "" - } - return e.validator.GetMessages() -} diff --git a/forms/elements/email.go b/forms/elements/email.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/email.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/file.go b/forms/elements/file.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/file.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/hidden.go b/forms/elements/hidden.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/hidden.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/image.go b/forms/elements/image.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/image.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/multicheckbox.go b/forms/elements/multicheckbox.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/multicheckbox.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/number.go b/forms/elements/number.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/number.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/password.go b/forms/elements/password.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/password.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/radio.go b/forms/elements/radio.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/radio.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/range.go b/forms/elements/range.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/range.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/select.go b/forms/elements/select.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/select.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/submit.go b/forms/elements/submit.go deleted file mode 100644 index faa88a5a..00000000 --- a/forms/elements/submit.go +++ /dev/null @@ -1,15 +0,0 @@ -package elements - -type Submit struct { - Element -} - -func NewSubmit() *Submit { - b := &Submit{} - b.options = make(map[string]interface{}) - b.attributes = make(map[string]interface{}) - b.labelAttributes = make(map[string]interface{}) - b.labelOptions = make(map[string]interface{}) - b.SetAttribute("type", "submit") - return b -} diff --git a/forms/elements/text.go b/forms/elements/text.go deleted file mode 100644 index c1050c3d..00000000 --- a/forms/elements/text.go +++ /dev/null @@ -1,15 +0,0 @@ -package elements - -type Text struct { - Element -} - -func NewText() *Text { - b := &Text{} - b.options = make(map[string]interface{}) - b.attributes = make(map[string]interface{}) - b.labelAttributes = make(map[string]interface{}) - b.labelOptions = make(map[string]interface{}) - b.SetAttribute("type", "text") - return b -} diff --git a/forms/elements/textarea.go b/forms/elements/textarea.go deleted file mode 100644 index c879ec49..00000000 --- a/forms/elements/textarea.go +++ /dev/null @@ -1,15 +0,0 @@ -package elements - -type Textarea struct { - Element -} - -func NewTextarea() *Textarea { - b := &Textarea{} - b.options = make(map[string]interface{}) - b.attributes = make(map[string]interface{}) - b.labelAttributes = make(map[string]interface{}) - b.labelOptions = make(map[string]interface{}) - b.SetAttribute("type", "textarea") - return b -} diff --git a/forms/elements/time.go b/forms/elements/time.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/time.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/elements/url.go b/forms/elements/url.go deleted file mode 100644 index 395f9955..00000000 --- a/forms/elements/url.go +++ /dev/null @@ -1 +0,0 @@ -package elements \ No newline at end of file diff --git a/forms/form.go b/forms/form.go deleted file mode 100644 index b554037d..00000000 --- a/forms/form.go +++ /dev/null @@ -1,57 +0,0 @@ -// Beego (http://beego.me/) -// @description beego is an open-source, high-performance web framework for the Go programming language. -// @link http://github.com/astaxie/beego for the canonical source repository -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// @authors astaxie - -package forms - -import ( - "github.com/astaxie/beego/forms/elements" -) - -type Form struct { - elements map[string]elements.ElementInterface -} - -func NewForm() *Form { - f := &Form{} - f.elements = make(map[string]elements.ElementInterface) - return f -} - -func (f *Form) Init() *Form { - f.elements = make(map[string]elements.ElementInterface) -} - -func (f *Form) Valid(data map[string]interface{}) bool { - for k, val := range data { - if e, ok := f.elements[k]; ok { - if !e.Valid(val) { - return false - } - } - } - return true -} - -func (f *Form) SetData() { - -} - -func (f *Form) Bind() { - -} - -func (f *Form) SaveData() { - -} - -func (f *Form) AddElement(e elements.ElementInterface) { - name := e.GetName() - f.elements[name] = e -} - -func (f *Form) Render() string { - -} diff --git a/forms/form_test.go b/forms/form_test.go deleted file mode 100644 index 6a1a78b9..00000000 --- a/forms/form_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package forms - -import ( - "fmt" - "testing" - - "./elements" -) - -func formTest(t *testing.T) { - rf := NewForm() - username := elements.NewText() - username.SetAttribute("name", "username") - username.SetAttribute("id", "username") - rf.AddElement(username) - - button := elements.NewSubmit() - rf.AddElement(rf) - - fmt.Println(rf.Render()) -} From 118e07158edbedc79730d155a47fe90dbffdd51c Mon Sep 17 00:00:00 2001 From: liulixiang1988 Date: Mon, 11 Aug 2014 22:19:59 +0800 Subject: [PATCH 072/120] improve the 'geturl' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we have a url mapping like this: `beego.Router(“/test”, &controllers.WeightController{}, "get:GetDetails”)` when u use `UrlFor(“WeightController.GetDetails”, “foo”, 1, “bar”, 2 `, it should return `/test?foo=1&bar=2` rather than `/test`. --- router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.go b/router.go index d24241e6..03eb5e83 100644 --- a/router.go +++ b/router.go @@ -459,7 +459,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin if find { if l.regexps == nil { if len(l.wildcards) == 0 { - return true, strings.Replace(url, "/"+url_placeholder, "", 1) + return true, strings.Replace(url, "/"+url_placeholder, "", 1) + tourl(params) } if len(l.wildcards) == 1 { if v, ok := params[l.wildcards[0]]; ok { From 8ed6d065725be7eec7e9db9227006130ecc518e4 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 11 Aug 2014 22:40:50 +0800 Subject: [PATCH 073/120] fix the regexps bugs --- tree.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tree.go b/tree.go index 1bf72f9d..d6b1f564 100644 --- a/tree.go +++ b/tree.go @@ -106,7 +106,11 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) { filterCards = append(filterCards, v) } l.wildcards = filterCards - l.regexps = regexp.MustCompile("^" + reg + strings.Trim(l.regexps.String(), "^$") + "$") + if l.regexps != nil { + l.regexps = regexp.MustCompile("^" + reg + strings.Trim(l.regexps.String(), "^$") + "$") + } else { + l.regexps = regexp.MustCompile("^" + reg + "$") + } } else { if l.regexps != nil { filterCards := []string{} From 52fdfc5665c8e6d9a04fd676cc60c7ffe247f778 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 00:02:27 +0800 Subject: [PATCH 074/120] beego: fix the tree addTree for regexp --- tree.go | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/tree.go b/tree.go index d6b1f564..7afe317c 100644 --- a/tree.go +++ b/tree.go @@ -46,22 +46,38 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st } seg := segments[0] iswild, params, regexpStr := splitSegment(seg) - if len(segments) == 1 && seg != "" { + if len(segments) == 1 { if iswild { - wildcards = append(wildcards, params...) if regexpStr != "" { - for _, w := range params { + if reg == "" { + rr := "" + for _, w := range wildcards { + if w == "." || w == ":" { + continue + } + if w == ":splat" { + rr = rr + "(.+)/" + } else { + rr = rr + "([^/]+)/" + } + } + regexpStr = rr + regexpStr + } else { + regexpStr = "/" + regexpStr + } + } else { + for _, w := range wildcards { if w == "." || w == ":" { continue } - regexpStr = "([^/]+)/" + regexpStr + regexpStr = "/([^/]+)" + regexpStr } } reg = reg + regexpStr - filterTreeWithPrefix(tree, wildcards, reg) + filterTreeWithPrefix(tree, append(wildcards, params...), reg) t.wildcard = tree } else { - filterTreeWithPrefix(tree, wildcards, reg) + filterTreeWithPrefix(tree, append(wildcards, params...), reg) t.fixrouters[seg] = tree } return @@ -70,21 +86,37 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st if t.wildcard == nil { t.wildcard = NewTree() } - wildcards = append(wildcards) if regexpStr != "" { - for _, w := range params { + if reg == "" { + rr := "" + for _, w := range wildcards { + if w == "." || w == ":" { + continue + } + if w == ":splat" { + rr = rr + "(.+)/" + } else { + rr = rr + "([^/]+)/" + } + } + regexpStr = rr + regexpStr + } else { + regexpStr = "/" + regexpStr + } + } else { + for _, w := range wildcards { if w == "." || w == ":" { continue } - regexpStr = "([^/]+)/" + regexpStr + regexpStr = "/([^/]+)" + regexpStr } } reg = reg + regexpStr - t.wildcard.addtree(segments[1:], tree, wildcards, reg) + t.wildcard.addtree(segments[1:], tree, append(wildcards, params...), reg) } else { subTree := NewTree() t.fixrouters[seg] = subTree - subTree.addtree(segments[1:], tree, wildcards, reg) + subTree.addtree(segments[1:], tree, append(wildcards, params...), reg) } } From f201859fa71553e3879822d56a73b473cc440f36 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 00:15:39 +0800 Subject: [PATCH 075/120] beego: fix the addTree --- tree.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tree.go b/tree.go index 7afe317c..121e02c6 100644 --- a/tree.go +++ b/tree.go @@ -108,7 +108,11 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st if w == "." || w == ":" { continue } - regexpStr = "/([^/]+)" + regexpStr + if w == ":splat" { + regexpStr = "/(.+)" + regexpStr + } else { + regexpStr = "/([^/]+)" + regexpStr + } } } reg = reg + regexpStr @@ -145,19 +149,15 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) { } } else { if l.regexps != nil { - filterCards := []string{} - for _, v := range l.wildcards { - if v == ":" || v == "." { - continue - } - filterCards = append(filterCards, v) - } - l.wildcards = filterCards for _, w := range wildcards { if w == "." || w == ":" { continue } - reg = "([^/]+)/" + reg + if w == ":splat" { + reg = "(.+)/" + reg + } else { + reg = "([^/]+)/" + reg + } } l.regexps = regexp.MustCompile("^" + reg + strings.Trim(l.regexps.String(), "^$") + "$") } From 6a78898bb1d6c341863ba2bb81715385a1889111 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 15:09:12 +0800 Subject: [PATCH 076/120] beego: fix the tree for addtree & add testcase --- tree.go | 36 ++++++++++++++++++++++++------------ tree_test.go | 18 ++++++++++++++++++ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/tree.go b/tree.go index 121e02c6..f32bed13 100644 --- a/tree.go +++ b/tree.go @@ -70,10 +70,10 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st if w == "." || w == ":" { continue } - regexpStr = "/([^/]+)" + regexpStr + regexpStr = "([^/]+)/" + regexpStr } } - reg = reg + regexpStr + reg = strings.Trim(reg+regexpStr, "/") filterTreeWithPrefix(tree, append(wildcards, params...), reg) t.wildcard = tree } else { @@ -99,9 +99,9 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st rr = rr + "([^/]+)/" } } - regexpStr = rr + regexpStr + regexpStr = rr + regexpStr + "/" } else { - regexpStr = "/" + regexpStr + regexpStr = "/" + regexpStr + "/" } } else { for _, w := range wildcards { @@ -109,9 +109,9 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st continue } if w == ":splat" { - regexpStr = "/(.+)" + regexpStr + regexpStr = "(.+)/" + regexpStr } else { - regexpStr = "/([^/]+)" + regexpStr + regexpStr = "([^/]+)/" + regexpStr } } } @@ -132,8 +132,24 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) { filterTreeWithPrefix(t.wildcard, wildcards, reg) } for _, l := range t.leaves { - l.wildcards = append(wildcards, l.wildcards...) if reg != "" { + if l.regexps != nil { + l.wildcards = append(wildcards, l.wildcards...) + l.regexps = regexp.MustCompile("^" + reg + strings.Trim(l.regexps.String(), "^$") + "$") + } else { + for _, v := range l.wildcards { + if v == ":" || v == "." { + continue + } + if v == ":splat" { + reg = reg + "/(.+)" + } else { + reg = reg + "/([^/]+)" + } + } + l.regexps = regexp.MustCompile("^" + reg + "$") + l.wildcards = append(wildcards, l.wildcards...) + } filterCards := []string{} for _, v := range l.wildcards { if v == ":" || v == "." { @@ -142,12 +158,8 @@ func filterTreeWithPrefix(t *Tree, wildcards []string, reg string) { filterCards = append(filterCards, v) } l.wildcards = filterCards - if l.regexps != nil { - l.regexps = regexp.MustCompile("^" + reg + strings.Trim(l.regexps.String(), "^$") + "$") - } else { - l.regexps = regexp.MustCompile("^" + reg + "$") - } } else { + l.wildcards = append(wildcards, l.wildcards...) if l.regexps != nil { for _, w := range wildcards { if w == "." || w == ":" { diff --git a/tree_test.go b/tree_test.go index 589b64ca..97c855c0 100644 --- a/tree_test.go +++ b/tree_test.go @@ -122,6 +122,24 @@ func TestAddTree(t *testing.T) { } } +func TestAddTree2(t *testing.T) { + tr := NewTree() + tr.AddRouter("/shop/:id/account", "astaxie") + tr.AddRouter("/shop/:sd/ttt_:id(.+)_:page(.+).html", "astaxie") + t3 := NewTree() + t3.AddTree("/:version(v1|v2)/:prefix", tr) + obj, param := t3.Match("/v1/zl/shop/123/account") + if obj == nil || obj.(string) != "astaxie" { + t.Fatal("/:version(v1|v2)/:prefix/shop/:id/account can't get obj ") + } + if param == nil { + t.Fatal("get param error") + } + if param[":id"] != "123" || param[":prefix"] != "zl" || param[":version"] != "v1" { + t.Fatal("get :id :prefix :version param error") + } +} + func TestSplitPath(t *testing.T) { a := splitPath("/") if len(a) != 0 { From b97279a74f98e3be0b269cb51cdebeca1d055cac Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 15:49:30 +0800 Subject: [PATCH 077/120] update the migration --- migration/migration.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 8cb0ce5d..c1037907 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -12,6 +12,7 @@ package migration import ( "errors" "sort" + "strings" "time" "github.com/astaxie/beego" @@ -25,7 +26,7 @@ const M_DATE_FORMAT = "20060102_150405" type Migrationer interface { Up() Down() - Exec() error + Exec(name, status string) error GetCreated() int64 } @@ -57,7 +58,7 @@ func (m *Migration) Sql(sql string) { } // execute the sql already add in the sql -func (m *Migration) Exec() error { +func (m *Migration) Exec(name, status string) error { o := orm.NewOrm() for _, s := range m.sqls { beego.Info("exec sql:", s) @@ -67,7 +68,28 @@ func (m *Migration) Exec() error { return err } } - return nil + return m.addOrUpdateRecord(name, status) +} + +func (m *Migration) addOrUpdateRecord(status, name string) error { + o := orm.NewOrm() + if status == "down" { + status = "rollback" + p, err := o.Raw("update migrations set status = ?,rollback_statements = ? where name = ?").Prepare() + if err != nil { + return nil + } + _, err = p.Exec(status, strings.Join(m.sqls, "; "), name) + return err + } else { + status = "update" + p, err := o.Raw("insert into migrations(`name`,`created_at`,`statements`,`status`) values(?,?,?,?)").Prepare() + if err != nil { + return err + } + _, err = p.Exec(name, m.GetCreated(), strings.Join(m.sqls, "; "), status) + return err + } } // get the unixtime from the Created @@ -96,7 +118,7 @@ func Upgrade(lasttime int64) error { if v.created > lasttime { beego.Info("start upgrade", v.name) v.m.Up() - err := v.m.Exec() + err := v.m.Exec(v.name, "up") if err != nil { return err } @@ -113,7 +135,7 @@ func Rollback(name string) error { if v, ok := migrationMap[name]; ok { beego.Info("start rollback") v.Down() - err := v.Exec() + err := v.Exec(name, "down") if err != nil { return err } @@ -131,7 +153,7 @@ func Reset() error { for k, v := range migrationMap { beego.Info("start reset:", k) v.Down() - err := v.Exec() + err := v.Exec(k, "down") if err != nil { return err } From fe9017c8196185ecf768480c402f3be4a73fd948 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 15:50:28 +0800 Subject: [PATCH 078/120] update the description --- migration/migration.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.go b/migration/migration.go index c1037907..03612237 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -7,6 +7,17 @@ // @license http://github.com/astaxie/beego/blob/master/LICENSE // // @authors astaxie +// +// CREATE TABLE `migrations` ( +// `id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key', +// `name` varchar(255) DEFAULT NULL COMMENT 'migration name, unique', +// `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date migrated or rolled back', +// `statements` longtext COMMENT 'SQL statements for this migration', +// `rollback_statements` longtext, +// `status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back', +// PRIMARY KEY (`id_migration`), +// UNIQUE KEY `name` (`name`) +// ) ENGINE=InnoDB DEFAULT CHARSET=utf8; package migration import ( From d325a66fee62380ae99a91573d8e4f6b23fc0a8f Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 12 Aug 2014 16:35:59 +0800 Subject: [PATCH 079/120] update the error info --- migration/migration.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/migration/migration.go b/migration/migration.go index 03612237..71f8be35 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -131,6 +131,7 @@ func Upgrade(lasttime int64) error { v.m.Up() err := v.m.Exec(v.name, "up") if err != nil { + beego.Error("execute error:", err) return err } beego.Info("end upgrade:", v.name) @@ -148,6 +149,7 @@ func Rollback(name string) error { v.Down() err := v.Exec(name, "down") if err != nil { + beego.Error("execute error:", err) return err } beego.Info("end rollback") @@ -166,6 +168,7 @@ func Reset() error { v.Down() err := v.Exec(k, "down") if err != nil { + beego.Error("execute error:", err) return err } beego.Info("end reset:", k) @@ -178,6 +181,7 @@ func Reset() error { func Refresh() error { err := Reset() if err != nil { + beego.Error("execute error:", err) return err } return Upgrade(0) From 5ecfe0c3353ae04ac02aa853906f68ae1e8664b4 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 13 Aug 2014 10:43:05 +0800 Subject: [PATCH 080/120] beego hook change the path & fix the migration bug --- beego.go | 5 +++-- migration/migration.go | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/beego.go b/beego.go index ffedcc68..48b4bf29 100644 --- a/beego.go +++ b/beego.go @@ -388,6 +388,9 @@ func initBeforeHttpRun() { Get("/docs", serverDocs) Get("/docs/*", serverDocs) } + + //init mime + AddAPPStartHook(initMime) } // this function is for test package init @@ -406,6 +409,4 @@ func TestBeegoInit(apppath string) { func init() { hooks = make([]hookfunc, 0) - //init mime - AddAPPStartHook(initMime) } diff --git a/migration/migration.go b/migration/migration.go index 71f8be35..6269104e 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -23,6 +23,7 @@ package migration import ( "errors" "sort" + "strconv" "strings" "time" @@ -82,11 +83,11 @@ func (m *Migration) Exec(name, status string) error { return m.addOrUpdateRecord(name, status) } -func (m *Migration) addOrUpdateRecord(status, name string) error { +func (m *Migration) addOrUpdateRecord(name, status string) error { o := orm.NewOrm() if status == "down" { status = "rollback" - p, err := o.Raw("update migrations set status = ?,rollback_statements = ? where name = ?").Prepare() + p, err := o.Raw("update migrations set status = ?, rollback_statements = ? where name = ?").Prepare() if err != nil { return nil } @@ -94,11 +95,11 @@ func (m *Migration) addOrUpdateRecord(status, name string) error { return err } else { status = "update" - p, err := o.Raw("insert into migrations(`name`,`created_at`,`statements`,`status`) values(?,?,?,?)").Prepare() + p, err := o.Raw("insert into migrations(`name`, `created_at`, `statements`, `status`) values(?,?,?,?)").Prepare() if err != nil { return err } - _, err = p.Exec(name, m.GetCreated(), strings.Join(m.sqls, "; "), status) + _, err = p.Exec(name, strconv.FormatInt(m.GetCreated(), 10), strings.Join(m.sqls, "; "), status) return err } } From efcaa3d9342706d55b69b7957d4887149c9114d4 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 13 Aug 2014 11:16:19 +0800 Subject: [PATCH 081/120] update the migration database time format --- migration/migration.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 6269104e..09499dca 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -23,7 +23,6 @@ package migration import ( "errors" "sort" - "strconv" "strings" "time" @@ -32,7 +31,10 @@ import ( ) // const the data format for the bee generate migration datatype -const M_DATE_FORMAT = "20060102_150405" +const ( + M_DATE_FORMAT = "20060102_150405" + M_DB_DATE_FORMAT = "2006-01-02 15:04:05" +) // Migrationer is an interface for all Migration struct type Migrationer interface { @@ -99,7 +101,11 @@ func (m *Migration) addOrUpdateRecord(name, status string) error { if err != nil { return err } - _, err = p.Exec(name, strconv.FormatInt(m.GetCreated(), 10), strings.Join(m.sqls, "; "), status) + t, err := time.Parse(M_DB_DATE_FORMAT, m.Created) + if err != nil { + return err + } + _, err = p.Exec(name, t.Format(M_DB_DATE_FORMAT), strings.Join(m.sqls, "; "), status) return err } } From e572f45296fb24ac0016347d7b7df39cc1a3016a Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 13 Aug 2014 14:50:32 +0800 Subject: [PATCH 082/120] update the error output --- migration/migration.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/migration/migration.go b/migration/migration.go index 09499dca..70b2ae2c 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -139,6 +139,7 @@ func Upgrade(lasttime int64) error { err := v.m.Exec(v.name, "up") if err != nil { beego.Error("execute error:", err) + time.Sleep(2 * time.Second) return err } beego.Info("end upgrade:", v.name) @@ -157,6 +158,7 @@ func Rollback(name string) error { err := v.Exec(name, "down") if err != nil { beego.Error("execute error:", err) + time.Sleep(2 * time.Second) return err } beego.Info("end rollback") @@ -176,6 +178,7 @@ func Reset() error { err := v.Exec(k, "down") if err != nil { beego.Error("execute error:", err) + time.Sleep(2 * time.Second) return err } beego.Info("end reset:", k) @@ -189,6 +192,7 @@ func Refresh() error { err := Reset() if err != nil { beego.Error("execute error:", err) + time.Sleep(2 * time.Second) return err } return Upgrade(0) From 32469cd69dc3f4fc335ec18bfa454f98001ac6f4 Mon Sep 17 00:00:00 2001 From: Zheng Yang Date: Wed, 13 Aug 2014 16:09:13 +0800 Subject: [PATCH 083/120] change time format --- migration/migration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/migration.go b/migration/migration.go index 70b2ae2c..27448267 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -101,7 +101,7 @@ func (m *Migration) addOrUpdateRecord(name, status string) error { if err != nil { return err } - t, err := time.Parse(M_DB_DATE_FORMAT, m.Created) + t, err := time.Parse(M_DATE_FORMAT, m.Created) if err != nil { return err } From ae37f95239043a8ebb98456328a1465e4ea1a816 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 13 Aug 2014 16:42:16 +0800 Subject: [PATCH 084/120] migration: delete the unique key for name --- migration/migration.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 27448267..c24b839e 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -15,8 +15,7 @@ // `statements` longtext COMMENT 'SQL statements for this migration', // `rollback_statements` longtext, // `status` enum('update','rollback') DEFAULT NULL COMMENT 'update indicates it is a normal migration while rollback means this migration is rolled back', -// PRIMARY KEY (`id_migration`), -// UNIQUE KEY `name` (`name`) +// PRIMARY KEY (`id_migration`) // ) ENGINE=InnoDB DEFAULT CHARSET=utf8; package migration From 20463fa725a9d8eaf5537633f5ca28691b5265f6 Mon Sep 17 00:00:00 2001 From: smallfish Date: Wed, 13 Aug 2014 17:26:22 +0800 Subject: [PATCH 085/120] Add CustomAbort() for Controller, support status code and body --- controller.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controller.go b/controller.go index 6f7b510c..ecc585e2 100644 --- a/controller.go +++ b/controller.go @@ -274,6 +274,11 @@ func (c *Controller) Abort(code string) { } } +// CustomAbort stops controller handler and show the error data, it's similar Aborts, but support status code and body. +func (c *Controller) CustomAbort(status int, body string) { + c.Ctx.Abort(status, body) +} + // StopRun makes panic of USERSTOPRUN error and go to recover function if defined. func (c *Controller) StopRun() { panic(USERSTOPRUN) From 55a77110175da26631af8767a94b4dae17f82c92 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 10:19:55 +0800 Subject: [PATCH 086/120] migration: skip reset --- migration/migration.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/migration/migration.go b/migration/migration.go index c24b839e..5945fd76 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -43,7 +43,10 @@ type Migrationer interface { GetCreated() int64 } -var migrationMap map[string]Migrationer +var ( + migrationMap map[string]Migrationer + SkipReset []string +) func init() { migrationMap = make(map[string]Migrationer) @@ -172,6 +175,10 @@ func Rollback(name string) error { func Reset() error { i := 0 for k, v := range migrationMap { + if inSlice(k, SkipReset) { + beego.Info("skip the", k) + continue + } beego.Info("start reset:", k) v.Down() err := v.Exec(k, "down") @@ -232,3 +239,12 @@ func sortMap(m map[string]Migrationer) dataSlice { sort.Sort(s) return s } + +func inSlice(key string, sli []string) bool { + for _, v := range sli { + if v == key { + return true + } + } + return false +} From f98b1810aba67f19a380033bcfccbcd2db22ec32 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 10:56:49 +0800 Subject: [PATCH 087/120] update the reset --- migration/migration.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 5945fd76..0a488ffb 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -45,7 +45,6 @@ type Migrationer interface { var ( migrationMap map[string]Migrationer - SkipReset []string ) func init() { @@ -175,7 +174,7 @@ func Rollback(name string) error { func Reset() error { i := 0 for k, v := range migrationMap { - if inSlice(k, SkipReset) { + if isRollBack(k) { beego.Info("skip the", k) continue } @@ -240,11 +239,19 @@ func sortMap(m map[string]Migrationer) dataSlice { return s } -func inSlice(key string, sli []string) bool { - for _, v := range sli { - if v == key { - return true - } +func isRollBack(name string) bool { + o := orm.NewOrm() + var maps []orm.Params + num, err := o.Raw("select * from migrations where `name` = ? order by id desc", name).Values(&maps) + if err != nil { + beego.Info("get name has error", err) + return false + } + if num <= 0 { + return false + } + if maps[0]["status"] == "rollback" { + return true } return false } From d2119f715c013cf4405950530eb254a596738666 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 11:39:59 +0800 Subject: [PATCH 088/120] update the migrations --- migration/migration.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/migration/migration.go b/migration/migration.go index 0a488ffb..19f4a49d 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -148,6 +148,7 @@ func Upgrade(lasttime int64) error { } } beego.Info("total success upgrade:", i, " migration") + time.Sleep(2 * time.Second) return nil } @@ -163,6 +164,7 @@ func Rollback(name string) error { return err } beego.Info("end rollback") + time.Sleep(2 * time.Second) return nil } else { return errors.New("not exist the migrationMap name:" + name) @@ -176,6 +178,7 @@ func Reset() error { for k, v := range migrationMap { if isRollBack(k) { beego.Info("skip the", k) + time.Sleep(1 * time.Second) continue } beego.Info("start reset:", k) @@ -189,6 +192,7 @@ func Reset() error { beego.Info("end reset:", k) } beego.Info("total success reset:", i, " migration") + time.Sleep(2 * time.Second) return nil } @@ -242,7 +246,7 @@ func sortMap(m map[string]Migrationer) dataSlice { func isRollBack(name string) bool { o := orm.NewOrm() var maps []orm.Params - num, err := o.Raw("select * from migrations where `name` = ? order by id desc", name).Values(&maps) + num, err := o.Raw("select * from migrations where `name` = ? order by id_migration desc", name).Values(&maps) if err != nil { beego.Info("get name has error", err) return false From 886bb782a5a19000f21442051323e30dbed697e1 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 11:44:10 +0800 Subject: [PATCH 089/120] sort the reset --- migration/migration.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 19f4a49d..82469568 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -174,22 +174,24 @@ func Rollback(name string) error { // reset all migration // run all migration's down function func Reset() error { + sm := sortMap(migrationMap) i := 0 - for k, v := range migrationMap { - if isRollBack(k) { - beego.Info("skip the", k) + for _, v := range sm { + if isRollBack(v.name) { + beego.Info("skip the", v.name) time.Sleep(1 * time.Second) continue } - beego.Info("start reset:", k) - v.Down() - err := v.Exec(k, "down") + beego.Info("start reset:", v.name) + v.m.Down() + err := v.m.Exec(v.name, "down") if err != nil { beego.Error("execute error:", err) time.Sleep(2 * time.Second) return err } - beego.Info("end reset:", k) + i++ + beego.Info("end reset:", v.name) } beego.Info("total success reset:", i, " migration") time.Sleep(2 * time.Second) From 14cd9e51aca0012919b6a4bf4fe3d4c05ef7bbab Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 11:54:15 +0800 Subject: [PATCH 090/120] revert the sort map for reset --- migration/migration.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 82469568..62665e43 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -176,7 +176,8 @@ func Rollback(name string) error { func Reset() error { sm := sortMap(migrationMap) i := 0 - for _, v := range sm { + for j := len(sm) - 1; j >= 0; j-- { + v := sm[j] if isRollBack(v.name) { beego.Info("skip the", v.name) time.Sleep(1 * time.Second) @@ -206,7 +207,8 @@ func Refresh() error { time.Sleep(2 * time.Second) return err } - return Upgrade(0) + err = Upgrade(0) + return err } type dataSlice []data From 57a9670b0af221fdeeb54e7c08c0cc544e978d1b Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 13:37:48 +0800 Subject: [PATCH 091/120] migration: reset the up state sql --- migration/migration.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/migration/migration.go b/migration/migration.go index 62665e43..4aeb8b87 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -39,6 +39,7 @@ const ( type Migrationer interface { Up() Down() + Reset() Exec(name, status string) error GetCreated() int64 } @@ -72,6 +73,11 @@ func (m *Migration) Sql(sql string) { m.sqls = append(m.sqls, sql) } +// Reset the sqls +func (m *Migration) Reset() { + m.sqls = make([]string, 0) +} + // execute the sql already add in the sql func (m *Migration) Exec(name, status string) error { o := orm.NewOrm() @@ -90,11 +96,11 @@ func (m *Migration) addOrUpdateRecord(name, status string) error { o := orm.NewOrm() if status == "down" { status = "rollback" - p, err := o.Raw("update migrations set status = ?, rollback_statements = ? where name = ?").Prepare() + p, err := o.Raw("update migrations set `status` = ?, `rollback_statements` = ?, `created_at` = ? where name = ?").Prepare() if err != nil { return nil } - _, err = p.Exec(status, strings.Join(m.sqls, "; "), name) + _, err = p.Exec(status, strings.Join(m.sqls, "; "), name, time.Now().Format(M_DB_DATE_FORMAT)) return err } else { status = "update" @@ -102,11 +108,7 @@ func (m *Migration) addOrUpdateRecord(name, status string) error { if err != nil { return err } - t, err := time.Parse(M_DATE_FORMAT, m.Created) - if err != nil { - return err - } - _, err = p.Exec(name, t.Format(M_DB_DATE_FORMAT), strings.Join(m.sqls, "; "), status) + _, err = p.Exec(name, time.Now().Format(M_DB_DATE_FORMAT), strings.Join(m.sqls, "; "), status) return err } } @@ -136,6 +138,7 @@ func Upgrade(lasttime int64) error { for _, v := range sm { if v.created > lasttime { beego.Info("start upgrade", v.name) + v.m.Reset() v.m.Up() err := v.m.Exec(v.name, "up") if err != nil { @@ -156,6 +159,7 @@ func Upgrade(lasttime int64) error { func Rollback(name string) error { if v, ok := migrationMap[name]; ok { beego.Info("start rollback") + v.Reset() v.Down() err := v.Exec(name, "down") if err != nil { @@ -184,6 +188,7 @@ func Reset() error { continue } beego.Info("start reset:", v.name) + v.m.Reset() v.m.Down() err := v.m.Exec(v.name, "down") if err != nil { From 31f0ac4ce347c14b01a5fe4e2a96747ab0aa794e Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 13:41:54 +0800 Subject: [PATCH 092/120] migration: update the params orders --- migration/migration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/migration.go b/migration/migration.go index 4aeb8b87..02e8d0db 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -100,7 +100,7 @@ func (m *Migration) addOrUpdateRecord(name, status string) error { if err != nil { return nil } - _, err = p.Exec(status, strings.Join(m.sqls, "; "), name, time.Now().Format(M_DB_DATE_FORMAT)) + _, err = p.Exec(status, strings.Join(m.sqls, "; "), time.Now().Format(M_DB_DATE_FORMAT), name) return err } else { status = "update" From 564c3bbeb512d7d9e7fe439ac6c02f400c50b516 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 14 Aug 2014 13:44:05 +0800 Subject: [PATCH 093/120] migration: update the debug error --- migration/migration.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/migration.go b/migration/migration.go index 02e8d0db..47035e6a 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -171,6 +171,8 @@ func Rollback(name string) error { time.Sleep(2 * time.Second) return nil } else { + beego.Error("not exist the migrationMap name:" + name) + time.Sleep(2 * time.Second) return errors.New("not exist the migrationMap name:" + name) } } From d314d12c770b5039a424fbd7cd56f260b15cce88 Mon Sep 17 00:00:00 2001 From: Lei Cao Date: Thu, 14 Aug 2014 17:35:23 +0800 Subject: [PATCH 094/120] Added the UI for Admin monitor page --- admin.go | 375 +++++++++++++++++++++++++++++------------- adminui.go | 313 +++++++++++++++++++++++++++++++++++ toolbox/statistics.go | 27 +-- 3 files changed, 592 insertions(+), 123 deletions(-) create mode 100644 adminui.go diff --git a/admin.go b/admin.go index fa9ef3b3..93b1894d 100644 --- a/admin.go +++ b/admin.go @@ -1,18 +1,15 @@ // Beego (http://beego.me/) -// // @description beego is an open-source, high-performance web framework for the Go programming language. -// // @link http://github.com/astaxie/beego for the canonical source repository -// // @license http://github.com/astaxie/beego/blob/master/LICENSE -// // @authors astaxie package beego import ( + "bytes" "fmt" "net/http" - "strconv" + "text/template" "time" "github.com/astaxie/beego/toolbox" @@ -49,7 +46,6 @@ func init() { beeAdminApp.Route("/prof", profIndex) beeAdminApp.Route("/healthcheck", healthcheck) beeAdminApp.Route("/task", taskStatus) - beeAdminApp.Route("/runtask", runTask) beeAdminApp.Route("/listconf", listConf) FilterMonitorFunc = func(string, string, time.Duration) bool { return true } } @@ -57,22 +53,22 @@ func init() { // AdminIndex is the default http.Handler for admin module. // it matches url pattern "/". func adminIndex(rw http.ResponseWriter, r *http.Request) { - rw.Write([]byte("beego admin dashboard")) - rw.Write([]byte("Welcome to Admin Dashboard
\n")) - rw.Write([]byte("There are servral functions:
\n")) - rw.Write([]byte("1. Record all request and request time, http://localhost:" + strconv.Itoa(AdminHttpPort) + "/qps
\n")) - rw.Write([]byte("2. Get runtime profiling data by the pprof, http://localhost:" + strconv.Itoa(AdminHttpPort) + "/prof
\n")) - rw.Write([]byte("3. Get healthcheck result from http://localhost:" + strconv.Itoa(AdminHttpPort) + "/healthcheck
\n")) - rw.Write([]byte("4. Get current task infomation from task http://localhost:" + strconv.Itoa(AdminHttpPort) + "/task
\n")) - rw.Write([]byte("5. To run a task passed a param http://localhost:" + strconv.Itoa(AdminHttpPort) + "/runtask
\n")) - rw.Write([]byte("6. Get all confige & router infomation http://localhost:" + strconv.Itoa(AdminHttpPort) + "/listconf
\n")) - rw.Write([]byte("")) + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(indexTpl)) + data := make(map[interface{}]interface{}) + tmpl.Execute(rw, data) } // QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter. // it's registered with url pattern "/qbs" in admin module. func qpsIndex(rw http.ResponseWriter, r *http.Request) { - toolbox.StatisticsMap.GetMap(rw) + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(qpsTpl)) + data := make(map[interface{}]interface{}) + data["Content"] = toolbox.StatisticsMap.GetMap() + + tmpl.Execute(rw, data) + } // ListConf is the http.Handler of displaying all beego configuration values as key/value pair. @@ -81,112 +77,217 @@ func listConf(rw http.ResponseWriter, r *http.Request) { r.ParseForm() command := r.Form.Get("command") if command != "" { + data := make(map[interface{}]interface{}) switch command { case "conf": - fmt.Fprintln(rw, "list all beego's conf:") - fmt.Fprintln(rw, "AppName:", AppName) - fmt.Fprintln(rw, "AppPath:", AppPath) - fmt.Fprintln(rw, "AppConfigPath:", AppConfigPath) - fmt.Fprintln(rw, "StaticDir:", StaticDir) - fmt.Fprintln(rw, "StaticExtensionsToGzip:", StaticExtensionsToGzip) - fmt.Fprintln(rw, "HttpAddr:", HttpAddr) - fmt.Fprintln(rw, "HttpPort:", HttpPort) - fmt.Fprintln(rw, "HttpTLS:", EnableHttpTLS) - fmt.Fprintln(rw, "HttpCertFile:", HttpCertFile) - fmt.Fprintln(rw, "HttpKeyFile:", HttpKeyFile) - fmt.Fprintln(rw, "RecoverPanic:", RecoverPanic) - fmt.Fprintln(rw, "AutoRender:", AutoRender) - fmt.Fprintln(rw, "ViewsPath:", ViewsPath) - fmt.Fprintln(rw, "RunMode:", RunMode) - fmt.Fprintln(rw, "SessionOn:", SessionOn) - fmt.Fprintln(rw, "SessionProvider:", SessionProvider) - fmt.Fprintln(rw, "SessionName:", SessionName) - fmt.Fprintln(rw, "SessionGCMaxLifetime:", SessionGCMaxLifetime) - fmt.Fprintln(rw, "SessionSavePath:", SessionSavePath) - fmt.Fprintln(rw, "SessionHashFunc:", SessionHashFunc) - fmt.Fprintln(rw, "SessionHashKey:", SessionHashKey) - fmt.Fprintln(rw, "SessionCookieLifeTime:", SessionCookieLifeTime) - fmt.Fprintln(rw, "UseFcgi:", UseFcgi) - fmt.Fprintln(rw, "MaxMemory:", MaxMemory) - fmt.Fprintln(rw, "EnableGzip:", EnableGzip) - fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex) - fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut) - fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow) - fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY) - fmt.Fprintln(rw, "EnableXSRF:", EnableXSRF) - fmt.Fprintln(rw, "XSRFExpire:", XSRFExpire) - fmt.Fprintln(rw, "CopyRequestBody:", CopyRequestBody) - fmt.Fprintln(rw, "TemplateLeft:", TemplateLeft) - fmt.Fprintln(rw, "TemplateRight:", TemplateRight) - fmt.Fprintln(rw, "BeegoServerName:", BeegoServerName) - fmt.Fprintln(rw, "EnableAdmin:", EnableAdmin) - fmt.Fprintln(rw, "AdminHttpAddr:", AdminHttpAddr) - fmt.Fprintln(rw, "AdminHttpPort:", AdminHttpPort) + m := make(map[string]interface{}) + + m["AppName"] = AppName + m["AppPath"] = AppPath + m["AppConfigPath"] = AppConfigPath + m["StaticDir"] = StaticDir + m["StaticExtensionsToGzip"] = StaticExtensionsToGzip + m["HttpAddr"] = HttpAddr + m["HttpPort"] = HttpPort + m["HttpTLS"] = EnableHttpTLS + m["HttpCertFile"] = HttpCertFile + m["HttpKeyFile"] = HttpKeyFile + m["RecoverPanic"] = RecoverPanic + m["AutoRender"] = AutoRender + m["ViewsPath"] = ViewsPath + m["RunMode"] = RunMode + m["SessionOn"] = SessionOn + m["SessionProvider"] = SessionProvider + m["SessionName"] = SessionName + m["SessionGCMaxLifetime"] = SessionGCMaxLifetime + m["SessionSavePath"] = SessionSavePath + m["SessionHashFunc"] = SessionHashFunc + m["SessionHashKey"] = SessionHashKey + m["SessionCookieLifeTime"] = SessionCookieLifeTime + m["UseFcgi"] = UseFcgi + m["MaxMemory"] = MaxMemory + m["EnableGzip"] = EnableGzip + m["DirectoryIndex"] = DirectoryIndex + m["HttpServerTimeOut"] = HttpServerTimeOut + m["ErrorsShow"] = ErrorsShow + m["XSRFKEY"] = XSRFKEY + m["EnableXSRF"] = EnableXSRF + m["XSRFExpire"] = XSRFExpire + m["CopyRequestBody"] = CopyRequestBody + m["TemplateLeft"] = TemplateLeft + m["TemplateRight"] = TemplateRight + m["BeegoServerName"] = BeegoServerName + m["EnableAdmin"] = EnableAdmin + m["AdminHttpAddr"] = AdminHttpAddr + m["AdminHttpPort"] = AdminHttpPort + + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(configTpl)) + + data["Content"] = m + + tmpl.Execute(rw, data) + case "router": - fmt.Fprintln(rw, "Print all router infomation:") - for method, t := range BeeApp.Handlers.routers { - fmt.Fprintln(rw) - fmt.Fprintln(rw) - fmt.Fprintln(rw, " Method:", method) - printTree(rw, t) + resultList := new([][]string) + + var result = []string{ + fmt.Sprintf("header"), + fmt.Sprintf("Router Pattern"), + fmt.Sprintf("Methods"), + fmt.Sprintf("Controller"), } - // @todo print routers + *resultList = append(*resultList, result) + + for method, t := range BeeApp.Handlers.routers { + var result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("Method: %s", method), + fmt.Sprintf(""), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) + + printTree(resultList, t) + } + data["Content"] = resultList + data["Title"] = "Routers" + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) + tmpl.Execute(rw, data) case "filter": - fmt.Fprintln(rw, "Print all filter infomation:") + resultList := new([][]string) + + var result = []string{ + fmt.Sprintf("header"), + fmt.Sprintf("Router Pattern"), + fmt.Sprintf("Filter Function"), + } + *resultList = append(*resultList, result) + if BeeApp.Handlers.enableFilter { - fmt.Fprintln(rw, "BeforeRouter:") + var result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("Before Router"), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) + if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok { for _, f := range bf { - fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc)) + + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", f.pattern), + fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), + } + *resultList = append(*resultList, result) + } } - fmt.Fprintln(rw, "BeforeExec:") + result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("Before Exec"), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok { for _, f := range bf { - fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc)) + + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", f.pattern), + fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), + } + *resultList = append(*resultList, result) + } } - fmt.Fprintln(rw, "AfterExec:") + result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("AfterExec Exec"), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) + if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok { for _, f := range bf { - fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc)) + + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", f.pattern), + fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), + } + *resultList = append(*resultList, result) + } } - fmt.Fprintln(rw, "FinishRouter:") + result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("Finish Router"), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) + if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok { for _, f := range bf { - fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc)) + + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", f.pattern), + fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), + } + *resultList = append(*resultList, result) + } } } + data["Content"] = resultList + data["Title"] = "Filters" + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) + tmpl.Execute(rw, data) + default: rw.Write([]byte("command not support")) } } else { - rw.Write([]byte("beego admin dashboard")) - rw.Write([]byte("ListConf support this command:
\n")) - rw.Write([]byte("1. command=conf
\n")) - rw.Write([]byte("2. command=router
\n")) - rw.Write([]byte("3. command=filter
\n")) - rw.Write([]byte("")) } } -func printTree(rw http.ResponseWriter, t *Tree) { +func printTree(resultList *[][]string, t *Tree) { for _, tr := range t.fixrouters { - printTree(rw, tr) + printTree(resultList, tr) } if t.wildcard != nil { - printTree(rw, t.wildcard) + printTree(resultList, t.wildcard) } for _, l := range t.leaves { if v, ok := l.runObject.(*controllerInfo); ok { if v.routerType == routerTypeBeego { - fmt.Fprintln(rw, v.pattern, v.methods, v.controllerType.Name()) + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", v.pattern), + fmt.Sprintf("%s", v.methods), + fmt.Sprintf("%s", v.controllerType), + } + *resultList = append(*resultList, result) } else if v.routerType == routerTypeRESTFul { - fmt.Fprintln(rw, v.pattern, v.methods) + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", v.pattern), + fmt.Sprintf("%s", v.methods), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) } else if v.routerType == routerTypeHandler { - fmt.Fprintln(rw, v.pattern, "handler") + var result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", v.pattern), + fmt.Sprintf(""), + fmt.Sprintf(""), + } + *resultList = append(*resultList, result) } } } @@ -197,58 +298,106 @@ func printTree(rw http.ResponseWriter, t *Tree) { func profIndex(rw http.ResponseWriter, r *http.Request) { r.ParseForm() command := r.Form.Get("command") + data := make(map[interface{}]interface{}) + + var result bytes.Buffer if command != "" { - toolbox.ProcessInput(command, rw) + toolbox.ProcessInput(command, &result) + data["Content"] = result.String() + data["Title"] = command + + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(profillingTpl)) + tmpl.Execute(rw, data) } else { - rw.Write([]byte("beego admin dashboard")) - rw.Write([]byte("request url like '/prof?command=lookup goroutine'
\n")) - rw.Write([]byte("the command have below types:
\n")) - rw.Write([]byte("1. lookup goroutine
\n")) - rw.Write([]byte("2. lookup heap
\n")) - rw.Write([]byte("3. lookup threadcreate
\n")) - rw.Write([]byte("4. lookup block
\n")) - rw.Write([]byte("5. start cpuprof
\n")) - rw.Write([]byte("6. stop cpuprof
\n")) - rw.Write([]byte("7. get memprof
\n")) - rw.Write([]byte("8. gc summary
\n")) - rw.Write([]byte("")) } } // Healthcheck is a http.Handler calling health checking and showing the result. // it's in "/healthcheck" pattern in admin module. func healthcheck(rw http.ResponseWriter, req *http.Request) { + data := make(map[interface{}]interface{}) + + resultList := new([][]string) + var result = []string{ + fmt.Sprintf("header"), + fmt.Sprintf("Name"), + fmt.Sprintf("Status"), + } + *resultList = append(*resultList, result) + for name, h := range toolbox.AdminCheckList { if err := h.Check(); err != nil { - fmt.Fprintf(rw, "%s : %s\n", name, err.Error()) + result = []string{ + fmt.Sprintf("error"), + fmt.Sprintf("%s", name), + fmt.Sprintf("%s", err.Error()), + } + } else { - fmt.Fprintf(rw, "%s : ok\n", name) + result = []string{ + fmt.Sprintf("success"), + fmt.Sprintf("%s", name), + fmt.Sprintf("OK"), + } + } + *resultList = append(*resultList, result) } + + data["Content"] = resultList + data["Title"] = "Health Check" + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(healthCheckTpl)) + tmpl.Execute(rw, data) + } // TaskStatus is a http.Handler with running task status (task name, status and the last execution). // it's in "/task" pattern in admin module. func taskStatus(rw http.ResponseWriter, req *http.Request) { - for tname, tk := range toolbox.AdminTaskList { - fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String()) - } -} + data := make(map[interface{}]interface{}) -// RunTask is a http.Handler to run a Task from the "query string. -// the request url likes /runtask?taskname=sendmail. -func runTask(rw http.ResponseWriter, req *http.Request) { + // Run Task req.ParseForm() taskname := req.Form.Get("taskname") - if t, ok := toolbox.AdminTaskList[taskname]; ok { - err := t.Run() - if err != nil { - fmt.Fprintf(rw, "%v", err) + if taskname != "" { + + if t, ok := toolbox.AdminTaskList[taskname]; ok { + err := t.Run() + if err != nil { + data["Message"] = []string{"error", fmt.Sprintf("%s", err)} + } + data["Message"] = []string{"success", fmt.Sprintf("%s run success,Now the Status is %s", taskname, t.GetStatus())} + } else { + data["Message"] = []string{"warning", fmt.Sprintf("there's no task which named: %s", taskname)} } - fmt.Fprintf(rw, "%s run success,Now the Status is %s", taskname, t.GetStatus()) - } else { - fmt.Fprintf(rw, "there's no task which named:%s", taskname) } + + // List Tasks + resultList := new([][]string) + var result = []string{ + fmt.Sprintf("header"), + fmt.Sprintf("Task Name"), + fmt.Sprintf("Task Spec"), + fmt.Sprintf("Task Function"), + } + *resultList = append(*resultList, result) + for tname, tk := range toolbox.AdminTaskList { + result = []string{ + fmt.Sprintf(""), + fmt.Sprintf("%s", tname), + fmt.Sprintf("%s", tk.GetStatus()), + fmt.Sprintf("%s", tk.GetPrev().String()), + } + *resultList = append(*resultList, result) + } + + data["Content"] = resultList + data["Title"] = "Tasks" + tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) + tmpl = template.Must(tmpl.Parse(tasksTpl)) + tmpl.Execute(rw, data) } // adminApp is an http.HandlerFunc map used as beeAdminApp. diff --git a/adminui.go b/adminui.go new file mode 100644 index 00000000..a030563a --- /dev/null +++ b/adminui.go @@ -0,0 +1,313 @@ +// Beego (http://beego.me/) +// @description beego is an open-source, high-performance web framework for the Go programming language. +// @link http://github.com/astaxie/beego for the canonical source repository +// @license http://github.com/astaxie/beego/blob/master/LICENSE +// @authors astaxie + +package beego + +var indexTpl = ` +{{define "content"}} +

Beego Admin Dashboard

+

+For detail usage please check our document: +

+

+Toolbox +

+

+Live Monitor +

+{{.Content}} +{{end}}` + +var profillingTpl = ` +{{define "content"}} +

{{.Title}}

+
+{{.Content}}
+
+{{end}}` + +var qpsTpl = ` +{{define "content"}} +

Requests statistics

+ +{{range $i, $slice := .Content}} + +{{range $j, $elem := $slice}} +{{if eq $i 0}} + +{{end}} +{{end}} + + +{{end}} +
+{{else}} + +{{end}} +{{$elem}} +{{if eq $i 0}} + +{{else}} +
+{{end}} +` + +var configTpl = ` +{{define "content"}} +

Configurations

+
+{{range $index, $elem := .Content}}
+{{$index}}={{$elem}}
+{{end}}
+
+{{end}} +` + +var routerAndFilterTpl = ` +{{define "content"}} + +

{{.Title}}

+ +{{range $i, $slice := .Content}} + + +{{ $header := index $slice 0}} +{{if eq "header" $header }} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} +{{else if eq "success" $header}} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} +{{else}} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} +{{end}} + + +{{end}} +
+ {{$elem}} + + {{$elem}} + + {{$elem}} +
+{{end}} +` + +var tasksTpl = ` +{{define "content"}} + +

{{.Title}}

+ +{{if .Message }} +{{ $messageType := index .Message 0}} +

+{{index .Message 1}} +

+{{end}} + + + +{{range $i, $slice := .Content}} + + +{{ $header := index $slice 0}} +{{if eq "header" $header }} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} + +{{else}} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} + +{{end}} + + +{{end}} +
+ {{$elem}} + + Run Task + + {{$elem}} + + Run +
+{{end}} +` + +var healthCheckTpl = ` +{{define "content"}} + +

{{.Title}}

+ +{{range $i, $slice := .Content}} + +{{ $header := index $slice 0}} +{{if eq "header" $header }} + + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} + +{{else}} + {{ if eq "success" $header}} + + {{else if eq "error" $header}} + + {{else}} + + {{end}} + {{range $j, $elem := $slice}} + {{if ne $j 0}} + + {{end}} + {{end}} + +{{end}} + +{{end}} +
+ {{$elem}} +
+ {{$elem}} +
+{{end}}` + +// The base dashboardTpl +var dashboardTpl = ` + + + + + + + + + + +Welcome to Beego Admin Dashboard + + + + + + + + + + + + +
+{{template "content" .}} +
+ + + + + + +` diff --git a/toolbox/statistics.go b/toolbox/statistics.go index fed8cc2b..e9ebc8f8 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -1,17 +1,12 @@ // Beego (http://beego.me/) -// // @description beego is an open-source, high-performance web framework for the Go programming language. -// // @link http://github.com/astaxie/beego for the canonical source repository -// // @license http://github.com/astaxie/beego/blob/master/LICENSE -// // @authors astaxie package toolbox import ( "fmt" - "io" "sync" "time" ) @@ -79,17 +74,29 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri } // put url statistics result in io.Writer -func (m *UrlMap) GetMap(rw io.Writer) { +func (m *UrlMap) GetMap() [][]string { m.lock.RLock() defer m.lock.RUnlock() - fmt.Fprintf(rw, "| % -50s| % -10s | % -16s | % -16s | % -16s | % -16s | % -16s |\n", "requestUrl", "method", "times", "used", "max used", "min used", "avg used") + resultLists := make([][]string, 0) + + var result = []string{"requestUrl", "method", "times", "used", "max used", "min used", "avg used"} + resultLists = append(resultLists, result) for k, v := range m.urlmap { for kk, vv := range v { - fmt.Fprintf(rw, "| % -50s| % -10s | % -16d | % -16s | % -16s | % -16s | % -16s |\n", k, - kk, vv.RequestNum, toS(vv.TotalTime), toS(vv.MaxTime), toS(vv.MinTime), toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum)), - ) + result := []string{ + fmt.Sprintf("% -50s", k), + fmt.Sprintf("% -10s", kk), + fmt.Sprintf("% -16d", vv.RequestNum), + fmt.Sprintf("% -16s", toS(vv.TotalTime)), + fmt.Sprintf("% -16s", toS(vv.MaxTime)), + fmt.Sprintf("% -16s", toS(vv.MinTime)), + fmt.Sprintf("% -16s", toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum))), + } + resultLists = append(resultLists, result) } } + fmt.Println(resultLists) + return resultLists } // global statistics data map From 75e2611cc4ae88e013dbd5d6ab7bd85dc831a255 Mon Sep 17 00:00:00 2001 From: smallfish Date: Thu, 14 Aug 2014 21:37:52 +0800 Subject: [PATCH 095/120] Update ctx.WriteString multiple buf output --- context/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 15a05c90..550b748f 100644 --- a/context/context.go +++ b/context/context.go @@ -62,7 +62,7 @@ func (ctx *Context) Abort(status int, body string) { // Write string to response body. // it sends response body. func (ctx *Context) WriteString(content string) { - ctx.Output.Body([]byte(content)) + ctx.ResponseWriter.Write([]byte(content)) } // Get cookie from request by a given key. From c347dd9e7b46c7ca24a29b48c0ec8f9d47c2d822 Mon Sep 17 00:00:00 2001 From: Lei Cao Date: Thu, 14 Aug 2014 23:50:15 +0800 Subject: [PATCH 096/120] Fix the comments and deleted the println --- admin.go | 4 ++++ adminui.go | 5 ++++- toolbox/statistics.go | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/admin.go b/admin.go index 93b1894d..c20ac7dc 100644 --- a/admin.go +++ b/admin.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) +// // @description beego is an open-source, high-performance web framework for the Go programming language. +// // @link http://github.com/astaxie/beego for the canonical source repository +// // @license http://github.com/astaxie/beego/blob/master/LICENSE +// // @authors astaxie package beego diff --git a/adminui.go b/adminui.go index a030563a..0c5a25d5 100644 --- a/adminui.go +++ b/adminui.go @@ -1,9 +1,12 @@ // Beego (http://beego.me/) +// // @description beego is an open-source, high-performance web framework for the Go programming language. +// // @link http://github.com/astaxie/beego for the canonical source repository +// // @license http://github.com/astaxie/beego/blob/master/LICENSE +// // @authors astaxie - package beego var indexTpl = ` diff --git a/toolbox/statistics.go b/toolbox/statistics.go index e9ebc8f8..0ca31473 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -1,7 +1,11 @@ // Beego (http://beego.me/) +// // @description beego is an open-source, high-performance web framework for the Go programming language. +// // @link http://github.com/astaxie/beego for the canonical source repository +// // @license http://github.com/astaxie/beego/blob/master/LICENSE +// // @authors astaxie package toolbox @@ -95,7 +99,6 @@ func (m *UrlMap) GetMap() [][]string { resultLists = append(resultLists, result) } } - fmt.Println(resultLists) return resultLists } From 7d1b03ee5d266249bc4b9a83444b3782e12fc847 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 00:14:30 +0800 Subject: [PATCH 097/120] toolbox: fix the test case --- toolbox/statistics_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toolbox/statistics_test.go b/toolbox/statistics_test.go index fc6e4dce..1649019c 100644 --- a/toolbox/statistics_test.go +++ b/toolbox/statistics_test.go @@ -10,7 +10,6 @@ package toolbox import ( - "os" "testing" "time" ) @@ -23,5 +22,5 @@ func TestStatics(t *testing.T) { StatisticsMap.AddStatistics("POST", "/api/user/astaxie", "&admin.user", time.Duration(12000)) StatisticsMap.AddStatistics("POST", "/api/user/xiemengjun", "&admin.user", time.Duration(13000)) StatisticsMap.AddStatistics("DELETE", "/api/user", "&admin.user", time.Duration(1400)) - StatisticsMap.GetMap(os.Stdout) + t.Log(StatisticsMap.GetMap()) } From 17006cfb26e7037aa5f02b3c3118f1b7fc220b7e Mon Sep 17 00:00:00 2001 From: Lei Cao Date: Fri, 15 Aug 2014 14:24:55 +0800 Subject: [PATCH 098/120] ajax refresh gc message --- admin.go | 31 +++++++++++++++++++++++++++++-- adminui.go | 29 +++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/admin.go b/admin.go index c20ac7dc..9b2f3dc3 100644 --- a/admin.go +++ b/admin.go @@ -11,6 +11,7 @@ package beego import ( "bytes" + "encoding/json" "fmt" "net/http" "text/template" @@ -59,6 +60,7 @@ func init() { func adminIndex(rw http.ResponseWriter, r *http.Request) { tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(indexTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) data := make(map[interface{}]interface{}) tmpl.Execute(rw, data) } @@ -68,6 +70,7 @@ func adminIndex(rw http.ResponseWriter, r *http.Request) { func qpsIndex(rw http.ResponseWriter, r *http.Request) { tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(qpsTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) data := make(map[interface{}]interface{}) data["Content"] = toolbox.StatisticsMap.GetMap() @@ -127,6 +130,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) { tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(configTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) data["Content"] = m @@ -158,6 +162,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) { data["Title"] = "Routers" tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) tmpl.Execute(rw, data) case "filter": resultList := new([][]string) @@ -250,6 +255,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) { data["Title"] = "Filters" tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) tmpl.Execute(rw, data) default: @@ -302,16 +308,35 @@ func printTree(resultList *[][]string, t *Tree) { func profIndex(rw http.ResponseWriter, r *http.Request) { r.ParseForm() command := r.Form.Get("command") - data := make(map[interface{}]interface{}) + format := r.Form.Get("format") + data := make(map[string]interface{}) var result bytes.Buffer if command != "" { toolbox.ProcessInput(command, &result) data["Content"] = result.String() - data["Title"] = command + if format == "json" && command == "gc summary" { + dataJson, err := json.Marshal(data) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + rw.Header().Set("Content-Type", "application/json") + rw.Write(dataJson) + return + } + + data["Title"] = command tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(profillingTpl)) + if command == "gc summary" { + tmpl = template.Must(tmpl.Parse(gcAjaxTpl)) + } else { + + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) + } tmpl.Execute(rw, data) } else { } @@ -353,6 +378,7 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) { data["Title"] = "Health Check" tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(healthCheckTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) tmpl.Execute(rw, data) } @@ -401,6 +427,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { data["Title"] = "Tasks" tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) tmpl = template.Must(tmpl.Parse(tasksTpl)) + tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) tmpl.Execute(rw, data) } diff --git a/adminui.go b/adminui.go index 0c5a25d5..d84cb2a4 100644 --- a/adminui.go +++ b/adminui.go @@ -27,11 +27,35 @@ For detail usage please check our document: var profillingTpl = ` {{define "content"}}

{{.Title}}

-
-{{.Content}}
+
+
{{.Content}}
{{end}}` +var defaultScriptsTpl = `` + +var gcAjaxTpl = ` +{{define "scripts"}} + +{{end}} +` + var qpsTpl = ` {{define "content"}}

Requests statistics

@@ -311,6 +335,7 @@ Healthcheck +{{template "scripts" .}} ` From 3969cd3b40190be51fc0d3ed9f88f37c1543cdb8 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 15:09:59 +0800 Subject: [PATCH 099/120] toolbox: improve the profile --- toolbox/profile.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/toolbox/profile.go b/toolbox/profile.go index 0e0aaa40..da14f0b0 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -13,6 +13,7 @@ import ( "fmt" "io" "log" + "net/http" "os" "runtime" "runtime/debug" @@ -43,40 +44,48 @@ func ProcessInput(input string, w io.Writer) { case "lookup block": p := pprof.Lookup("block") p.WriteTo(w, 2) - case "start cpuprof": - StartCPUProfile() - case "stop cpuprof": - StopCPUProfile() + case "get cpuprof": + GetCPUProfile(w.(http.ResponseWriter)) case "get memprof": - MemProf() + MemProf(w) case "gc summary": PrintGCSummary(w) } } // record memory profile in pprof -func MemProf() { - if f, err := os.Create("mem-" + strconv.Itoa(pid) + ".memprof"); err != nil { - log.Fatal("record memory profile failed: ", err) +func MemProf(w io.Writer) { + filename := "mem-" + strconv.Itoa(pid) + ".memprof" + if f, err := os.Create(filename); err != nil { + fmt.Fprintf(w, "create file %s error %s\n", filename, err.Error()) + log.Fatal("record heap profile failed: ", err) } else { runtime.GC() pprof.WriteHeapProfile(f) f.Close() + fmt.Fprintf(w, "create heap profile %s \n", filename) + fmt.Fprintf(w, "Now you can use this to check it: go tool pprof %s\n", filename) } } // start cpu profile monitor -func StartCPUProfile() { - f, err := os.Create("cpu-" + strconv.Itoa(pid) + ".pprof") +func GetCPUProfile(rw http.ResponseWriter) { + sec := 30 + rw.Header().Set("Content-Type", "application/octet-stream") + filename := "cpu-" + strconv.Itoa(pid) + ".pprof" + f, err := os.Create(filename) if err != nil { - log.Fatal(err) + rw.Header().Set("Content-Type", "text/plain; charset=utf-8") + rw.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(rw, "Could not enable CPU profiling: %s\n", err) + log.Fatal("record cpu profile failed: ", err) } + fmt.Fprintf(rw, "start cpu profileing\n") pprof.StartCPUProfile(f) -} - -// stop cpu profile monitor -func StopCPUProfile() { + time.Sleep(time.Duration(sec) * time.Second) pprof.StopCPUProfile() + fmt.Fprintf(rw, "create cpu profile %s \n", filename) + fmt.Fprintf(rw, "Now you can use this to check it: go tool pprof %s\n", filename) } // print gc information to io.Writer From cad3da337a5c040ebcbdd0d02363f767d3300464 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 15:17:11 +0800 Subject: [PATCH 100/120] toolbox: fix the program name --- toolbox/profile.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/toolbox/profile.go b/toolbox/profile.go index da14f0b0..3283fd4d 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -15,6 +15,7 @@ import ( "log" "net/http" "os" + "path" "runtime" "runtime/debug" "runtime/pprof" @@ -64,7 +65,8 @@ func MemProf(w io.Writer) { pprof.WriteHeapProfile(f) f.Close() fmt.Fprintf(w, "create heap profile %s \n", filename) - fmt.Fprintf(w, "Now you can use this to check it: go tool pprof %s\n", filename) + _, fl := path.Split(os.Args[0]) + fmt.Fprintf(w, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename) } } @@ -85,7 +87,8 @@ func GetCPUProfile(rw http.ResponseWriter) { time.Sleep(time.Duration(sec) * time.Second) pprof.StopCPUProfile() fmt.Fprintf(rw, "create cpu profile %s \n", filename) - fmt.Fprintf(rw, "Now you can use this to check it: go tool pprof %s\n", filename) + _, fl := path.Split(os.Args[0]) + fmt.Fprintf(rw, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename) } // print gc information to io.Writer From b611b9dab6b68edce4a51a02338f50f58825d174 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 15:19:35 +0800 Subject: [PATCH 101/120] change the adminui link --- adminui.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adminui.go b/adminui.go index d84cb2a4..241fd5ea 100644 --- a/adminui.go +++ b/adminui.go @@ -297,8 +297,7 @@ Requests statistics
  • lookup heap
  • lookup threadcreate
  • lookup block
  • -
  • start cpuprof
  • -
  • stop cpuprof
  • +
  • get cpuprof
  • get memprof
  • gc summary
  • From c1234e7c6deb5987368843d13881aab6221d23c7 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 15:24:46 +0800 Subject: [PATCH 102/120] fix the responseWriter --- toolbox/profile.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/toolbox/profile.go b/toolbox/profile.go index 3283fd4d..a4e4b155 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -13,7 +13,6 @@ import ( "fmt" "io" "log" - "net/http" "os" "path" "runtime" @@ -46,7 +45,7 @@ func ProcessInput(input string, w io.Writer) { p := pprof.Lookup("block") p.WriteTo(w, 2) case "get cpuprof": - GetCPUProfile(w.(http.ResponseWriter)) + GetCPUProfile(w) case "get memprof": MemProf(w) case "gc summary": @@ -71,24 +70,21 @@ func MemProf(w io.Writer) { } // start cpu profile monitor -func GetCPUProfile(rw http.ResponseWriter) { +func GetCPUProfile(w io.Writer) { sec := 30 - rw.Header().Set("Content-Type", "application/octet-stream") filename := "cpu-" + strconv.Itoa(pid) + ".pprof" f, err := os.Create(filename) if err != nil { - rw.Header().Set("Content-Type", "text/plain; charset=utf-8") - rw.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(rw, "Could not enable CPU profiling: %s\n", err) + fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err) log.Fatal("record cpu profile failed: ", err) } - fmt.Fprintf(rw, "start cpu profileing\n") pprof.StartCPUProfile(f) time.Sleep(time.Duration(sec) * time.Second) pprof.StopCPUProfile() - fmt.Fprintf(rw, "create cpu profile %s \n", filename) + + fmt.Fprintf(w, "create cpu profile %s \n", filename) _, fl := path.Split(os.Args[0]) - fmt.Fprintf(rw, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename) + fmt.Fprintf(w, "Now you can use this to check it: go tool pprof %s %s\n", fl, filename) } // print gc information to io.Writer From cd9e614a7141e1b7a03d0a6e7d555ba1bbc375c9 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 15 Aug 2014 17:15:20 +0800 Subject: [PATCH 103/120] plugins: basic auth & cors --- plugins/auth/basic.go | 67 ++++++---- plugins/cors/cors.go | 229 ++++++++++++++++++++++++++++++++++ plugins/cors/cors_test.go | 253 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 525 insertions(+), 24 deletions(-) create mode 100644 plugins/cors/cors.go create mode 100644 plugins/cors/cors_test.go diff --git a/plugins/auth/basic.go b/plugins/auth/basic.go index feafc0c9..98e4864f 100644 --- a/plugins/auth/basic.go +++ b/plugins/auth/basic.go @@ -1,23 +1,38 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie -package auth +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -// Example: +// Package auth provides handlers to enable basic auth support. +// Simple Usage: +// import( +// "github.com/astaxie/beego" +// "github.com/astaxie/beego/plugins/auth" +// ) +// +// func main(){ +// // authenticate every request +// beego.InsertFilter("*", beego.BeforeRouter,auth.Basic("username","secretpassword")) +// beego.Run() +// } +// +// +// Advanced Usage: // func SecretAuth(username, password string) bool { -// if username == "astaxie" && password == "helloBeego" { -// return true -// } -// return false +// return username == "astaxie" && password == "helloBeego" // } -// authPlugin := auth.NewBasicAuthenticator(SecretAuth, "My Realm") +// authPlugin := auth.NewBasicAuthenticator(SecretAuth, "Authorization Required") // beego.InsertFilter("*", beego.BeforeRouter,authPlugin) +package auth import ( "encoding/base64" @@ -28,6 +43,15 @@ import ( "github.com/astaxie/beego/context" ) +var defaultRealm = "Authorization Required" + +func Basic(username string, password string) beego.FilterFunc { + secrets := func(user, pass string) bool { + return user == username && pass == password + } + return NewBasicAuthenticator(secrets, defaultRealm) +} + func NewBasicAuthenticator(secrets SecretProvider, Realm string) beego.FilterFunc { return func(ctx *context.Context) { a := &BasicAuth{Secrets: secrets, Realm: Realm} @@ -44,13 +68,10 @@ type BasicAuth struct { Realm string } -/* - Checks the username/password combination from the request. Returns - either an empty string (authentication failed) or the name of the - authenticated user. - - Supports MD5 and SHA1 password entries -*/ +//Checks the username/password combination from the request. Returns +//either an empty string (authentication failed) or the name of the +//authenticated user. +//Supports MD5 and SHA1 password entries func (a *BasicAuth) CheckAuth(r *http.Request) string { s := strings.SplitN(r.Header.Get("Authorization"), " ", 2) if len(s) != 2 || s[0] != "Basic" { @@ -72,10 +93,8 @@ func (a *BasicAuth) CheckAuth(r *http.Request) string { return "" } -/* - http.Handler for BasicAuth which initiates the authentication process - (or requires reauthentication). -*/ +//http.Handler for BasicAuth which initiates the authentication process +//(or requires reauthentication). func (a *BasicAuth) RequireAuth(w http.ResponseWriter, r *http.Request) { w.Header().Set("WWW-Authenticate", `Basic realm="`+a.Realm+`"`) w.WriteHeader(401) diff --git a/plugins/cors/cors.go b/plugins/cors/cors.go new file mode 100644 index 00000000..c8de8250 --- /dev/null +++ b/plugins/cors/cors.go @@ -0,0 +1,229 @@ +// Copyright 2014 beego Author. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package cors provides handlers to enable CORS support. +// Usage +// +// import ( +// "github.com/astaxie/beego" +// "github.com/astaxie/beego/plugins/cors" +// ) + +//func main() { +// // CORS for https://foo.* origins, allowing: +// // - PUT and PATCH methods +// // - Origin header +// // - Credentials share +// beego.InsertFilter("*", beego.BeforeRouter,cors.Allow(&cors.Options{ +// AllowOrigins: []string{"https://*.foo.com"}, +// AllowMethods: []string{"PUT", "PATCH"}, +// AllowHeaders: []string{"Origin"}, +// ExposeHeaders: []string{"Content-Length"}, +// AllowCredentials: true, +// })) +// beego.Run() +//} +package cors + +import ( + "net/http" + "regexp" + "strconv" + "strings" + "time" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/context" +) + +const ( + headerAllowOrigin = "Access-Control-Allow-Origin" + headerAllowCredentials = "Access-Control-Allow-Credentials" + headerAllowHeaders = "Access-Control-Allow-Headers" + headerAllowMethods = "Access-Control-Allow-Methods" + headerExposeHeaders = "Access-Control-Expose-Headers" + headerMaxAge = "Access-Control-Max-Age" + + headerOrigin = "Origin" + headerRequestMethod = "Access-Control-Request-Method" + headerRequestHeaders = "Access-Control-Request-Headers" +) + +var ( + defaultAllowHeaders = []string{"Origin", "Accept", "Content-Type", "Authorization"} + // Regex patterns are generated from AllowOrigins. These are used and generated internally. + allowOriginPatterns = []string{} +) + +// Options represents Access Control options. +type Options struct { + // If set, all origins are allowed. + AllowAllOrigins bool + // A list of allowed origins. Wild cards and FQDNs are supported. + AllowOrigins []string + // If set, allows to share auth credentials such as cookies. + AllowCredentials bool + // A list of allowed HTTP methods. + AllowMethods []string + // A list of allowed HTTP headers. + AllowHeaders []string + // A list of exposed HTTP headers. + ExposeHeaders []string + // Max age of the CORS headers. + MaxAge time.Duration +} + +// Header converts options into CORS headers. +func (o *Options) Header(origin string) (headers map[string]string) { + headers = make(map[string]string) + // if origin is not allowed, don't extend the headers + // with CORS headers. + if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { + return + } + + // add allow origin + if o.AllowAllOrigins { + headers[headerAllowOrigin] = "*" + } else { + headers[headerAllowOrigin] = origin + } + + // add allow credentials + headers[headerAllowCredentials] = strconv.FormatBool(o.AllowCredentials) + + // add allow methods + if len(o.AllowMethods) > 0 { + headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") + } + + // add allow headers + if len(o.AllowHeaders) > 0 { + headers[headerAllowHeaders] = strings.Join(o.AllowHeaders, ",") + } + + // add exposed header + if len(o.ExposeHeaders) > 0 { + headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") + } + // add a max age header + if o.MaxAge > time.Duration(0) { + headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) + } + return +} + +// PreflightHeader converts options into CORS headers for a preflight response. +func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string) { + headers = make(map[string]string) + if !o.AllowAllOrigins && !o.IsOriginAllowed(origin) { + return + } + // verify if requested method is allowed + for _, method := range o.AllowMethods { + if method == rMethod { + headers[headerAllowMethods] = strings.Join(o.AllowMethods, ",") + break + } + } + + // verify if requested headers are allowed + var allowed []string + for _, rHeader := range strings.Split(rHeaders, ",") { + rHeader = strings.TrimSpace(rHeader) + lookupLoop: + for _, allowedHeader := range o.AllowHeaders { + if strings.ToLower(rHeader) == strings.ToLower(allowedHeader) { + allowed = append(allowed, rHeader) + break lookupLoop + } + } + } + + headers[headerAllowCredentials] = strconv.FormatBool(o.AllowCredentials) + // add allow origin + if o.AllowAllOrigins { + headers[headerAllowOrigin] = "*" + } else { + headers[headerAllowOrigin] = origin + } + + // add allowed headers + if len(allowed) > 0 { + headers[headerAllowHeaders] = strings.Join(allowed, ",") + } + + // add exposed headers + if len(o.ExposeHeaders) > 0 { + headers[headerExposeHeaders] = strings.Join(o.ExposeHeaders, ",") + } + // add a max age header + if o.MaxAge > time.Duration(0) { + headers[headerMaxAge] = strconv.FormatInt(int64(o.MaxAge/time.Second), 10) + } + return +} + +// IsOriginAllowed looks up if the origin matches one of the patterns +// generated from Options.AllowOrigins patterns. +func (o *Options) IsOriginAllowed(origin string) (allowed bool) { + for _, pattern := range allowOriginPatterns { + allowed, _ = regexp.MatchString(pattern, origin) + if allowed { + return + } + } + return +} + +// Allow enables CORS for requests those match the provided options. +func Allow(opts *Options) beego.FilterFunc { + // Allow default headers if nothing is specified. + if len(opts.AllowHeaders) == 0 { + opts.AllowHeaders = defaultAllowHeaders + } + + for _, origin := range opts.AllowOrigins { + pattern := regexp.QuoteMeta(origin) + pattern = strings.Replace(pattern, "\\*", ".*", -1) + pattern = strings.Replace(pattern, "\\?", ".", -1) + allowOriginPatterns = append(allowOriginPatterns, "^"+pattern+"$") + } + + return func(ctx *context.Context) { + var ( + origin = ctx.Input.Header(headerOrigin) + requestedMethod = ctx.Input.Header(headerRequestMethod) + requestedHeaders = ctx.Input.Header(headerRequestHeaders) + // additional headers to be added + // to the response. + headers map[string]string + ) + + if ctx.Input.Method() == "OPTIONS" && + (requestedMethod != "" || requestedHeaders != "") { + headers = opts.PreflightHeader(origin, requestedMethod, requestedHeaders) + for key, value := range headers { + ctx.Output.Header(key, value) + } + ctx.Output.SetStatus(http.StatusOK) + return + } + headers = opts.Header(origin) + + for key, value := range headers { + ctx.Output.Header(key, value) + } + } +} diff --git a/plugins/cors/cors_test.go b/plugins/cors/cors_test.go new file mode 100644 index 00000000..0ed468fe --- /dev/null +++ b/plugins/cors/cors_test.go @@ -0,0 +1,253 @@ +// Copyright 2014 beego Author. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package cors provides handlers to enable CORS support. +package cors + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/context" +) + +type HttpHeaderGuardRecorder struct { + *httptest.ResponseRecorder + savedHeaderMap http.Header +} + +func NewRecorder() *HttpHeaderGuardRecorder { + return &HttpHeaderGuardRecorder{httptest.NewRecorder(), nil} +} + +func (gr *HttpHeaderGuardRecorder) WriteHeader(code int) { + gr.ResponseRecorder.WriteHeader(code) + gr.savedHeaderMap = gr.ResponseRecorder.Header() +} + +func (gr *HttpHeaderGuardRecorder) Header() http.Header { + if gr.savedHeaderMap != nil { + // headers were written. clone so we don't get updates + clone := make(http.Header) + for k, v := range gr.savedHeaderMap { + clone[k] = v + } + return clone + } else { + return gr.ResponseRecorder.Header() + } +} + +func Test_AllowAll(t *testing.T) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowAllOrigins: true, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + r, _ := http.NewRequest("PUT", "/foo", nil) + handler.ServeHTTP(recorder, r) + + if recorder.HeaderMap.Get(headerAllowOrigin) != "*" { + t.Errorf("Allow-Origin header should be *") + } +} + +func Test_AllowRegexMatch(t *testing.T) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowOrigins: []string{"https://aaa.com", "https://*.foo.com"}, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + origin := "https://bar.foo.com" + r, _ := http.NewRequest("PUT", "/foo", nil) + r.Header.Add("Origin", origin) + handler.ServeHTTP(recorder, r) + + headerValue := recorder.HeaderMap.Get(headerAllowOrigin) + if headerValue != origin { + t.Errorf("Allow-Origin header should be %v, found %v", origin, headerValue) + } +} + +func Test_AllowRegexNoMatch(t *testing.T) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowOrigins: []string{"https://*.foo.com"}, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + origin := "https://ww.foo.com.evil.com" + r, _ := http.NewRequest("PUT", "/foo", nil) + r.Header.Add("Origin", origin) + handler.ServeHTTP(recorder, r) + + headerValue := recorder.HeaderMap.Get(headerAllowOrigin) + if headerValue != "" { + t.Errorf("Allow-Origin header should not exist, found %v", headerValue) + } +} + +func Test_OtherHeaders(t *testing.T) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowAllOrigins: true, + AllowCredentials: true, + AllowMethods: []string{"PATCH", "GET"}, + AllowHeaders: []string{"Origin", "X-whatever"}, + ExposeHeaders: []string{"Content-Length", "Hello"}, + MaxAge: 5 * time.Minute, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + r, _ := http.NewRequest("PUT", "/foo", nil) + handler.ServeHTTP(recorder, r) + + credentialsVal := recorder.HeaderMap.Get(headerAllowCredentials) + methodsVal := recorder.HeaderMap.Get(headerAllowMethods) + headersVal := recorder.HeaderMap.Get(headerAllowHeaders) + exposedHeadersVal := recorder.HeaderMap.Get(headerExposeHeaders) + maxAgeVal := recorder.HeaderMap.Get(headerMaxAge) + + if credentialsVal != "true" { + t.Errorf("Allow-Credentials is expected to be true, found %v", credentialsVal) + } + + if methodsVal != "PATCH,GET" { + t.Errorf("Allow-Methods is expected to be PATCH,GET; found %v", methodsVal) + } + + if headersVal != "Origin,X-whatever" { + t.Errorf("Allow-Headers is expected to be Origin,X-whatever; found %v", headersVal) + } + + if exposedHeadersVal != "Content-Length,Hello" { + t.Errorf("Expose-Headers are expected to be Content-Length,Hello. Found %v", exposedHeadersVal) + } + + if maxAgeVal != "300" { + t.Errorf("Max-Age is expected to be 300, found %v", maxAgeVal) + } +} + +func Test_DefaultAllowHeaders(t *testing.T) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowAllOrigins: true, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + + r, _ := http.NewRequest("PUT", "/foo", nil) + handler.ServeHTTP(recorder, r) + + headersVal := recorder.HeaderMap.Get(headerAllowHeaders) + if headersVal != "Origin,Accept,Content-Type,Authorization" { + t.Errorf("Allow-Headers is expected to be Origin,Accept,Content-Type,Authorization; found %v", headersVal) + } +} + +func Test_Preflight(t *testing.T) { + recorder := NewRecorder() + handler := beego.NewControllerRegister() + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowAllOrigins: true, + AllowMethods: []string{"PUT", "PATCH"}, + AllowHeaders: []string{"Origin", "X-whatever", "X-CaseSensitive"}, + })) + + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(200) + }) + + r, _ := http.NewRequest("OPTIONS", "/foo", nil) + r.Header.Add(headerRequestMethod, "PUT") + r.Header.Add(headerRequestHeaders, "X-whatever, x-casesensitive") + handler.ServeHTTP(recorder, r) + + headers := recorder.Header() + methodsVal := headers.Get(headerAllowMethods) + headersVal := headers.Get(headerAllowHeaders) + originVal := headers.Get(headerAllowOrigin) + + if methodsVal != "PUT,PATCH" { + t.Errorf("Allow-Methods is expected to be PUT,PATCH, found %v", methodsVal) + } + + if !strings.Contains(headersVal, "X-whatever") { + t.Errorf("Allow-Headers is expected to contain X-whatever, found %v", headersVal) + } + + if !strings.Contains(headersVal, "x-casesensitive") { + t.Errorf("Allow-Headers is expected to contain x-casesensitive, found %v", headersVal) + } + + if originVal != "*" { + t.Errorf("Allow-Origin is expected to be *, found %v", originVal) + } + + if recorder.Code != http.StatusOK { + t.Errorf("Status code is expected to be 200, found %d", recorder.Code) + } +} + +func Benchmark_WithoutCORS(b *testing.B) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + beego.RunMode = "prod" + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + b.ResetTimer() + for i := 0; i < 100; i++ { + r, _ := http.NewRequest("PUT", "/foo", nil) + handler.ServeHTTP(recorder, r) + } +} + +func Benchmark_WithCORS(b *testing.B) { + recorder := httptest.NewRecorder() + handler := beego.NewControllerRegister() + beego.RunMode = "prod" + handler.InsertFilter("*", beego.BeforeRouter, Allow(&Options{ + AllowAllOrigins: true, + AllowCredentials: true, + AllowMethods: []string{"PATCH", "GET"}, + AllowHeaders: []string{"Origin", "X-whatever"}, + MaxAge: 5 * time.Minute, + })) + handler.Any("/foo", func(ctx *context.Context) { + ctx.Output.SetStatus(500) + }) + b.ResetTimer() + for i := 0; i < 100; i++ { + r, _ := http.NewRequest("PUT", "/foo", nil) + handler.ServeHTTP(recorder, r) + } +} From 75904effd9ba7201a7bb0acd42f0c9d832025adf Mon Sep 17 00:00:00 2001 From: Francois Date: Fri, 15 Aug 2014 21:11:16 +0200 Subject: [PATCH 104/120] Makes more sense to Use Debug instead of Info? --- router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.go b/router.go index 03eb5e83..51b08235 100644 --- a/router.go +++ b/router.go @@ -773,7 +773,7 @@ Admin: } else { devinfo = fmt.Sprintf("| % -10s| % -16s | % -10s | % -40s | % -10s |", "beego", timeend.String(), r.Method, r.URL.Path, "notmatch") } - Info(devinfo) + Debug(devinfo) } // Call WriteHeader if status code has been set changed From 1dbbb89ad1c39b42da8fe2be6e605c6df6139735 Mon Sep 17 00:00:00 2001 From: Francois Date: Fri, 15 Aug 2014 21:12:57 +0200 Subject: [PATCH 105/120] To match with logs/log.go (and RFC 5424 specs) --- log.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/log.go b/log.go index 2a6793b0..accbd97d 100644 --- a/log.go +++ b/log.go @@ -17,12 +17,14 @@ import ( // Log levels to control the logging output. const ( - LevelTrace = iota - LevelDebug - LevelInfo - LevelWarning - LevelError + LevelEmergency = iota + LevelAlert LevelCritical + LevelError + LevelWarning + LevelNotice + LevelInformational + LevelDebug ) // SetLogLevel sets the global log level used by the simple From 7be811461604699a516f991eac1529559cca87a4 Mon Sep 17 00:00:00 2001 From: Francois Date: Fri, 15 Aug 2014 21:30:59 +0200 Subject: [PATCH 106/120] To match with logs/log.go (and RFC 5424 specs) --- log.go | 77 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/log.go b/log.go index 2a6793b0..d888b17a 100644 --- a/log.go +++ b/log.go @@ -17,12 +17,14 @@ import ( // Log levels to control the logging output. const ( - LevelTrace = iota - LevelDebug - LevelInfo - LevelWarning - LevelError + LevelEmergency = iota + LevelAlert LevelCritical + LevelError + LevelWarning + LevelNotice + LevelInformational + LevelDebug ) // SetLogLevel sets the global log level used by the simple @@ -48,29 +50,12 @@ func SetLogger(adaptername string, config string) error { return nil } -// Trace logs a message at trace level. -func Trace(v ...interface{}) { - BeeLogger.Trace(generateFmtStr(len(v)), v...) +func Emergency(v ...interface{}) { + BeeLogger.Emergency(generateFmtStr(len(v)), v...) } -// Debug logs a message at debug level. -func Debug(v ...interface{}) { - BeeLogger.Debug(generateFmtStr(len(v)), v...) -} - -// Info logs a message at info level. -func Info(v ...interface{}) { - BeeLogger.Info(generateFmtStr(len(v)), v...) -} - -// Warning logs a message at warning level. -func Warn(v ...interface{}) { - BeeLogger.Warn(generateFmtStr(len(v)), v...) -} - -// Error logs a message at error level. -func Error(v ...interface{}) { - BeeLogger.Error(generateFmtStr(len(v)), v...) +func Alert(v ...interface{}) { + BeeLogger.Alert(generateFmtStr(len(v)), v...) } // Critical logs a message at critical level. @@ -78,6 +63,46 @@ func Critical(v ...interface{}) { BeeLogger.Critical(generateFmtStr(len(v)), v...) } +// Error logs a message at error level. +func Error(v ...interface{}) { + BeeLogger.Error(generateFmtStr(len(v)), v...) +} + +// Warning logs a message at warning level. +func Warning(v ...interface{}) { + BeeLogger.Warning(generateFmtStr(len(v)), v...) +} + +// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. +func Warn(v ...interface{}) { + Warning(v...) +} + +func Notice(v ...interface{}) { + BeeLogger.Notice(generateFmtStr(len(v)), v...) +} + +// Info logs a message at info level. +func Informational(v ...interface{}) { + BeeLogger.Informational(generateFmtStr(len(v)), v...) +} + +// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. +func Info(v ...interface{}) { + Informational(v...) +} + +// Debug logs a message at debug level. +func Debug(v ...interface{}) { + BeeLogger.Debug(generateFmtStr(len(v)), v...) +} + +// Trace logs a message at trace level. +// Deprecated: compatibility alias for Warning(), Will be removed in 1.5.0. +func Trace(v ...interface{}) { + BeeLogger.Trace(generateFmtStr(len(v)), v...) +} + func generateFmtStr(n int) string { return strings.Repeat("%v ", n) } From d27c5c8daf715b92cd2e61062d89cce802370d2c Mon Sep 17 00:00:00 2001 From: smallfish Date: Sun, 17 Aug 2014 21:13:29 +0800 Subject: [PATCH 107/120] Remove some unnecessary code --- httplib/httplib.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index 53b8e6ca..ca012502 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -395,10 +395,7 @@ func (b *BeegoHttpRequest) ToFile(filename string) error { } defer resp.Body.Close() _, err = io.Copy(f, resp.Body) - if err != nil { - return err - } - return nil + return err } // ToJson returns the map that marshals from the body bytes as json in response . @@ -409,10 +406,7 @@ func (b *BeegoHttpRequest) ToJson(v interface{}) error { return err } err = json.Unmarshal(data, v) - if err != nil { - return err - } - return nil + return err } // ToXml returns the map that marshals from the body bytes as xml in response . @@ -423,10 +417,7 @@ func (b *BeegoHttpRequest) ToXML(v interface{}) error { return err } err = xml.Unmarshal(data, v) - if err != nil { - return err - } - return nil + return err } // Response executes request client gets response mannually. From 986e91b7d65323b68ef1d93330776476e9ca0613 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 14:35:39 +0800 Subject: [PATCH 108/120] beego: update the debug info rules --- router.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/router.go b/router.go index 51b08235..dee96111 100644 --- a/router.go +++ b/router.go @@ -591,6 +591,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) serverStaticRouter(context) if w.started { + findrouter = true goto Admin } @@ -769,9 +770,9 @@ Admin: if RunMode == "dev" { var devinfo string if findrouter { - devinfo = fmt.Sprintf("| % -10s| % -16s | % -10s | % -40s | % -10s | % -40s |", "beego", timeend.String(), r.Method, r.URL.Path, "match", routerInfo.pattern) + devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s | % -40s |", r.Method, r.URL.Path, timeend.String(), "match", routerInfo.pattern) } else { - devinfo = fmt.Sprintf("| % -10s| % -16s | % -10s | % -40s | % -10s |", "beego", timeend.String(), r.Method, r.URL.Path, "notmatch") + devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch") } Debug(devinfo) } From 51ee1e77c2ff6117d15f8c2832d22449e114444e Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 14:42:17 +0800 Subject: [PATCH 109/120] beego: close the file when finish init --- session/sess_file.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/session/sess_file.go b/session/sess_file.go index 38de7a90..0362e45a 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -29,7 +29,6 @@ var ( // File session store type FileSessionStore struct { - f *os.File sid string lock sync.RWMutex values map[interface{}]interface{} @@ -77,14 +76,23 @@ func (fs *FileSessionStore) SessionID() string { // Write file session to local file with Gob string func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) { - defer fs.f.Close() b, err := EncodeGob(fs.values) if err != nil { return } - fs.f.Truncate(0) - fs.f.Seek(0, 0) - fs.f.Write(b) + _, err = os.Stat(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid)) + var f *os.File + if err == nil { + f, err = os.OpenFile(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid), os.O_RDWR, 0777) + } else if os.IsNotExist(err) { + f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid)) + } else { + return + } + f.Truncate(0) + f.Seek(0, 0) + f.Write(b) + f.Close() } // File session provider @@ -137,8 +145,7 @@ func (fp *FileProvider) SessionRead(sid string) (SessionStore, error) { } } f.Close() - f, err = os.OpenFile(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid), os.O_WRONLY|os.O_CREATE, 0777) - ss := &FileSessionStore{f: f, sid: sid, values: kv} + ss := &FileSessionStore{sid: sid, values: kv} return ss, nil } @@ -235,9 +242,7 @@ func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (SessionStore, err return nil, err } } - - newf, err = os.OpenFile(path.Join(fp.savePath, string(sid[0]), string(sid[1]), sid), os.O_WRONLY|os.O_CREATE, 0777) - ss := &FileSessionStore{f: newf, sid: sid, values: kv} + ss := &FileSessionStore{sid: sid, values: kv} return ss, nil } From e5663226431b5616f9c2701e9fa95823c80348f6 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 14:46:43 +0800 Subject: [PATCH 110/120] beego: change the version from 1.4.0 to 1.3.2 --- beego.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beego.go b/beego.go index 48b4bf29..f7cfa56a 100644 --- a/beego.go +++ b/beego.go @@ -22,7 +22,7 @@ import ( ) // beego web framework version. -const VERSION = "1.3.2" +const VERSION = "1.4.0" type hookfunc func() error //hook function to run var hooks []hookfunc //hook function slice to store the hookfunc From e07d780dcf516de6d573c5bf8e7eee22660a2c00 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 15:00:27 +0800 Subject: [PATCH 111/120] update the router info --- router.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index dee96111..a87b7aad 100644 --- a/router.go +++ b/router.go @@ -770,7 +770,11 @@ Admin: if RunMode == "dev" { var devinfo string if findrouter { - devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s | % -40s |", r.Method, r.URL.Path, timeend.String(), "match", routerInfo.pattern) + if routerInfo != nil { + devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s | % -40s |", r.Method, r.URL.Path, timeend.String(), "match", routerInfo.pattern) + } else { + devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "match") + } } else { devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch") } From 86752a55b6278e6b989466aee53c92b56fd148f9 Mon Sep 17 00:00:00 2001 From: smallfish Date: Mon, 18 Aug 2014 15:03:10 +0800 Subject: [PATCH 112/120] rename SetAgent and ToXML --- httplib/httplib.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index ca012502..ca7ebdd8 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -127,7 +127,7 @@ func (b *BeegoHttpRequest) SetEnableCookie(enable bool) *BeegoHttpRequest { } // SetUserAgent sets User-Agent header field -func (b *BeegoHttpRequest) SetAgent(useragent string) *BeegoHttpRequest { +func (b *BeegoHttpRequest) SetUserAgent(useragent string) *BeegoHttpRequest { b.setting.UserAgent = useragent return b } @@ -411,7 +411,7 @@ func (b *BeegoHttpRequest) ToJson(v interface{}) error { // ToXml returns the map that marshals from the body bytes as xml in response . // it calls Response inner. -func (b *BeegoHttpRequest) ToXML(v interface{}) error { +func (b *BeegoHttpRequest) ToXml(v interface{}) error { data, err := b.Bytes() if err != nil { return err From 7668c54d05bef686b6fb60278cc1a6f48bfb35ad Mon Sep 17 00:00:00 2001 From: smallfish Date: Mon, 18 Aug 2014 15:03:34 +0800 Subject: [PATCH 113/120] update testcase for httplib --- httplib/httplib_test.go | 113 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 64de6596..cadf139d 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -11,94 +11,95 @@ package httplib import ( - "fmt" - "io/ioutil" + "strings" "testing" ) -func TestGetUrl(t *testing.T) { - resp, err := Get("http://beego.me").Debug(true).Response() +func TestSimpleGet(t *testing.T) { + str, err := Get("http://httpbin.org/get").String() if err != nil { t.Fatal(err) } - if resp.Body == nil { - t.Fatal("body is nil") - } - data, err := ioutil.ReadAll(resp.Body) - defer resp.Body.Close() - if err != nil { - t.Fatal(err) - } - if len(data) == 0 { - t.Fatal("data is no") - } + t.Log(str) +} - str, err := Get("http://beego.me").String() +func TestSimplePost(t *testing.T) { + v := "smallfish" + req := Post("http://httpbin.org/post") + req.Param("username", v) + str, err := req.String() if err != nil { t.Fatal(err) } - if len(str) == 0 { - t.Fatal("has no info") + t.Log(str) + n := strings.Index(str, v) + if n == -1 { + t.Fatal(v + " not found in post") } } -func ExamplePost(t *testing.T) { - b := Post("http://beego.me/").Debug(true) - b.Param("username", "astaxie") - b.Param("password", "hello") - b.PostFile("uploadfile", "httplib_test.go") - str, err := b.String() +func TestPostFile(t *testing.T) { + v := "smallfish" + req := Post("http://httpbin.org/post") + req.Param("username", v) + req.PostFile("uploadfile", "httplib_test.go") + str, err := req.String() if err != nil { t.Fatal(err) } - fmt.Println(str) + t.Log(str) + n := strings.Index(str, v) + if n == -1 { + t.Fatal(v + " not found in post") + } } -func TestSimpleGetString(t *testing.T) { - fmt.Println("TestSimpleGetString==========================================") - html, err := Get("http://httpbin.org/headers").SetAgent("beegoooooo").String() +func TestWithCookie(t *testing.T) { + v := "smallfish" + str, err := Get("http://httpbin.org/cookies/set?k1=" + v).SetEnableCookie(true).String() if err != nil { t.Fatal(err) } - fmt.Println(html) - fmt.Println("TestSimpleGetString==========================================") + t.Log(str) + str, err = Get("http://httpbin.org/cookies").SetEnableCookie(true).String() + if err != nil { + t.Fatal(err) + } + t.Log(str) + n := strings.Index(str, v) + if n == -1 { + t.Fatal(v + " not found in cookie") + } } -func TestSimpleGetStringWithDefaultCookie(t *testing.T) { - fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") - html, err := Get("http://httpbin.org/cookies/set?k1=v1").SetEnableCookie(true).String() +func TestWithUserAgent(t *testing.T) { + v := "beego" + str, err := Get("http://httpbin.org/headers").SetUserAgent(v).String() if err != nil { t.Fatal(err) } - fmt.Println(html) - html, err = Get("http://httpbin.org/cookies").SetEnableCookie(true).String() - if err != nil { - t.Fatal(err) + t.Log(str) + n := strings.Index(str, v) + if n == -1 { + t.Fatal(v + " not found in user-agent") } - fmt.Println(html) - fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") } -func TestDefaultSetting(t *testing.T) { - fmt.Println("TestDefaultSetting==========================================") - var def BeegoHttpSettings - def.EnableCookie = true - //def.ShowDebug = true - def.UserAgent = "UserAgent" - //def.ConnectTimeout = 60*time.Second - //def.ReadWriteTimeout = 60*time.Second - def.Transport = nil //http.DefaultTransport - SetDefaultSetting(def) +func TestWithSetting(t *testing.T) { + v := "beego" + var setting BeegoHttpSettings + setting.EnableCookie = true + setting.UserAgent = v + setting.Transport = nil + SetDefaultSetting(setting) - html, err := Get("http://httpbin.org/headers").String() + str, err := Get("http://httpbin.org/get").String() if err != nil { t.Fatal(err) } - fmt.Println(html) - html, err = Get("http://httpbin.org/headers").String() - if err != nil { - t.Fatal(err) + t.Log(str) + n := strings.Index(str, v) + if n == -1 { + t.Fatal(v + " not found in user-agent") } - fmt.Println(html) - fmt.Println("TestDefaultSetting==========================================") } From a144769515b8ddfb69046b3ef9e29c38bab94f3b Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 16:41:43 +0800 Subject: [PATCH 114/120] update the documents & comments --- README.md | 20 +++----- admin.go | 17 +++--- adminui.go | 17 +++--- app.go | 17 +++--- beego.go | 26 ++++++++-- cache/cache.go | 31 +++++++++-- cache/cache_test.go | 17 +++--- cache/conv.go | 17 +++--- cache/conv_test.go | 17 +++--- cache/file.go | 17 +++--- cache/memcache/memcache.go | 30 +++++++++-- cache/memory.go | 17 +++--- cache/redis/redis.go | 30 +++++++++-- cache/redis/redis_test.go | 22 ++++---- config.go | 17 +++--- config/config.go | 42 +++++++++++++-- config/fake.go | 17 +++--- config/ini.go | 17 +++--- config/ini_test.go | 17 +++--- config/json.go | 17 +++--- config/json_test.go | 17 +++--- config/xml/xml.go | 30 +++++++++-- config/xml/xml_test.go | 17 +++--- config/yaml/yaml.go | 30 +++++++++-- config/yaml/yaml_test.go | 17 +++--- config_test.go | 17 +++--- context/context.go | 22 ++++++-- context/input.go | 17 +++--- context/input_test.go | 17 +++--- context/output.go | 17 +++--- controller.go | 17 +++--- docs.go | 17 +++--- filter.go | 17 +++--- filter_test.go | 17 +++--- flash.go | 17 +++--- flash_test.go | 17 +++--- httplib/httplib.go | 31 +++++++++-- httplib/httplib_test.go | 17 +++--- log.go | 17 +++--- logs/conn.go | 17 +++--- logs/conn_test.go | 17 +++--- logs/console.go | 17 +++--- logs/console_test.go | 17 +++--- logs/file.go | 17 +++--- logs/file_test.go | 17 +++--- logs/log.go | 33 ++++++++++-- logs/smtp.go | 19 ++++--- logs/smtp_test.go | 17 +++--- memzipfile.go | 17 +++--- middleware/error.go | 17 +++--- middleware/exceptions.go | 17 +++--- middleware/i18n.go | 22 ++++++-- migration/migration.go | 18 +++++-- mime.go | 17 +++--- namespace.go | 17 +++--- namespace_test.go | 17 +++--- orm/README.md | 7 +-- orm/cmd.go | 17 +++--- orm/cmd_utils.go | 17 +++--- orm/db.go | 17 +++--- orm/db_alias.go | 17 +++--- orm/db_mysql.go | 17 +++--- orm/db_oracle.go | 17 +++--- orm/db_postgres.go | 17 +++--- orm/db_sqlite.go | 17 +++--- orm/db_tables.go | 17 +++--- orm/db_utils.go | 17 +++--- orm/models.go | 17 +++--- orm/models_boot.go | 17 +++--- orm/models_fields.go | 17 +++--- orm/models_info_f.go | 17 +++--- orm/models_info_m.go | 17 +++--- orm/models_test.go | 17 +++--- orm/models_utils.go | 17 +++--- orm/orm.go | 51 ++++++++++++++++-- orm/orm_conds.go | 17 +++--- orm/orm_log.go | 17 +++--- orm/orm_object.go | 17 +++--- orm/orm_querym2m.go | 17 +++--- orm/orm_queryset.go | 17 +++--- orm/orm_raw.go | 17 +++--- orm/orm_test.go | 17 +++--- orm/types.go | 17 +++--- orm/utils.go | 17 +++--- parser.go | 17 +++--- plugins/auth/basic.go | 10 ++-- plugins/cors/cors.go | 37 +++++++------ plugins/cors/cors_test.go | 1 - router.go | 17 +++--- router_test.go | 17 +++--- session/couchbase/sess_couchbase.go | 33 ++++++++++-- session/memcache/sess_memcache.go | 49 +++++++++++++----- session/mysql/sess_mysql.go | 37 ++++++++++--- session/postgres/sess_postgresql.go | 80 +++++++++++++++++------------ session/redis/sess_redis.go | 35 ++++++++++--- session/sess_cookie.go | 17 +++--- session/sess_cookie_test.go | 17 +++--- session/sess_file.go | 17 +++--- session/sess_mem.go | 17 +++--- session/sess_mem_test.go | 17 +++--- session/sess_test.go | 17 +++--- session/sess_utils.go | 17 +++--- session/session.go | 28 ++++++++-- staticfile.go | 17 +++--- swagger/docsSpec.go | 18 ++++--- template.go | 19 ++++--- template_test.go | 17 +++--- templatefunc.go | 17 +++--- templatefunc_test.go | 17 +++--- testing/assertions.go | 17 +++--- testing/client.go | 17 +++--- toolbox/healthcheck.go | 38 ++++++++------ toolbox/profile.go | 17 +++--- toolbox/profile_test.go | 17 +++--- toolbox/statistics.go | 17 +++--- toolbox/statistics_test.go | 17 +++--- toolbox/task.go | 17 +++--- toolbox/task_test.go | 17 +++--- tree.go | 17 +++--- tree_test.go | 17 +++--- utils/caller.go | 17 +++--- utils/caller_test.go | 17 +++--- utils/captcha/captcha.go | 19 ++++--- utils/captcha/image.go | 17 +++--- utils/captcha/image_test.go | 17 +++--- utils/captcha/siprng.go | 17 +++--- utils/captcha/siprng_test.go | 17 +++--- utils/debug.go | 17 +++--- utils/debug_test.go | 17 +++--- utils/file.go | 17 +++--- utils/file_test.go | 17 +++--- utils/mail.go | 17 +++--- utils/mail_test.go | 17 +++--- utils/rand.go | 17 +++--- utils/safemap.go | 17 +++--- utils/safemap_test.go | 17 +++--- utils/slice.go | 17 +++--- utils/slice_test.go | 17 +++--- validation/util.go | 17 +++--- validation/util_test.go | 17 +++--- validation/validation.go | 47 +++++++++++++++-- validation/validation_test.go | 17 +++--- validation/validators.go | 17 +++--- 143 files changed, 1911 insertions(+), 908 deletions(-) diff --git a/README.md b/README.md index a5b30a88..3357beef 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ [![Build Status](https://drone.io/github.com/astaxie/beego/status.png)](https://drone.io/github.com/astaxie/beego/latest) -beego is a Go Framework inspired by tornado and sinatra. - -It is a simple & powerful web framework. +beego is an open-source, high-performance, modularity, full-stack web framework. More info [beego.me](http://beego.me) @@ -12,20 +10,18 @@ More info [beego.me](http://beego.me) * RESTful support * MVC architecture -* Session support (store in memory, file, Redis or MySQL) -* Cache support (store in memory, Redis or Memcache) -* Global Config -* Intelligent routing -* Thread-safe map -* Friendly displaying of errors -* Useful template functions - +* modularity +* auto API documents +* annotation router +* namespace +* powerful develop tools +* full stack for web & API ## Documentation [English](http://beego.me/docs/intro/) -[API](http://gowalker.org/github.com/astaxie/beego) +[API](http://godoc.org/github.com/astaxie/beego) [中文文档](http://beego.me/docs/intro/) diff --git a/admin.go b/admin.go index 9b2f3dc3..e464a0e3 100644 --- a/admin.go +++ b/admin.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/adminui.go b/adminui.go index 241fd5ea..0c82775e 100644 --- a/adminui.go +++ b/adminui.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego var indexTpl = ` diff --git a/app.go b/app.go index 64bafde8..f1706616 100644 --- a/app.go +++ b/app.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/beego.go b/beego.go index f7cfa56a..a16f9ceb 100644 --- a/beego.go +++ b/beego.go @@ -1,12 +1,28 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// beego is an open-source, high-performance, modularity, full-stack web framework // -// @authors astaxie +// package main +// +// import "github.com/astaxie/beego" +// +// func main() { +// beego.Run() +// } +// +// more infomation: http://beego.me package beego import ( diff --git a/cache/cache.go b/cache/cache.go index 26e40fa3..d4ad5d59 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,12 +1,33 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: // -// @authors astaxie +// import( +// "github.com/astaxie/beego/cache" +// ) +// +// bm, err := cache.NewCache("memory", `{"interval":60}`) +// +// Use it like this: +// +// bm.Put("astaxie", 1, 10) +// bm.Get("astaxie") +// bm.IsExist("astaxie") +// bm.Delete("astaxie") +// +// more docs http://beego.me/docs/module/cache.md package cache import ( diff --git a/cache/cache_test.go b/cache/cache_test.go index 9426e159..bf9e79c2 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cache import ( diff --git a/cache/conv.go b/cache/conv.go index 57167706..724abfd2 100644 --- a/cache/conv.go +++ b/cache/conv.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cache import ( diff --git a/cache/conv_test.go b/cache/conv_test.go index d98db9e3..267bb0c9 100644 --- a/cache/conv_test.go +++ b/cache/conv_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cache import ( diff --git a/cache/file.go b/cache/file.go index b4af2211..6ecf6568 100644 --- a/cache/file.go +++ b/cache/file.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cache import ( diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 7e8b6a73..f5a5c6ef 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -1,12 +1,32 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package memcahe for cache provider // -// @authors astaxie +// depend on github.com/bradfitz/gomemcache/memcache +// +// go install github.com/bradfitz/gomemcache/memcache +// +// Usage: +// import( +// _ "github.com/astaxie/beego/cache/memcache" +// "github.com/astaxie/beego/cache" +// ) +// +// bm, err := cache.NewCache("memcache", `{"conn":"127.0.0.1:11211"}`) +// +// more docs http://beego.me/docs/module/cache.md package memcache import ( diff --git a/cache/memory.go b/cache/memory.go index cc4835c1..b90d227c 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cache import ( diff --git a/cache/redis/redis.go b/cache/redis/redis.go index bd9d44c9..35cf88cd 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -1,12 +1,32 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package redis for cache provider // -// @authors astaxie +// depend on github.com/garyburd/redigo/redis +// +// go install github.com/garyburd/redigo/redis +// +// Usage: +// import( +// _ "github.com/astaxie/beego/cache/redis" +// "github.com/astaxie/beego/cache" +// ) +// +// bm, err := cache.NewCache("redis", `{"conn":"127.0.0.1:11211"}`) +// +// more docs http://beego.me/docs/module/cache.md package redis import ( diff --git a/cache/redis/redis_test.go b/cache/redis/redis_test.go index 5128d249..fbe82ac5 100644 --- a/cache/redis/redis_test.go +++ b/cache/redis/redis_test.go @@ -1,12 +1,16 @@ -// Beego (http://beego.me/) - -// @description beego is an open-source, high-performance web framework for the Go programming language. - -// @link http://github.com/astaxie/beego for the canonical source repository - -// @license http://github.com/astaxie/beego/blob/master/LICENSE - -// @authors astaxie +// Copyright 2014 beego Author. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package redis diff --git a/config.go b/config.go index 802365ee..db234e16 100644 --- a/config.go +++ b/config.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/config/config.go b/config/config.go index 744adb4b..8d9261b8 100644 --- a/config/config.go +++ b/config/config.go @@ -1,12 +1,44 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: +// import( +// "github.com/astaxie/beego/config" +// ) // -// @authors astaxie +// cnf, err := config.NewConfig("ini", "config.conf") +// +// cnf APIS: +// +// cnf.Set(key, val string) error +// cnf.String(key string) string +// cnf.Strings(key string) []string +// cnf.Int(key string) (int, error) +// cnf.Int64(key string) (int64, error) +// cnf.Bool(key string) (bool, error) +// cnf.Float(key string) (float64, error) +// cnf.DefaultString(key string, defaultval string) string +// cnf.DefaultStrings(key string, defaultval []string) []string +// cnf.DefaultInt(key string, defaultval int) int +// cnf.DefaultInt64(key string, defaultval int64) int64 +// cnf.DefaultBool(key string, defaultval bool) bool +// cnf.DefaultFloat(key string, defaultval float64) float64 +// cnf.DIY(key string) (interface{}, error) +// cnf.GetSection(section string) (map[string]string, error) +// cnf.SaveConfigFile(filename string) error +// +// more docs http://beego.me/docs/module/config.md package config import ( diff --git a/config/fake.go b/config/fake.go index fec4250d..54588e5e 100644 --- a/config/fake.go +++ b/config/fake.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( diff --git a/config/ini.go b/config/ini.go index 1a8e1a12..ec72a718 100644 --- a/config/ini.go +++ b/config/ini.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( diff --git a/config/ini_test.go b/config/ini_test.go index fc4d88dd..7599ab8b 100644 --- a/config/ini_test.go +++ b/config/ini_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( diff --git a/config/json.go b/config/json.go index 0ddca1f0..ae86ea53 100644 --- a/config/json.go +++ b/config/json.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( diff --git a/config/json_test.go b/config/json_test.go index 80f5148c..409e2c12 100644 --- a/config/json_test.go +++ b/config/json_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( diff --git a/config/xml/xml.go b/config/xml/xml.go index 6a8494cd..a1d9fcdb 100644 --- a/config/xml/xml.go +++ b/config/xml/xml.go @@ -1,12 +1,32 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package xml for config provider // -// @authors astaxie +// depend on github.com/beego/x2j +// +// go install github.com/beego/x2j +// +// Usage: +// import( +// _ "github.com/astaxie/beego/config/xml" +// "github.com/astaxie/beego/config" +// ) +// +// cnf, err := config.NewConfig("xml", "config.xml") +// +// more docs http://beego.me/docs/module/config.md package xml import ( diff --git a/config/xml/xml_test.go b/config/xml/xml_test.go index 564d6344..fa3c17f1 100644 --- a/config/xml/xml_test.go +++ b/config/xml/xml_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package xml import ( diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 89244e34..c5be44a9 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -1,12 +1,32 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package yaml for config provider // -// @authors astaxie +// depend on github.com/beego/goyaml2 +// +// go install github.com/beego/goyaml2 +// +// Usage: +// import( +// _ "github.com/astaxie/beego/config/yaml" +// "github.com/astaxie/beego/config" +// ) +// +// cnf, err := config.NewConfig("yaml", "config.yaml") +// +// more docs http://beego.me/docs/module/config.md package yaml import ( diff --git a/config/yaml/yaml_test.go b/config/yaml/yaml_test.go index d960f501..19ecdca1 100644 --- a/config/yaml/yaml_test.go +++ b/config/yaml/yaml_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package yaml import ( diff --git a/config_test.go b/config_test.go index 9b355c45..17645f80 100644 --- a/config_test.go +++ b/config_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/context/context.go b/context/context.go index 26753a6a..1f683ff5 100644 --- a/context/context.go +++ b/context/context.go @@ -1,12 +1,24 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: // -// @authors astaxie +// import "github.com/astaxie/beego/context" +// +// ctx := context.Context{Request:req,ResponseWriter:rw} +// +// more docs http://beego.me/docs/module/context.md package context import ( diff --git a/context/input.go b/context/input.go index 13f78fbc..c6038693 100644 --- a/context/input.go +++ b/context/input.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package context import ( diff --git a/context/input_test.go b/context/input_test.go index dc554786..ddd1a056 100644 --- a/context/input_test.go +++ b/context/input_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package context import ( diff --git a/context/output.go b/context/output.go index 8f59c94d..6298ee77 100644 --- a/context/output.go +++ b/context/output.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package context import ( diff --git a/controller.go b/controller.go index d23a0c8b..eee79513 100644 --- a/controller.go +++ b/controller.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/docs.go b/docs.go index 8dfd3d82..aaad205e 100644 --- a/docs.go +++ b/docs.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/filter.go b/filter.go index d9024f9a..294966d4 100644 --- a/filter.go +++ b/filter.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego // FilterRouter defines filter operation before controller handler execution. diff --git a/filter_test.go b/filter_test.go index 089fea03..ff6f750b 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/flash.go b/flash.go index 68de09c9..6e85141f 100644 --- a/flash.go +++ b/flash.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/flash_test.go b/flash_test.go index 383a10b7..7c581e6a 100644 --- a/flash_test.go +++ b/flash_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/httplib/httplib.go b/httplib/httplib.go index 7bd7e743..7348791e 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -1,12 +1,33 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: // -// @authors astaxie +// import "github.com/astaxie/beego/context" +// +// b:=httplib.Post("http://beego.me/") +// b.Param("username","astaxie") +// b.Param("password","123456") +// b.PostFile("uploadfile1", "httplib.pdf") +// b.PostFile("uploadfile2", "httplib.txt") +// str, err := b.String() +// if err != nil { +// t.Fatal(err) +// } +// fmt.Println(str) +// +// more docs http://beego.me/docs/module/httplib.md package httplib import ( diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 9a94116e..3d0273b7 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package httplib import ( diff --git a/log.go b/log.go index d888b17a..5afba8ed 100644 --- a/log.go +++ b/log.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/logs/conn.go b/logs/conn.go index b7255b5c..612634fa 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/conn_test.go b/logs/conn_test.go index 4e200424..747fb890 100644 --- a/logs/conn_test.go +++ b/logs/conn_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/console.go b/logs/console.go index 96a34c0f..0248a329 100644 --- a/logs/console.go +++ b/logs/console.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/console_test.go b/logs/console_test.go index 8b775baa..2fad7241 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/file.go b/logs/file.go index 2d371a1e..e80b955c 100644 --- a/logs/file.go +++ b/logs/file.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/file_test.go b/logs/file_test.go index 66ebb01c..c71e9bb4 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/logs/log.go b/logs/log.go index 8e6c0308..4349e8a5 100644 --- a/logs/log.go +++ b/logs/log.go @@ -1,12 +1,35 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: // -// @authors astaxie +// import "github.com/astaxie/beego/logs" +// +// log := NewLogger(10000) +// log.SetLogger("console", "") +// +// > the first params stand for how many channel +// +// Use it like this: +// +// log.Trace("trace") +// log.Info("info") +// log.Warn("warning") +// log.Debug("debug") +// log.Critical("critical") +// +// more docs http://beego.me/docs/module/logs.md package logs import ( diff --git a/logs/smtp.go b/logs/smtp.go index fa5dc78e..3373d7f4 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( @@ -77,7 +82,7 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { // Set up authentication information. auth := s.GetSmtpAuth(hp[0]) - + // Connect to the server, authenticate, set the sender and recipient, // and send the email all in one step. content_type := "Content-Type: text/plain" + "; charset=UTF-8" diff --git a/logs/smtp_test.go b/logs/smtp_test.go index 58e15134..28e762d2 100644 --- a/logs/smtp_test.go +++ b/logs/smtp_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package logs import ( diff --git a/memzipfile.go b/memzipfile.go index 2fce9b81..cc5e3851 100644 --- a/memzipfile.go +++ b/memzipfile.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/middleware/error.go b/middleware/error.go index 49ed1673..3b7191e9 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package middleware import ( diff --git a/middleware/exceptions.go b/middleware/exceptions.go index 4165c3e6..a08a7358 100644 --- a/middleware/exceptions.go +++ b/middleware/exceptions.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package middleware import "fmt" diff --git a/middleware/i18n.go b/middleware/i18n.go index 3009b46d..e4dab693 100644 --- a/middleware/i18n.go +++ b/middleware/i18n.go @@ -1,12 +1,24 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Usage: // -// @authors astaxie +// import "github.com/astaxie/beego/middleware" +// +// I18N = middleware.NewLocale("conf/i18n.conf", beego.AppConfig.String("language")) +// +// more docs: http://beego.me/docs/module/i18n.md package middleware import ( diff --git a/migration/migration.go b/migration/migration.go index 47035e6a..d64d60d3 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -1,12 +1,20 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// migration package for migration // -// @authors astaxie +// The table structure is as follow: // // CREATE TABLE `migrations` ( // `id_migration` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'surrogate key', diff --git a/mime.go b/mime.go index 57487398..155e5e12 100644 --- a/mime.go +++ b/mime.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/namespace.go b/namespace.go index c8ec2488..d0109291 100644 --- a/namespace.go +++ b/namespace.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/namespace_test.go b/namespace_test.go index 7587f4b2..a92ae3ef 100644 --- a/namespace_test.go +++ b/namespace_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/orm/README.md b/orm/README.md index d4721307..74f1b47b 100644 --- a/orm/README.md +++ b/orm/README.md @@ -154,10 +154,5 @@ note: not recommend use this in product env. more details and examples in docs and test -* [中文](http://beego.me/docs/Models_Overview?lang=zh) -* [English](http://beego.me/docs/Models_Overview?lang=en) +[documents](http://beego.me/docs/mvc/model/overview.md) -## TODO -- some unrealized api -- examples -- docs diff --git a/orm/cmd.go b/orm/cmd.go index e31b0ef4..2358ef3c 100644 --- a/orm/cmd.go +++ b/orm/cmd.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/cmd_utils.go b/orm/cmd_utils.go index 82f125d3..8304da6b 100644 --- a/orm/cmd_utils.go +++ b/orm/cmd_utils.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db.go b/orm/db.go index f4a9f42c..2addff22 100644 --- a/orm/db.go +++ b/orm/db.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_alias.go b/orm/db_alias.go index 5a00d620..0a862241 100644 --- a/orm/db_alias.go +++ b/orm/db_alias.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_mysql.go b/orm/db_mysql.go index 85582966..3c2ad3a4 100644 --- a/orm/db_mysql.go +++ b/orm/db_mysql.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_oracle.go b/orm/db_oracle.go index c8321c5a..1e385c9a 100644 --- a/orm/db_oracle.go +++ b/orm/db_oracle.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm // oracle dbBaser diff --git a/orm/db_postgres.go b/orm/db_postgres.go index ac94446e..296ee6a0 100644 --- a/orm/db_postgres.go +++ b/orm/db_postgres.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_sqlite.go b/orm/db_sqlite.go index 8f6aae76..0a2f32c8 100644 --- a/orm/db_sqlite.go +++ b/orm/db_sqlite.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_tables.go b/orm/db_tables.go index 56e19759..a9aa10ab 100644 --- a/orm/db_tables.go +++ b/orm/db_tables.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/db_utils.go b/orm/db_utils.go index 713eb51c..4a3ba464 100644 --- a/orm/db_utils.go +++ b/orm/db_utils.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models.go b/orm/models.go index c1c51deb..dcb32b55 100644 --- a/orm/models.go +++ b/orm/models.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_boot.go b/orm/models_boot.go index 138a4844..cb44bc05 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_fields.go b/orm/models_fields.go index dd99596f..f038dd0f 100644 --- a/orm/models_fields.go +++ b/orm/models_fields.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_info_f.go b/orm/models_info_f.go index ebd140f7..a79ffab2 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_info_m.go b/orm/models_info_m.go index e9d2e65f..3600ee7c 100644 --- a/orm/models_info_m.go +++ b/orm/models_info_m.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_test.go b/orm/models_test.go index 99377bfa..fe78c45f 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/models_utils.go b/orm/models_utils.go index b682040b..ffde40ea 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm.go b/orm/orm.go index 96cb3430..cdb7f27c 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -1,12 +1,53 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Simple Usage // -// @authors astaxie, slene +// package main +// +// import ( +// "fmt" +// "github.com/astaxie/beego/orm" +// _ "github.com/go-sql-driver/mysql" // import your used driver +// ) +// +// // Model Struct +// type User struct { +// Id int `orm:"auto"` +// Name string `orm:"size(100)"` +// } +// +// func init() { +// orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) +// } +// +// func main() { +// o := orm.NewOrm() +// user := User{Name: "slene"} +// // insert +// id, err := o.Insert(&user) +// // update +// user.Name = "astaxie" +// num, err := o.Update(&user) +// // read one +// u := User{Id: user.Id} +// err = o.Read(&u) +// // delete +// num, err = o.Delete(&u) +// } +// +// more docs: http://beego.me/docs/mvc/model/overview.md package orm import ( diff --git a/orm/orm_conds.go b/orm/orm_conds.go index c5a57305..6344653a 100644 --- a/orm/orm_conds.go +++ b/orm/orm_conds.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_log.go b/orm/orm_log.go index ad9ae70c..419d8e11 100644 --- a/orm/orm_log.go +++ b/orm/orm_log.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_object.go b/orm/orm_object.go index 1a91d789..df5a6600 100644 --- a/orm/orm_object.go +++ b/orm/orm_object.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_querym2m.go b/orm/orm_querym2m.go index c525d42e..1eaccf72 100644 --- a/orm/orm_querym2m.go +++ b/orm/orm_querym2m.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_queryset.go b/orm/orm_queryset.go index 5c651023..4f5d5485 100644 --- a/orm/orm_queryset.go +++ b/orm/orm_queryset.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_raw.go b/orm/orm_raw.go index 5936e590..1393d414 100644 --- a/orm/orm_raw.go +++ b/orm/orm_raw.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/orm_test.go b/orm/orm_test.go index d8b48ef4..e7420bcb 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/types.go b/orm/types.go index f104513a..c342e1c2 100644 --- a/orm/types.go +++ b/orm/types.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/orm/utils.go b/orm/utils.go index a0bb94a3..df6147c1 100644 --- a/orm/utils.go +++ b/orm/utils.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie, slene +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package orm import ( diff --git a/parser.go b/parser.go index 0d3f6b84..65144f5d 100644 --- a/parser.go +++ b/parser.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/plugins/auth/basic.go b/plugins/auth/basic.go index 98e4864f..ed8bc4bd 100644 --- a/plugins/auth/basic.go +++ b/plugins/auth/basic.go @@ -27,11 +27,11 @@ // // // Advanced Usage: -// func SecretAuth(username, password string) bool { -// return username == "astaxie" && password == "helloBeego" -// } -// authPlugin := auth.NewBasicAuthenticator(SecretAuth, "Authorization Required") -// beego.InsertFilter("*", beego.BeforeRouter,authPlugin) +// func SecretAuth(username, password string) bool { +// return username == "astaxie" && password == "helloBeego" +// } +// authPlugin := auth.NewBasicAuthenticator(SecretAuth, "Authorization Required") +// beego.InsertFilter("*", beego.BeforeRouter,authPlugin) package auth import ( diff --git a/plugins/cors/cors.go b/plugins/cors/cors.go index c8de8250..dce750eb 100644 --- a/plugins/cors/cors.go +++ b/plugins/cors/cors.go @@ -14,26 +14,25 @@ // Package cors provides handlers to enable CORS support. // Usage -// -// import ( -// "github.com/astaxie/beego" -// "github.com/astaxie/beego/plugins/cors" +// import ( +// "github.com/astaxie/beego" +// "github.com/astaxie/beego/plugins/cors" // ) - -//func main() { -// // CORS for https://foo.* origins, allowing: -// // - PUT and PATCH methods -// // - Origin header -// // - Credentials share -// beego.InsertFilter("*", beego.BeforeRouter,cors.Allow(&cors.Options{ -// AllowOrigins: []string{"https://*.foo.com"}, -// AllowMethods: []string{"PUT", "PATCH"}, -// AllowHeaders: []string{"Origin"}, -// ExposeHeaders: []string{"Content-Length"}, -// AllowCredentials: true, -// })) -// beego.Run() -//} +// +// func main() { +// // CORS for https://foo.* origins, allowing: +// // - PUT and PATCH methods +// // - Origin header +// // - Credentials share +// beego.InsertFilter("*", beego.BeforeRouter,cors.Allow(&cors.Options{ +// AllowOrigins: []string{"https://*.foo.com"}, +// AllowMethods: []string{"PUT", "PATCH"}, +// AllowHeaders: []string{"Origin"}, +// ExposeHeaders: []string{"Content-Length"}, +// AllowCredentials: true, +// })) +// beego.Run() +// } package cors import ( diff --git a/plugins/cors/cors_test.go b/plugins/cors/cors_test.go index 0ed468fe..5c02ab98 100644 --- a/plugins/cors/cors_test.go +++ b/plugins/cors/cors_test.go @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package cors provides handlers to enable CORS support. package cors import ( diff --git a/router.go b/router.go index a87b7aad..6f8bd769 100644 --- a/router.go +++ b/router.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/router_test.go b/router_test.go index d4d80fa0..d378589b 100644 --- a/router_test.go +++ b/router_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/session/couchbase/sess_couchbase.go b/session/couchbase/sess_couchbase.go index 8066e338..827d55d9 100644 --- a/session/couchbase/sess_couchbase.go +++ b/session/couchbase/sess_couchbase.go @@ -1,12 +1,35 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package couchbase for session provider // -// @authors astaxie +// depend on github.com/couchbaselabs/go-couchbasee +// +// go install github.com/couchbaselabs/go-couchbase +// +// Usage: +// import( +// _ "github.com/astaxie/beego/session/couchbase" +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("couchbase", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"http://host:port/, Pool, Bucket"}``) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md package session import ( diff --git a/session/memcache/sess_memcache.go b/session/memcache/sess_memcache.go index 5a1dc6b9..5827a0a9 100644 --- a/session/memcache/sess_memcache.go +++ b/session/memcache/sess_memcache.go @@ -1,12 +1,35 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package memcache for session provider // -// @authors astaxie +// depend on github.com/bradfitz/gomemcache/memcache +// +// go install github.com/bradfitz/gomemcache/memcache +// +// Usage: +// import( +// _ "github.com/astaxie/beego/session/memcache" +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("memcache", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:11211"}``) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md package session import ( @@ -65,12 +88,12 @@ func (rs *MemcacheSessionStore) Flush() error { return nil } -// get redis session id +// get memcache session id func (rs *MemcacheSessionStore) SessionID() string { return rs.sid } -// save session values to redis +// save session values to memcache func (rs *MemcacheSessionStore) SessionRelease(w http.ResponseWriter) { b, err := session.EncodeGob(rs.values) if err != nil { @@ -80,7 +103,7 @@ func (rs *MemcacheSessionStore) SessionRelease(w http.ResponseWriter) { client.Set(&item) } -// redis session provider +// memcahe session provider type MemProvider struct { maxlifetime int64 conninfo []string @@ -88,7 +111,7 @@ type MemProvider struct { password string } -// init redis session +// init memcache session // savepath like // e.g. 127.0.0.1:9090 func (rp *MemProvider) SessionInit(maxlifetime int64, savePath string) error { @@ -98,7 +121,7 @@ func (rp *MemProvider) SessionInit(maxlifetime int64, savePath string) error { return nil } -// read redis session by sid +// read memcache session by sid func (rp *MemProvider) SessionRead(sid string) (session.SessionStore, error) { if client == nil { if err := rp.connectInit(); err != nil { @@ -123,7 +146,7 @@ func (rp *MemProvider) SessionRead(sid string) (session.SessionStore, error) { return rs, nil } -// check redis session exist by sid +// check memcache session exist by sid func (rp *MemProvider) SessionExist(sid string) bool { if client == nil { if err := rp.connectInit(); err != nil { @@ -137,7 +160,7 @@ func (rp *MemProvider) SessionExist(sid string) bool { } } -// generate new sid for redis session +// generate new sid for memcache session func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionStore, error) { if client == nil { if err := rp.connectInit(); err != nil { @@ -177,7 +200,7 @@ func (rp *MemProvider) SessionRegenerate(oldsid, sid string) (session.SessionSto return rs, nil } -// delete redis session by id +// delete memcache session by id func (rp *MemProvider) SessionDestroy(sid string) error { if client == nil { if err := rp.connectInit(); err != nil { diff --git a/session/mysql/sess_mysql.go b/session/mysql/sess_mysql.go index 39f31230..0f6d3e4f 100644 --- a/session/mysql/sess_mysql.go +++ b/session/mysql/sess_mysql.go @@ -1,14 +1,23 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie -package session +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// package mysql for session provider +// +// depends on github.com/go-sql-driver/mysql: +// +// go install github.com/go-sql-driver/mysql +// // mysql session support need create table as sql: // CREATE TABLE `session` ( // `session_key` char(64) NOT NULL, @@ -16,6 +25,20 @@ package session // `session_expiry` int(11) unsigned NOT NULL, // PRIMARY KEY (`session_key`) // ) ENGINE=MyISAM DEFAULT CHARSET=utf8; +// +// Usage: +// import( +// _ "github.com/astaxie/beego/session/mysql" +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("mysql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]"}``) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md +package session import ( "database/sql" diff --git a/session/postgres/sess_postgresql.go b/session/postgres/sess_postgresql.go index 1796da2f..ac9a1612 100644 --- a/session/postgres/sess_postgresql.go +++ b/session/postgres/sess_postgresql.go @@ -1,43 +1,55 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package postgresql for session provider // -// @authors astaxie +// depends on github.com/lib/pq: +// +// go install github.com/lib/pq +// +// +// needs this table in your database: +// +// CREATE TABLE session ( +// session_key char(64) NOT NULL, +// session_data bytea, +// session_expiry timestamp NOT NULL, +// CONSTRAINT session_key PRIMARY KEY(session_key) +// ); + +// will be activated with these settings in app.conf: + +// SessionOn = true +// SessionProvider = postgresql +// SessionSavePath = "user=a password=b dbname=c sslmode=disable" +// SessionName = session +// +// +// Usage: +// import( +// _ "github.com/astaxie/beego/session/postgresql" +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("postgresql", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"user=pqgotest dbname=pqgotest sslmode=verify-full"}``) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md package session -/* - -beego session provider for postgresql -------------------------------------- - -depends on github.com/lib/pq: - -go install github.com/lib/pq - - -needs this table in your database: - -CREATE TABLE session ( -session_key char(64) NOT NULL, -session_data bytea, -session_expiry timestamp NOT NULL, -CONSTRAINT session_key PRIMARY KEY(session_key) -); - - -will be activated with these settings in app.conf: - -SessionOn = true -SessionProvider = postgresql -SessionSavePath = "user=a password=b dbname=c sslmode=disable" -SessionName = session - -*/ - import ( "database/sql" "net/http" diff --git a/session/redis/sess_redis.go b/session/redis/sess_redis.go index 8368dbc0..f2b0b29b 100644 --- a/session/redis/sess_redis.go +++ b/session/redis/sess_redis.go @@ -1,12 +1,35 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package redis for session provider // -// @authors astaxie +// depend on github.com/garyburd/redigo/redis +// +// go install github.com/garyburd/redigo/redis +// +// Usage: +// import( +// _ "github.com/astaxie/beego/session/redis" +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("redis", ``{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:7070"}``) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md package session import ( @@ -17,7 +40,7 @@ import ( "github.com/astaxie/beego/session" - "github.com/beego/redigo/redis" + "github.com/garyburd/redigo/redis" ) var redispder = &RedisProvider{} diff --git a/session/sess_cookie.go b/session/sess_cookie.go index 08b1ce38..01dc505c 100644 --- a/session/sess_cookie.go +++ b/session/sess_cookie.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_cookie_test.go b/session/sess_cookie_test.go index 0a5831e1..4f40a7ba 100644 --- a/session/sess_cookie_test.go +++ b/session/sess_cookie_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_file.go b/session/sess_file.go index 0362e45a..b1084acf 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_mem.go b/session/sess_mem.go index deec8190..627a3246 100644 --- a/session/sess_mem.go +++ b/session/sess_mem.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_mem_test.go b/session/sess_mem_test.go index 6bcbd157..03927c76 100644 --- a/session/sess_mem_test.go +++ b/session/sess_mem_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_test.go b/session/sess_test.go index ed9acd9d..5ba910f2 100644 --- a/session/sess_test.go +++ b/session/sess_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/sess_utils.go b/session/sess_utils.go index 63bf3d9c..9ae74528 100644 --- a/session/sess_utils.go +++ b/session/sess_utils.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package session import ( diff --git a/session/session.go b/session/session.go index 35d81b6e..88e94d59 100644 --- a/session/session.go +++ b/session/session.go @@ -1,12 +1,30 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package session provider // -// @authors astaxie +// Usage: +// import( +// "github.com/astaxie/beego/session" +// ) +// +// func init() { +// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`) +// go globalSessions.GC() +// } +// +// more docs: http://beego.me/docs/module/session.md package session import ( diff --git a/staticfile.go b/staticfile.go index 1881b711..a9deabe9 100644 --- a/staticfile.go +++ b/staticfile.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/swagger/docsSpec.go b/swagger/docsSpec.go index fd054c52..6f8fe1db 100644 --- a/swagger/docsSpec.go +++ b/swagger/docsSpec.go @@ -1,12 +1,18 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// swagger struct definition package swagger const SwaggerVersion = "1.2" diff --git a/template.go b/template.go index 69a286c2..2ca84f22 100644 --- a/template.go +++ b/template.go @@ -1,15 +1,18 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie -package beego +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -//@todo add template funcs +package beego import ( "errors" diff --git a/template_test.go b/template_test.go index a18dc09f..b35da5ce 100644 --- a/template_test.go +++ b/template_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/templatefunc.go b/templatefunc.go index f72017e1..a365718d 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/templatefunc_test.go b/templatefunc_test.go index 49807f12..44a06dec 100644 --- a/templatefunc_test.go +++ b/templatefunc_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/testing/assertions.go b/testing/assertions.go index 7fa4c199..96c5d4dd 100644 --- a/testing/assertions.go +++ b/testing/assertions.go @@ -1,10 +1,15 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package testing diff --git a/testing/client.go b/testing/client.go index 0819d508..366bda96 100644 --- a/testing/client.go +++ b/testing/client.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package testing import ( diff --git a/toolbox/healthcheck.go b/toolbox/healthcheck.go index dc195549..4ccff785 100644 --- a/toolbox/healthcheck.go +++ b/toolbox/healthcheck.go @@ -1,26 +1,34 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie -package toolbox +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -//type DatabaseCheck struct { -//} - -//func (dc *DatabaseCheck) Check() error { +// toolbox healthcheck +// +// type DatabaseCheck struct { +// } +// +// func (dc *DatabaseCheck) Check() error { // if dc.isConnected() { // return nil // } else { // return errors.New("can't connect database") -// } -//} - -//AddHealthCheck("database",&DatabaseCheck{}) +// } +// } +// +// AddHealthCheck("database",&DatabaseCheck{}) +// +// more docs: http://beego.me/docs/module/toolbox.md +package toolbox // health checker map var AdminCheckList map[string]HealthChecker diff --git a/toolbox/profile.go b/toolbox/profile.go index a4e4b155..b428e2ff 100644 --- a/toolbox/profile.go +++ b/toolbox/profile.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/toolbox/profile_test.go b/toolbox/profile_test.go index cb3135d5..07a20c4e 100644 --- a/toolbox/profile_test.go +++ b/toolbox/profile_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/toolbox/statistics.go b/toolbox/statistics.go index 0ca31473..0a5170b0 100644 --- a/toolbox/statistics.go +++ b/toolbox/statistics.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/toolbox/statistics_test.go b/toolbox/statistics_test.go index 1649019c..448b2af5 100644 --- a/toolbox/statistics_test.go +++ b/toolbox/statistics_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/toolbox/task.go b/toolbox/task.go index 439035a1..6931e189 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/toolbox/task_test.go b/toolbox/task_test.go index a1e85166..596bc9c5 100644 --- a/toolbox/task_test.go +++ b/toolbox/task_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package toolbox import ( diff --git a/tree.go b/tree.go index f32bed13..eebc7f85 100644 --- a/tree.go +++ b/tree.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import ( diff --git a/tree_test.go b/tree_test.go index 97c855c0..30856d29 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package beego import "testing" diff --git a/utils/caller.go b/utils/caller.go index 6684880a..de04d96e 100644 --- a/utils/caller.go +++ b/utils/caller.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/caller_test.go b/utils/caller_test.go index 95262d75..0675f0aa 100644 --- a/utils/caller_test.go +++ b/utils/caller_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 27748f12..62adc81d 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -1,13 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository -// -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// http://www.apache.org/licenses/LICENSE-2.0 // +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // an example for use captcha // // ``` @@ -224,7 +228,6 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) { return true } - // create a new captcha.Captcha func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha { cpt := &Captcha{} diff --git a/utils/captcha/image.go b/utils/captcha/image.go index cde4932a..8e9039d0 100644 --- a/utils/captcha/image.go +++ b/utils/captcha/image.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package captcha import ( diff --git a/utils/captcha/image_test.go b/utils/captcha/image_test.go index 393262c8..5e35b7f7 100644 --- a/utils/captcha/image_test.go +++ b/utils/captcha/image_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package captcha import ( diff --git a/utils/captcha/siprng.go b/utils/captcha/siprng.go index 54d6e93b..5e256cf9 100644 --- a/utils/captcha/siprng.go +++ b/utils/captcha/siprng.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package captcha import ( diff --git a/utils/captcha/siprng_test.go b/utils/captcha/siprng_test.go index f6d31055..189d3d3c 100644 --- a/utils/captcha/siprng_test.go +++ b/utils/captcha/siprng_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package captcha import "testing" diff --git a/utils/debug.go b/utils/debug.go index 972b2c5b..f9a682d3 100644 --- a/utils/debug.go +++ b/utils/debug.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/debug_test.go b/utils/debug_test.go index 40598551..efb8924e 100644 --- a/utils/debug_test.go +++ b/utils/debug_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/file.go b/utils/file.go index ad221c92..c9c3e903 100644 --- a/utils/file.go +++ b/utils/file.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/file_test.go b/utils/file_test.go index 0805415a..020d7e4c 100644 --- a/utils/file_test.go +++ b/utils/file_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/mail.go b/utils/mail.go index d0383ade..c7ab73d8 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/mail_test.go b/utils/mail_test.go index f09f5b78..c38356a2 100644 --- a/utils/mail_test.go +++ b/utils/mail_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import "testing" diff --git a/utils/rand.go b/utils/rand.go index 23cf3926..74bb4121 100644 --- a/utils/rand.go +++ b/utils/rand.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/safemap.go b/utils/safemap.go index e99aceee..37e76eb3 100644 --- a/utils/safemap.go +++ b/utils/safemap.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/safemap_test.go b/utils/safemap_test.go index 32034e91..fb271d18 100644 --- a/utils/safemap_test.go +++ b/utils/safemap_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/slice.go b/utils/slice.go index 323c02fd..729f6594 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/utils/slice_test.go b/utils/slice_test.go index a1c053c6..142dec96 100644 --- a/utils/slice_test.go +++ b/utils/slice_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package utils import ( diff --git a/validation/util.go b/validation/util.go index 91d2a735..249462d4 100644 --- a/validation/util.go +++ b/validation/util.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package validation import ( diff --git a/validation/util_test.go b/validation/util_test.go index ca99a7ab..c4283c4e 100644 --- a/validation/util_test.go +++ b/validation/util_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package validation import ( diff --git a/validation/validation.go b/validation/validation.go index b86b565f..addf6b7e 100644 --- a/validation/validation.go +++ b/validation/validation.go @@ -1,12 +1,49 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// package for validations // -// @authors astaxie +// import ( +// "github.com/astaxie/beego/validation" +// "log" +// ) +// +// type User struct { +// Name string +// Age int +// } +// +// func main() { +// u := User{"man", 40} +// valid := validation.Validation{} +// valid.Required(u.Name, "name") +// valid.MaxSize(u.Name, 15, "nameMax") +// valid.Range(u.Age, 0, 140, "age") +// if valid.HasErrors() { +// // validation does not pass +// // print invalid message +// for _, err := range valid.Errors { +// log.Println(err.Key, err.Message) +// } +// } +// // or use like this +// if v := valid.Max(u.Age, 140); !v.Ok { +// log.Println(v.Error.Key, v.Error.Message) +// } +// } +// +// more info: http://beego.me/docs/mvc/controller/validation.md package validation import ( diff --git a/validation/validation_test.go b/validation/validation_test.go index ff279b64..be63ac93 100644 --- a/validation/validation_test.go +++ b/validation/validation_test.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package validation import ( diff --git a/validation/validators.go b/validation/validators.go index 5a468d67..25415bdd 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -1,12 +1,17 @@ -// Beego (http://beego.me/) +// Copyright 2014 beego Author. All Rights Reserved. // -// @description beego is an open-source, high-performance web framework for the Go programming language. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// @link http://github.com/astaxie/beego for the canonical source repository +// http://www.apache.org/licenses/LICENSE-2.0 // -// @license http://github.com/astaxie/beego/blob/master/LICENSE -// -// @authors astaxie +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package validation import ( From c4fa17921e4adf61c7b0b69315418d12986b1434 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 18 Aug 2014 16:44:40 +0800 Subject: [PATCH 115/120] comments for godocs --- beego.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beego.go b/beego.go index a16f9ceb..46499743 100644 --- a/beego.go +++ b/beego.go @@ -14,13 +14,13 @@ // beego is an open-source, high-performance, modularity, full-stack web framework // -// package main +// package main // -// import "github.com/astaxie/beego" +// import "github.com/astaxie/beego" // -// func main() { -// beego.Run() -// } +// func main() { +// beego.Run() +// } // // more infomation: http://beego.me package beego From de87529387a23d0c6145f6ffc3b5df427ac79c1c Mon Sep 17 00:00:00 2001 From: smallfish Date: Mon, 18 Aug 2014 21:01:49 +0800 Subject: [PATCH 116/120] Update httplib support read data from response buffer, add some testcases --- httplib/httplib.go | 35 ++++++++++++++------- httplib/httplib_test.go | 70 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 15 deletions(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index f641222d..18e4caf3 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -16,7 +16,7 @@ // // import "github.com/astaxie/beego/context" // -// b:=httplib.Post("http://beego.me/") +// b := httplib.Post("http://beego.me/") // b.Param("username","astaxie") // b.Param("password","123456") // b.PostFile("uploadfile1", "httplib.pdf") @@ -76,41 +76,46 @@ func SetDefaultSetting(setting BeegoHttpSettings) { // Get returns *BeegoHttpRequest with GET method. func Get(url string) *BeegoHttpRequest { var req http.Request + var resp http.Response req.Method = "GET" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} } // Post returns *BeegoHttpRequest with POST method. func Post(url string) *BeegoHttpRequest { var req http.Request + var resp http.Response req.Method = "POST" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} } // Put returns *BeegoHttpRequest with PUT method. func Put(url string) *BeegoHttpRequest { var req http.Request + var resp http.Response req.Method = "PUT" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} } // Delete returns *BeegoHttpRequest DELETE GET method. func Delete(url string) *BeegoHttpRequest { var req http.Request + var resp http.Response req.Method = "DELETE" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} } // Head returns *BeegoHttpRequest with HEAD method. func Head(url string) *BeegoHttpRequest { var req http.Request + var resp http.Response req.Method = "HEAD" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} } // BeegoHttpSettings @@ -132,6 +137,8 @@ type BeegoHttpRequest struct { params map[string]string files map[string]string setting BeegoHttpSettings + resp *http.Response + body []byte } // Change request settings @@ -247,6 +254,9 @@ func (b *BeegoHttpRequest) Body(data interface{}) *BeegoHttpRequest { } func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { + if b.resp.StatusCode != 0 { + return b.resp, nil + } var paramBody string if len(b.params) > 0 { var buf bytes.Buffer @@ -365,6 +375,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { if err != nil { return nil, err } + b.resp = resp return resp, nil } @@ -382,6 +393,9 @@ func (b *BeegoHttpRequest) String() (string, error) { // Bytes returns the body []byte in response. // it calls Response inner. func (b *BeegoHttpRequest) Bytes() ([]byte, error) { + if b.body != nil { + return b.body, nil + } resp, err := b.getResponse() if err != nil { return nil, err @@ -394,6 +408,7 @@ func (b *BeegoHttpRequest) Bytes() ([]byte, error) { if err != nil { return nil, err } + b.body = data return data, nil } @@ -406,15 +421,11 @@ func (b *BeegoHttpRequest) ToFile(filename string) error { } defer f.Close() - resp, err := b.getResponse() + data, err := b.Bytes() if err != nil { return err } - if resp.Body == nil { - return nil - } - defer resp.Body.Close() - _, err = io.Copy(f, resp.Body) + _, err = f.Write(data) return err } diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index abf03ace..b352bd4a 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -19,23 +19,41 @@ import ( "testing" ) -func TestSimpleGet(t *testing.T) { - str, err := Get("http://httpbin.org/get").String() +func TestResponse(t *testing.T) { + req := Get("http://httpbin.org/get") + resp, err := req.Response() if err != nil { t.Fatal(err) } - t.Log(str) + t.Log(resp) +} + +func TestGet(t *testing.T) { + req := Get("http://httpbin.org/get") + b, err := req.Bytes() + if err != nil { + t.Fatal(err) + } + t.Log(b) + + s, err := req.String() + if err != nil { + t.Fatal(err) + } + t.Log(s) } func TestSimplePost(t *testing.T) { v := "smallfish" req := Post("http://httpbin.org/post") req.Param("username", v) + str, err := req.String() if err != nil { t.Fatal(err) } t.Log(str) + n := strings.Index(str, v) if n == -1 { t.Fatal(v + " not found in post") @@ -47,17 +65,35 @@ func TestPostFile(t *testing.T) { req := Post("http://httpbin.org/post") req.Param("username", v) req.PostFile("uploadfile", "httplib_test.go") + str, err := req.String() if err != nil { t.Fatal(err) } t.Log(str) + n := strings.Index(str, v) if n == -1 { t.Fatal(v + " not found in post") } } +func TestSimplePut(t *testing.T) { + str, err := Put("http://httpbin.org/put").String() + if err != nil { + t.Fatal(err) + } + t.Log(str) +} + +func TestSimpleDelete(t *testing.T) { + str, err := Delete("http://httpbin.org/delete").String() + if err != nil { + t.Fatal(err) + } + t.Log(str) +} + func TestWithCookie(t *testing.T) { v := "smallfish" str, err := Get("http://httpbin.org/cookies/set?k1=" + v).SetEnableCookie(true).String() @@ -65,11 +101,13 @@ func TestWithCookie(t *testing.T) { t.Fatal(err) } t.Log(str) + str, err = Get("http://httpbin.org/cookies").SetEnableCookie(true).String() if err != nil { t.Fatal(err) } t.Log(str) + n := strings.Index(str, v) if n == -1 { t.Fatal(v + " not found in cookie") @@ -83,6 +121,7 @@ func TestWithUserAgent(t *testing.T) { t.Fatal(err) } t.Log(str) + n := strings.Index(str, v) if n == -1 { t.Fatal(v + " not found in user-agent") @@ -102,8 +141,33 @@ func TestWithSetting(t *testing.T) { t.Fatal(err) } t.Log(str) + n := strings.Index(str, v) if n == -1 { t.Fatal(v + " not found in user-agent") } } + +func TestToJson(t *testing.T) { + req := Get("http://httpbin.org/ip") + resp, err := req.Response() + if err != nil { + t.Fatal(err) + } + t.Log(resp) + + // httpbin will return http remote addr + type Ip struct { + Origin string `json:"origin"` + } + var ip Ip + err = req.ToJson(&ip) + if err != nil { + t.Fatal(err) + } + t.Log(ip.Origin) + + if n := strings.Count(ip.Origin, "."); n != 3 { + t.Fatal("response is not valid ip") + } +} From c16b7be9ac333ce0db2cb755f5e05d4e6d4c823d Mon Sep 17 00:00:00 2001 From: smallfish Date: Mon, 18 Aug 2014 21:29:45 +0800 Subject: [PATCH 117/120] rollback the ToFile func implement, and add testcase --- httplib/httplib.go | 8 ++++++-- httplib/httplib_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/httplib/httplib.go b/httplib/httplib.go index 18e4caf3..1c0d5544 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -421,11 +421,15 @@ func (b *BeegoHttpRequest) ToFile(filename string) error { } defer f.Close() - data, err := b.Bytes() + resp, err := b.getResponse() if err != nil { return err } - _, err = f.Write(data) + if resp.Body == nil { + return nil + } + defer resp.Body.Close() + _, err = io.Copy(f, resp.Body) return err } diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index b352bd4a..2d49d875 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -15,6 +15,8 @@ package httplib import ( + "io/ioutil" + "os" "strings" "testing" ) @@ -41,6 +43,10 @@ func TestGet(t *testing.T) { t.Fatal(err) } t.Log(s) + + if string(b) != s { + t.Fatal("request data not match") + } } func TestSimplePost(t *testing.T) { @@ -171,3 +177,17 @@ func TestToJson(t *testing.T) { t.Fatal("response is not valid ip") } } + +func TestToFile(t *testing.T) { + f := "beego_testfile" + req := Get("http://httpbin.org/ip") + err := req.ToFile(f) + if err != nil { + t.Fatal(err) + } + defer os.Remove(f) + b, err := ioutil.ReadFile(f) + if n := strings.Index(string(b), "origin"); n == -1 { + t.Fatal(err) + } +} From 80274684e0bf07543d890fbb05f1c3780d157a30 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 19 Aug 2014 09:48:21 +0800 Subject: [PATCH 118/120] context: redirect should writer to response instantly --- context/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 1f683ff5..d31076d4 100644 --- a/context/context.go +++ b/context/context.go @@ -49,7 +49,7 @@ type Context struct { // It sends http response header directly. func (ctx *Context) Redirect(status int, localurl string) { ctx.Output.Header("Location", localurl) - ctx.Output.SetStatus(status) + ctx.ResponseWriter.WriteHeader(status) } // Abort stops this request. From aaabeff44f7956397adf71ce12b677996d389ffb Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 20 Aug 2014 10:59:38 +0800 Subject: [PATCH 119/120] change the route info --- router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.go b/router.go index 6f8bd769..f8b52270 100644 --- a/router.go +++ b/router.go @@ -783,7 +783,7 @@ Admin: } else { devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch") } - Debug(devinfo) + Info(devinfo) } // Call WriteHeader if status code has been set changed From 7f977a0c8ccdbc21e84f928046cb8778f24a67e0 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 20 Aug 2014 11:54:25 +0800 Subject: [PATCH 120/120] beego: change the colour --- logs/console.go | 4 ++-- router.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/logs/console.go b/logs/console.go index 0248a329..461291c2 100644 --- a/logs/console.go +++ b/logs/console.go @@ -38,8 +38,8 @@ var colors = []Brush{ NewBrush("1;31"), // Error red NewBrush("1;33"), // Warning yellow NewBrush("1;32"), // Notice green - NewBrush("1;34"), // Informational green - NewBrush("1;30"), // Debug black + NewBrush("1;34"), // Informational blue + NewBrush("1;34"), // Debug blue } // ConsoleWriter implements LoggerInterface and writes messages to terminal. diff --git a/router.go b/router.go index f8b52270..6f8bd769 100644 --- a/router.go +++ b/router.go @@ -783,7 +783,7 @@ Admin: } else { devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch") } - Info(devinfo) + Debug(devinfo) } // Call WriteHeader if status code has been set changed