Skip to content

Commit

Permalink
Remove package variables
Browse files Browse the repository at this point in the history
Kubernetes-commit: 87494389ac7987ed9586190dc9566669b33a9f7c
  • Loading branch information
liggitt authored and k8s-publishing-bot committed Apr 22, 2022
1 parent 28c4a4d commit 7481505
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
13 changes: 5 additions & 8 deletions third_party/forked/golang/template/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ import (
"reflect"
)

var Indirect = indirect
var PrintableValue = printableValue

var (
errorType = reflect.TypeOf((*error)(nil)).Elem()
fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
)

// indirect returns the item at the end of indirection, and a bool to indicate if it's nil.
// Indirect returns the item at the end of indirection, and a bool to indicate if it's nil.
// We indirect through pointers and empty interfaces (only) because
// non-empty interfaces have methods we might need.
func indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
func Indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
for ; v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface; v = v.Elem() {
if v.IsNil() {
return v, true
Expand All @@ -31,11 +28,11 @@ func indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
return v, false
}

// printableValue returns the, possibly indirected, interface value inside v that
// PrintableValue returns the, possibly indirected, interface value inside v that
// is best for a call to formatted printer.
func printableValue(v reflect.Value) (interface{}, bool) {
func PrintableValue(v reflect.Value) (interface{}, bool) {
if v.Kind() == reflect.Ptr {
v, _ = indirect(v) // fmt.Fprint handles nil.
v, _ = Indirect(v) // fmt.Fprint handles nil.
}
if !v.IsValid() {
return "<no value>", true
Expand Down
41 changes: 17 additions & 24 deletions third_party/forked/golang/template/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import (
"reflect"
)

var Equal = eq
var GreaterEqual = ge
var Greater = gt
var LessEqual = le
var Less = lt
var NotEqual = ne

var (
errBadComparisonType = errors.New("invalid type for comparison")
errBadComparison = errors.New("incompatible types for comparison")
Expand Down Expand Up @@ -52,8 +45,8 @@ func basicKind(v reflect.Value) (kind, error) {
return invalidKind, errBadComparisonType
}

// eq evaluates the comparison a == b || a == c || ...
func eq(arg1 interface{}, arg2 ...interface{}) (bool, error) {
// Equal evaluates the comparison a == b || a == c || ...
func Equal(arg1 interface{}, arg2 ...interface{}) (bool, error) {
v1 := reflect.ValueOf(arg1)
k1, err := basicKind(v1)
if err != nil {
Expand Down Expand Up @@ -104,15 +97,15 @@ func eq(arg1 interface{}, arg2 ...interface{}) (bool, error) {
return false, nil
}

// ne evaluates the comparison a != b.
func ne(arg1, arg2 interface{}) (bool, error) {
// NotEqual evaluates the comparison a != b.
func NotEqual(arg1, arg2 interface{}) (bool, error) {
// != is the inverse of ==.
equal, err := eq(arg1, arg2)
equal, err := Equal(arg1, arg2)
return !equal, err
}

// lt evaluates the comparison a < b.
func lt(arg1, arg2 interface{}) (bool, error) {
// Less evaluates the comparison a < b.
func Less(arg1, arg2 interface{}) (bool, error) {
v1 := reflect.ValueOf(arg1)
k1, err := basicKind(v1)
if err != nil {
Expand Down Expand Up @@ -153,30 +146,30 @@ func lt(arg1, arg2 interface{}) (bool, error) {
return truth, nil
}

// le evaluates the comparison <= b.
func le(arg1, arg2 interface{}) (bool, error) {
// LessEqual evaluates the comparison <= b.
func LessEqual(arg1, arg2 interface{}) (bool, error) {
// <= is < or ==.
lessThan, err := lt(arg1, arg2)
lessThan, err := Less(arg1, arg2)
if lessThan || err != nil {
return lessThan, err
}
return eq(arg1, arg2)
return Equal(arg1, arg2)
}

// gt evaluates the comparison a > b.
func gt(arg1, arg2 interface{}) (bool, error) {
// Greater evaluates the comparison a > b.
func Greater(arg1, arg2 interface{}) (bool, error) {
// > is the inverse of <=.
lessOrEqual, err := le(arg1, arg2)
lessOrEqual, err := LessEqual(arg1, arg2)
if err != nil {
return false, err
}
return !lessOrEqual, nil
}

// ge evaluates the comparison a >= b.
func ge(arg1, arg2 interface{}) (bool, error) {
// GreaterEqual evaluates the comparison a >= b.
func GreaterEqual(arg1, arg2 interface{}) (bool, error) {
// >= is the inverse of <.
lessThan, err := lt(arg1, arg2)
lessThan, err := Less(arg1, arg2)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 7481505

Please sign in to comment.