From b4612dcfe009228a3657589490de337c3085be4f Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Fri, 3 Jun 2016 19:53:00 +0300 Subject: [PATCH] Custom func {{ url }} accepts array of strings as parameters also , example updated --- route.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/route.go b/route.go index 5e3b052c..a898564b 100644 --- a/route.go +++ b/route.go @@ -195,6 +195,11 @@ func (r *Route) Parse(args ...interface{}) (string, bool) { argsString[i] = strconv.Itoa(num) } else if b, ok := v.(bool); ok { argsString[i] = strconv.FormatBool(b) + } else if arr, ok := v.([]string); ok { + if len(arr) > 0 { + argsString[i] = arr[0] + argsString = append(argsString, arr[1:]...) + } } } @@ -206,7 +211,24 @@ func (r *Route) Parse(args ...interface{}) (string, bool) { return "", false } - return fmt.Sprintf(r.formattedPath, args...), true + arguments := args[0:] + + // check for arrays + for i, v := range arguments { + if arr, ok := v.([]string); ok { + if len(arr) > 0 { + interfaceArr := make([]interface{}, len(arr)) + for j, sv := range arr { + interfaceArr[j] = sv + } + arguments[i] = interfaceArr[0] + arguments = append(arguments, interfaceArr[1:]...) + } + + } + } + + return fmt.Sprintf(r.formattedPath, arguments...), true } // GetURI returns the GetDomain() + Parse(...optional named parameters if route is dynamic)