code style simplify
Showing
2 changed files
with
4 additions
and
7 deletions
| ... | @@ -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") | ... | ... |
-
Please register or sign in to post a comment