Refactor pattern of ok !ok

This commit is contained in:
Arturo Filastò 2020-01-07 16:44:11 +02:00
parent 2cb6661340
commit 427ca18985

View File

@ -26,16 +26,19 @@ type PsiphonTestKeys struct {
// GetTestKeys generates a summary for a test run // GetTestKeys generates a summary for a test run
func (h Psiphon) GetTestKeys(tk map[string]interface{}) (interface{}, error) { func (h Psiphon) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
var err error var (
err error
ok bool
)
testKeys := PsiphonTestKeys{IsAnomaly: false, Failure: ""} testKeys := PsiphonTestKeys{IsAnomaly: false, Failure: ""}
if tk["failure"] != nil { if tk["failure"] != nil {
testKeys.IsAnomaly = true testKeys.IsAnomaly = true
testKeys.Failure, ok := tk["failure"].(string) testKeys.Failure, ok = tk["failure"].(string)
if !ok { if !ok {
err = errors.Wrap(err, "failure key invalid") err = errors.Wrap(err, "failure key invalid")
} }
} }
testKeys.BootstrapTime, ok := tk["bootstrap_time"].(float64) testKeys.BootstrapTime, ok = tk["bootstrap_time"].(float64)
if !ok { if !ok {
err = errors.Wrap(err, "bootstrap_time key invalid") err = errors.Wrap(err, "bootstrap_time key invalid")
} }