Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: go/util/util.go

Issue 1300273002: Reland of Add a library for running external commands, providing timeouts and test injection. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Fix squashWriters for struct arguments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/util/command.go ('k') | go/util/util_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/util/util.go
diff --git a/go/util/util.go b/go/util/util.go
index d43c6058f67d8869071deab3a29a1176fca3c232..c1b3cca8519680683eb6fcc40ea7b1b2e2167bb0 100644
--- a/go/util/util.go
+++ b/go/util/util.go
@@ -7,6 +7,7 @@ import (
"io"
mathrand "math/rand"
"os"
+ "reflect"
"regexp"
"runtime"
"sort"
@@ -445,3 +446,32 @@ func AnyMatch(re []*regexp.Regexp, s string) bool {
}
return false
}
+
+// Returns true if i is nil or is an interface containing a nil or invalid value.
+func IsNil(i interface{}) bool {
+ if i == nil {
+ return true
+ }
+ v := reflect.ValueOf(i)
+ if !v.IsValid() {
+ return true
+ }
+ switch v.Kind() {
+ case reflect.Chan, reflect.Func, reflect.Map, reflect.Slice:
+ return v.IsNil()
+ case reflect.Interface, reflect.Ptr:
+ if v.IsNil() {
+ return true
+ }
+ inner := v.Elem()
+ if !inner.IsValid() {
+ return true
+ }
+ if inner.CanInterface() {
+ return IsNil(inner.Interface())
+ }
+ return false
+ default:
+ return false
+ }
+}
« no previous file with comments | « go/util/command.go ('k') | go/util/util_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698