quick/config: No need to use Data() with type assertion. (#1480)

Since input to quick.New() is a pointer the unmarshalled value
internally already has the value, subsequent type assertions
are not needed.

Thanks to Bala for finding this behavior.

Fixes #1475
master
Harshavardhana 9 years ago
parent 9dccbd6478
commit f145e1042f
  1. 24
      config-old.go
  2. 2
      config-v4.go

@ -24,16 +24,16 @@ func loadConfigV1() (*configV1, error) {
if _, err = os.Stat(configFile); err != nil { if _, err = os.Stat(configFile); err != nil {
return nil, err return nil, err
} }
a := &configV1{} c := &configV1{}
a.Version = "1" c.Version = "1"
qc, err := quick.New(a) qc, err := quick.New(c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := qc.Load(configFile); err != nil { if err := qc.Load(configFile); err != nil {
return nil, err return nil, err
} }
return qc.Data().(*configV1), nil return c, nil
} }
/////////////////// Config V2 /////////////////// /////////////////// Config V2 ///////////////////
@ -67,16 +67,16 @@ func loadConfigV2() (*configV2, error) {
if _, err = os.Stat(configFile); err != nil { if _, err = os.Stat(configFile); err != nil {
return nil, err return nil, err
} }
a := &configV2{} c := &configV2{}
a.Version = "2" c.Version = "2"
qc, err := quick.New(a) qc, err := quick.New(c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := qc.Load(configFile); err != nil { if err := qc.Load(configFile); err != nil {
return nil, err return nil, err
} }
return qc.Data().(*configV2), nil return c, nil
} }
/////////////////// Config V3 /////////////////// /////////////////// Config V3 ///////////////////
@ -134,14 +134,14 @@ func loadConfigV3() (*configV3, error) {
if _, err = os.Stat(configFile); err != nil { if _, err = os.Stat(configFile); err != nil {
return nil, err return nil, err
} }
a := &configV3{} c := &configV3{}
a.Version = "3" c.Version = "3"
qc, err := quick.New(a) qc, err := quick.New(c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := qc.Load(configFile); err != nil { if err := qc.Load(configFile); err != nil {
return nil, err return nil, err
} }
return qc.Data().(*configV3), nil return c, nil
} }

@ -87,7 +87,7 @@ func initConfig() error {
return err return err
} }
// Save the loaded config globally. // Save the loaded config globally.
serverConfig = qc.Data().(*serverConfigV4) serverConfig = srvCfg
// Set the version properly after the unmarshalled json is loaded. // Set the version properly after the unmarshalled json is loaded.
serverConfig.Version = globalMinioConfigVersion serverConfig.Version = globalMinioConfigVersion
return nil return nil

Loading…
Cancel
Save