Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Feature Switching plugin for Grails 2

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 grails-app
Octocat-spinner-32 scripts
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 web-app
Octocat-spinner-32 wrapper
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 FeatureSwitchGrailsPlugin.groovy
Octocat-spinner-32 README.markdown
Octocat-spinner-32 application.properties
Octocat-spinner-32 grailsw
README.markdown

Build Status

Feature Switcher Plugin for Grails

Configuration

Features can be turned on and off in your configuration using the following format

  features {
    myfeature {
      enabled = true
    }
  }

Where myfeature is the name of the feature you are configuring.

Usage in Controllers and Services

To execute a block of code when the feature 'myfeature' is enabled:

  withFeature('myfeature') {
    // do something
  }

When the feature 'myfeature' is not enabled:

  withoutFeature('myfeature') {
    // do something
  }

Usage in GSPs

To execute some markup when the feature 'myfeature' is enabled:

  <feature:enabled feature="myfeature">
     <h1>The feature is enabled!</h1>
  </feature:enabled>

And the same only when the feature is not enabled:

  <feature:disabled feature="myfeature">
    <h1>The feature is disabled!</h1>
  </feature:disabled>

Toggling switches via the admin page

The admin page is accessible at

http://localhost:8080/your-app/admin/features

Features highlighted in green are enabled, and those in red are disabled. Clicking the 'toggle' button on any feature will disable or enable that particular feature.

If you want to toggle features easily in a test, you can simply hit the url

http://localhost:8080/your-app/admin/feature/myfeature

which will toggle that feature on or off depending on its current state.

These state changes will only last as long as the application is running, the state is not persisted and is read from configuration on start-up.

Toggling switches via a restful URL

The restful urls for enabling and disabling features are:

To enable:

http://localhost:8080/feature-switch/admin/features/<your-feature-name>/enable

To disable:

http://localhost:8080/feature-switch/admin/features/<your-feature-name>/disable

The response from these is a JSON result explaining if the feature has been enabled or disabled:

{"your-feature-name": "disabled"}

Toggling of a non-existent feature will cause a 500 with an IllegalArgumentException including the name of the feature.

Something went wrong with that request. Please try again.