Skip to content

Commit

Permalink
Better config management.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Sep 13, 2018
1 parent 1d2674c commit 5dec8f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

An extremely lightweight, flexible, and high performance [Undertow](http://undertow.io) based Java framework for developing and running microservices.

JAX-RS compliant.

Verifiably [FAST](https://www.techempower.com/benchmarks/): [The latest benchmarks](https://www.techempower.com/benchmarks/) show Proteus ranks faster than 99% of other Java frameworks.

Inspired by [Play](http://playframework.com), [Jooby](http://jooby.org), and [light-4j](https://github.com/networknt/light-4j).
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/io/sinistral/proteus/modules/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,24 @@ public ConfigModule(URL configURL)

@Override
protected void configure()
{
if(configFile == null && configURL == null)
{
this.bindConfig(ConfigFactory.defaultApplication());
}
else if(configURL != null)
{
this.bindConfig( ConfigFactory.load(ConfigFactory.parseURL(configURL)));
{
Config config = ConfigFactory.defaultApplication();

Config referenceConfig = ConfigFactory.load(ConfigFactory.defaultReference());

config = ConfigFactory.load(config).withFallback(referenceConfig);

if(configURL != null)
{
config = ConfigFactory.load(ConfigFactory.parseURL(configURL)).withFallback(config);
}
else if(configFile != null)
{
this.bindConfig(fileConfig(configFile));
{

config = fileConfig(configFile).withFallback(config);
}

this.bindConfig(config);

install(new ApplicationModule(this.config));
}
Expand All @@ -84,6 +89,7 @@ else if(configFile != null)
@SuppressWarnings("unchecked")
private void bindConfig(final Config config)
{

traverse(this.binder(), "", config.root());

for (Entry<String, ConfigValue> entry : config.entrySet())
Expand All @@ -102,6 +108,7 @@ private void bindConfig(final Config config)

Key<Object> key = (Key<Object>) Key.get(listType, Names.named(name));


this.binder().bind(key).toInstance(values);
}
else
Expand All @@ -126,14 +133,15 @@ private static void traverse(final Binder binder, final String nextPath, final C
{
rootConfig.forEach((key, value) ->
{

if (value instanceof ConfigObject)
{
ConfigObject child = (ConfigObject) value;

String path = nextPath + key;

Named named = Names.named(path);

binder.bind(Config.class).annotatedWith(named).toInstance(child.toConfig());

traverse(binder, path + ".", child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
Expand Down Expand Up @@ -74,7 +75,7 @@
import io.undertow.util.Methods;


@Singleton
public class SwaggerService extends BaseService implements Supplier<RoutingHandler>
{

Expand Down

0 comments on commit 5dec8f0

Please sign in to comment.