Skip to content

Instantly share code, notes, and snippets.

@paolobueno
Created February 20, 2018 16:36
Show Gist options
  • Select an option

  • Save paolobueno/69c8e3a5809add431d1252f61a110036 to your computer and use it in GitHub Desktop.

Select an option

Save paolobueno/69c8e3a5809add431d1252f61a110036 to your computer and use it in GitHub Desktop.
Config overload
export interface IKeycloakConfig {}
export interface IMetricsConfig {}
export class Config {
private serviceConfig: any[] = [];
/**
* @param config - any type of configuration that will be send from server.
* It's not possible easy/worth to wrap that to types. Even native implementations do not do that.
*/
constructor(config: any) {
if(config && config.services){
this.serviceConfig = config.services;
}
}
public getKeycloakConfig(): IKeycloakConfig {
return this.configByKey('keycloak')
}
public getMetricsConfig(): IMetricsConfig {
return this.configByKey('metrics')
}
public configByKey(key: 'keycloak'): IKeycloakConfig
public configByKey(key: 'metrics'): IMetricsConfig
public configByKey(key: String): any {
return this.serviceConfig.filter(config => config.type = key);
}
}
export default Config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment