Created
February 20, 2018 16:36
-
-
Save paolobueno/69c8e3a5809add431d1252f61a110036 to your computer and use it in GitHub Desktop.
Config overload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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