From 14629c214b52b4214089525ba9719c11a831a4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E8=99=9E?= Date: Mon, 25 Aug 2014 20:14:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96GetData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 去掉重复的ToLower 2. getData内部统一ToLower 3.调整getData中对空字符串判断位置 ==== 4. 待确定:在getData中是否有必要进行lock操作 --- config/ini.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/config/ini.go b/config/ini.go index ec72a718..b996a709 100644 --- a/config/ini.go +++ b/config/ini.go @@ -147,7 +147,7 @@ type IniConfigContainer struct { // Bool returns the boolean value for a given key. func (c *IniConfigContainer) Bool(key string) (bool, error) { - return strconv.ParseBool(c.getdata(strings.ToLower(key))) + return strconv.ParseBool(c.getdata(key)) } // DefaultBool returns the boolean value for a given key. @@ -162,7 +162,7 @@ func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool { // 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))) + return strconv.Atoi(c.getdata(key)) } // DefaultInt returns the integer value for a given key. @@ -177,7 +177,7 @@ func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int { // 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) + return strconv.ParseInt(c.getdata(key), 10, 64) } // DefaultInt64 returns the int64 value for a given key. @@ -192,7 +192,7 @@ func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64 { // 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) + return strconv.ParseFloat(c.getdata(key), 64) } // DefaultFloat returns the float64 value for a given key. @@ -206,9 +206,8 @@ func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float6 } // 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)) +func (c *IniConfigContainer) String(key string) string { + return c.getdata(key) } // DefaultString returns the string value for a given key. @@ -338,15 +337,16 @@ func (c *IniConfigContainer) DIY(key string) (v interface{}, err error) { // section.key or key func (c *IniConfigContainer) getdata(key string) string { - c.RLock() - defer c.RUnlock() - if len(key) == 0 { + if len(key) == 0 { return "" } + c.RLock() + defer c.RUnlock() + var ( section, k string - sectionKey []string = strings.Split(key, "::") + sectionKey []string = strings.Split(strings.ToLower(key), "::") ) if len(sectionKey) >= 2 { section = sectionKey[0] From ccb61f041669f2108696d005a5f37952279f99b9 Mon Sep 17 00:00:00 2001 From: xianyu Date: Mon, 25 Aug 2014 21:31:53 +0800 Subject: [PATCH 2/2] gofmt Signed-off-by: devYu --- config/ini.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config/ini.go b/config/ini.go index b996a709..1bf2e808 100644 --- a/config/ini.go +++ b/config/ini.go @@ -206,7 +206,7 @@ func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float6 } // String returns the string value for a given key. -func (c *IniConfigContainer) String(key string) string { +func (c *IniConfigContainer) String(key string) string { return c.getdata(key) } @@ -337,12 +337,11 @@ func (c *IniConfigContainer) DIY(key string) (v interface{}, err error) { // section.key or key func (c *IniConfigContainer) getdata(key string) string { - if len(key) == 0 { + if len(key) == 0 { return "" } - c.RLock() + c.RLock() defer c.RUnlock() - var ( section, k string