route_mappings.go
func (a *App) buildRouteName(p string) string {
	if p == "/" || p == "" {
		return "root"
	}

	resultParts := []string{}
	parts := strings.Split(p, "/")

	for index, part := range parts {

		if strings.Contains(part, "{") || part == "" {
			continue
		}

		shouldSingularize := (len(parts) > index+1) && strings.Contains(parts[index+1], "{")
		if shouldSingularize {
			part = flect.Singularize(part)
		}

		if parts[index] == "new" || parts[index] == "edit" {
			resultParts = append([]string{part}, resultParts...)
			continue
		}

		if index > 0 && strings.Contains(parts[index-1], "}") {
			resultParts = append(resultParts, part)
			continue
		}

		resultParts = append(resultParts, part)
	}

	if len(resultParts) == 0 {
		return "unnamed"
	}

	underscore := strings.TrimSpace(strings.Join(resultParts, "_"))
	return name.VarCase(underscore)
}
func (a *App) buildRouteName(p string) string {
	if p == "/" || p == "" {
		return "root"
	}

	resultParts := []string{}
	parts := strings.Split(p, "/")

	for index, part := range parts {

		if strings.Contains(part, "{") || part == "" {
			continue
		}

		shouldSingularize := (len(parts) > index+1) && strings.Contains(parts[index+1], "{")
		if shouldSingularize {
			part = flect.Singularize(part)
		}

		if parts[index] == "new" || parts[index] == "edit" {
			resultParts = append([]string{part}, resultParts...)
			continue
		}

		if index > 0 && strings.Contains(parts[index-1], "}") {
			resultParts = append(resultParts, part)
			continue
		}

		resultParts = append(resultParts, part)
	}

	if len(resultParts) == 0 {
		return "unnamed"
	}

	underscore := strings.TrimSpace(strings.Join(resultParts, "_"))
	return name.VarCase(underscore)
}
func ( a * App ) buildRouteName ( p string ) string { if p == " " || p == " " { return " " } resultParts := [ ] string { } parts := strings . Split ( p , " " ) for index , part := range parts { if strings . Contains ( part , " " ) || part == " " { continue } shouldSingularize := ( len ( parts ) > index + 1 ) && strings . Contains ( parts [ index + 1 ] , " " ) if shouldSingularize { part = flect . Singularize ( part ) } if parts [ index ] == " " || parts [ index ] == " " { resultParts = append ( [ ] string { part } , resultParts ... ) continue } if index > 0 && strings . Contains ( parts [ index - 1 ] , " " ) { resultParts = append ( resultParts , part ) continue } resultParts = append ( resultParts , part ) } if len ( resultParts ) == 0 { return " " } underscore := strings . TrimSpace ( strings . Join ( resultParts , " " ) ) return name . VarCase ( underscore ) }
//buildRouteName builds a route based on the path passed.
buildRouteName builds a route based on the path passed .