func trimNonAlphaNumeric(text string) string {
	newText := regexpEndReplace.ReplaceAllString(text, "")
	return regexpBeginReplace.ReplaceAllString(newText, "")
}
trimNonAlphaNumeric remove all non-alphanumeric values from start and end of the string
package util
import (
	"fmt"
	"regexp"
)
var regexpEndReplace, regexpBeginReplace *regexp.Regexp
func init() {
	regexpEndReplace, _ = regexp.Compile("[^A-Za-z0-9]+$")
	regexpBeginReplace, _ = regexp.Compile("^[^A-Za-z0-9]+")
}
func Truncate(format string, max int, values ...interface{}) string {
	var truncated []interface{}
	result := fmt.Sprintf(format, values...)
	if excess := len(result) - max; excess > 0 {
		for _, value := range values {
			if excess == 0 {
				continue
			}
			if s, ok := value.(string); ok {
				if len(s) > excess {
					value = s[:len(s)-excess]
					excess = 0
				} else {
					value = ""  
					excess = excess - len(s)
				}
			}
			truncated = append(truncated, value)
		}
		result = fmt.Sprintf(format, truncated...)
	}
	if len(result) > max {
		return result[:max]
	}
	return trimNonAlphaNumeric(result)
}