From 2fdf8d5dc3e6883957bf34adc7030d10c2cd1ebb Mon Sep 17 00:00:00 2001 From: Toshaan Bharvani Date: Wed, 7 Feb 2018 14:51:07 +0100 Subject: [PATCH] lang: Interface sorting order as golang does not loop over the same map/list always the same we use a helper list to sort it Signed-off-by: Toshaan Bharvani --- lang/funcs/operator_polyfunc.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lang/funcs/operator_polyfunc.go b/lang/funcs/operator_polyfunc.go index bf93cbdc..d68d3501 100644 --- a/lang/funcs/operator_polyfunc.go +++ b/lang/funcs/operator_polyfunc.go @@ -20,6 +20,7 @@ package funcs // this is here, in case we allow others to register operators... import ( "fmt" "math" + "sort" "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" @@ -376,9 +377,13 @@ func LookupOperator(operator string, size int) ([]*types.Type, error) { results := []*types.Type{} if operator == "" { - // FIXME: loop this in sorted order... - for _, a := range OperatorFuncs { - fns = append(fns, a...) + var keys []string + for k := range OperatorFuncs { + keys = append(keys, k) + } + sort.Strings(keys) + for _, a := range keys { + fns = append(fns, OperatorFuncs[a]...) } }