20e05a39 by fuxiaohei

code style simplify

1 parent 77c40e6f
...@@ -39,7 +39,7 @@ func Register(name string, adapter Config) { ...@@ -39,7 +39,7 @@ func Register(name string, adapter Config) {
39 if adapter == nil { 39 if adapter == nil {
40 panic("config: Register adapter is nil") 40 panic("config: Register adapter is nil")
41 } 41 }
42 if _, dup := adapters[name]; dup { 42 if _, ok := adapters[name]; ok {
43 panic("config: Register called twice for adapter " + name) 43 panic("config: Register called twice for adapter " + name)
44 } 44 }
45 adapters[name] = adapter 45 adapters[name] = adapter
......
...@@ -20,13 +20,11 @@ type fakeConfigContainer struct { ...@@ -20,13 +20,11 @@ type fakeConfigContainer struct {
20 } 20 }
21 21
22 func (c *fakeConfigContainer) getData(key string) string { 22 func (c *fakeConfigContainer) getData(key string) string {
23 key = strings.ToLower(key) 23 return c.data[strings.ToLower(key)]
24 return c.data[key]
25 } 24 }
26 25
27 func (c *fakeConfigContainer) Set(key, val string) error { 26 func (c *fakeConfigContainer) Set(key, val string) error {
28 key = strings.ToLower(key) 27 c.data[strings.ToLower(key)] = val
29 c.data[key] = val
30 return nil 28 return nil
31 } 29 }
32 30
...@@ -55,8 +53,7 @@ func (c *fakeConfigContainer) Float(key string) (float64, error) { ...@@ -55,8 +53,7 @@ func (c *fakeConfigContainer) Float(key string) (float64, error) {
55 } 53 }
56 54
57 func (c *fakeConfigContainer) DIY(key string) (interface{}, error) { 55 func (c *fakeConfigContainer) DIY(key string) (interface{}, error) {
58 key = strings.ToLower(key) 56 if v, ok := c.data[strings.ToLower(key)]; ok {
59 if v, ok := c.data[key]; ok {
60 return v, nil 57 return v, nil
61 } 58 }
62 return nil, errors.New("key not find") 59 return nil, errors.New("key not find")
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!