Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
simplify feature enums sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bennetschulz1309 committed Jun 24, 2020
1 parent 8b193b4 commit 0e67bf7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion spring-boot-hello-world-feature-enum/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-spring-boot-starter</artifactId>
<version>2.7.0-SNAPSHOT</version>
<version>2.6.1.Final</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum Features implements Feature {
@EnabledByDefault
HELLO_WORLD,

@Label("")
@Label("another descrition")
REVERSE_GREETING;

public boolean isActive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.togglz.core.Feature;
import org.togglz.core.manager.FeatureManager;
import org.togglz.core.util.NamedFeature;

@RestController
public class HelloWorldController {

private static final String GREETING = "Greetings from Spring Boot!";

private final FeatureManager manager;

public HelloWorldController(FeatureManager manager) {
this.manager = manager;
}

@RequestMapping("/")
public ResponseEntity<?> index() {
if (manager.isActive(Features.HELLO_WORLD)) {
StringBuilder sb = new StringBuilder(GREETING);
if (manager.isActive(Features.REVERSE_GREETING)) {
if (Features.HELLO_WORLD.isActive()) {
StringBuilder sb = new StringBuilder("Greetings from Spring Boot!");
if (Features.REVERSE_GREETING.isActive()) {
sb.reverse();
}
return ResponseEntity.ok().body(sb.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sample;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.togglz.core.manager.EnumBasedFeatureProvider;
import org.togglz.core.spi.FeatureProvider;

@Configuration
public class TogglzConfiguration {

@Bean
public FeatureProvider featureProvider() {
return new EnumBasedFeatureProvider(Features.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ logging:
level:
org.togglz: DEBUG
togglz:
features:
HELLO_WORLD:
enabled: true
REVERSE_GREETING:
enabled: false
console:
secured: false
use-management-port: false

management:
endpoints:
web:
Expand Down

0 comments on commit 0e67bf7

Please sign in to comment.