Domanda

I'm writing a config file for grails app where I want to define redirect patterns. I've written a config script RedirectMappingsConfig.groovy:

import java.util.regex.Pattern

def c = {pattern, goto, path ->
    if (pattern instanceof Pattern && pattern.matcher(path).matches()) {
        return goto
    }
    return false
}

def redirectFromTo = [
        c.curry(Pattern.compile('/si/reference.*'), '/enterprise-solutions/references-and-partners#references'),
        c.curry(Pattern.compile('/si/kontakt.*'), '/contact-us'),
        c.curry(Pattern.compile('/si/zaposlitve.*'), '/careers'),
        c.curry(Pattern.compile('/aa'), '/')
]

This list will be read in a filter which will perform redirect if some pattern matches request uri.

Problem: application does not compile, the error is:

Compilation error: startup failed:
RedirectMappingsConfig.groovy: 3: unexpected token: pattern @ line 3, column 10.
   def c = {pattern, goto, path ->
            ^

Any idea what is wrong with the syntax? I'm using grails 2.1.1.

È stato utile?

Soluzione

goto is a reserved word in Groovy... Change your closure to:

def c = {pattern, addr, path ->
    if (pattern instanceof Pattern && pattern.matcher(path).matches()) {
        return addr
    }
    return false
}

And this error should go away :-)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top