Skip to content

Commit

Permalink
Added error checks for getters
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatrykx committed Jul 26, 2021
1 parent 4787f63 commit a57ff7b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cmd/sriovdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ func main() {
}

config.NewConfig()
cfg := config.GetConfig()

cfg, err := config.GetConfig()
if err != nil {
glog.Fatalf("error while getting config: %v", err)
return
}

// Read global config
if err := cfg.ReadConfig(cp.configFile); err != nil {
Expand All @@ -73,7 +78,12 @@ func main() {
}

features.NewFeatureGate()
fg := features.GetFeatureGate()

fg, err := features.GetFeatureGate()
if err != nil {
glog.Fatalf("error while getting feature gate: %v", err)
return
}

// Set FeatureGates with ConfigMap
if err := fg.SetFromMap(cfg.FeatureGates); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ func NewConfig() {
}

// GetConfig returns config
func GetConfig() *Config {
return cfg
func GetConfig() (*Config, error) {
var err error
if cfg == nil {
err = fmt.Errorf("config was not initialized")
}
return cfg, err
}

func newConfig() *Config {
Expand Down
8 changes: 6 additions & 2 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ func NewFeatureGate() {
}

// GetFeatureGate returns current feature gate
func GetFeatureGate() *FeatureGate {
return fg
func GetFeatureGate() (*FeatureGate, error) {
var err error
if fg == nil {
err = fmt.Errorf("feature gate object was not initialized")
}
return fg, err
}

func newFeatureGate() *FeatureGate {
Expand Down

0 comments on commit a57ff7b

Please sign in to comment.