diff options
Diffstat (limited to 'common/types/types.go')
-rw-r--r-- | common/types/types.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/common/types/types.go b/common/types/types.go index 95e72d99b..f03031439 100644 --- a/common/types/types.go +++ b/common/types/types.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Hugo Authors. All rights reserved. +// Copyright 2019 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package types import ( "fmt" + "reflect" "github.com/spf13/cast" ) @@ -56,3 +57,24 @@ func NewKeyValuesStrings(key string, values ...string) KeyValues { type Zeroer interface { IsZero() bool } + +// IsNil reports whether v is nil. +func IsNil(v interface{}) bool { + if v == nil { + return true + } + + value := reflect.ValueOf(v) + switch value.Kind() { + case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: + return value.IsNil() + } + + return false +} + +// DevMarker is a marker interface for types that should only be used during +// development. +type DevMarker interface { + DevOnly() +} |