Functions - config

contains
I

Checks whether the given key is in the configuration registry.

getAsArray
I

Retrieves the specified configuration value as an array.

getAsBoolean
I

Retrieves the specified configuration value as a boolean.

getAsFloat
I

Retrieves the specified configuration value as a float.

getAsInt
I

Retrieves the specified configuration value as an int.

getAsMap
I

Retrieves the specified configuration value as a map.

getAsString
I

Retrieves the specified configuration value as a string.

setConfig
I

Sets the specified key/value pair as a configuration.

contains

(string key)

returns boolean
Isolated Function

Checks whether the given key is in the configuration registry.

 boolean configAvailable = config:contains("host");

Parameters

  • key string
  • The configuration key to be looked-up

  • Return Type

    (boolean)
  • Returns true if the key is present; if not returs false

getAsArray

(string key)

returns null
Isolated Function

Retrieves the specified configuration value as an array.

 int[]|error ports = config:getAsArray("ports").cloneWithType(int[]);

Parameters

  • key string
  • The key of the configuration to be retrieved

  • Return Type

    (null)
  • Configuration value mapped with the given key. If there is no mapping, an empty array will be returned

getAsBoolean

(string key, boolean defaultValue)

returns boolean
Isolated Function

Retrieves the specified configuration value as a boolean.

 boolean cachingEnabled = config:getAsBoolean("http.caching_enabled");

Parameters

  • key string
  • The key of the configuration to be retrieved

  • defaultValue boolean (default false)
  • The default value to be used in case there is no mapping for the provided key

  • Return Type

    (boolean)
  • Configuration value mapped with the given key

getAsFloat

(string key, float defaultVal)

returns float
Isolated Function

Retrieves the specified configuration value as a float.

 float evictionFactor = config:getAsFloat("http.eviction_factor");

Parameters

  • key string
  • The key of the configuration to be retrieved

  • defaultVal float (default 0.0)
  • The default value to be used in case there is no mapping for the provided key

  • Return Type

    (float)
  • Configuration value mapped with the given key

getAsInt

(string key, int defaultValue)

returns int
Isolated Function

Retrieves the specified configuration value as an int.

 int port = config:getAsInt("http.port");

Parameters

  • key string
  • The key of the configuration to be retrieved

  • defaultValue int (default 0)
  • The default value to be used in case there is no mapping for the provided key

  • Return Type

    (int)
  • Configuration value mapped with the given key

getAsMap

(string key)

returns null
Isolated Function

Retrieves the specified configuration value as a map.

 map<anydata> configValue = config:getAsMap("http.listenerConfig");

Parameters

  • key string
  • The key of the configuration to be retrieved

  • Return Type

    (null)
  • Configuration value mapped with the given key. If there is no mapping, an empty map will be returned

getAsString

(string key, string defaultValue)

returns string
Isolated Function

Retrieves the specified configuration value as a string.

 string host = config:getAsString("http.host");

Parameters

  • key string
  • The key of the configuration to be retrieved

  • defaultValue string
  • The default value to be used in case there is no mapping for the provided key

  • Return Type

    (string)
  • Configuration value mapped with the given key

setConfig

(string key, string | int | float | boolean value)

Isolated Function

Sets the specified key/value pair as a configuration.

 config:setConfig("john.country", "USA");

Parameters

  • key string
  • The key of the configuration value to be set

  • value string | int | float | boolean
  • The configuration value to be set