readConfig static method

Map<String, DVHttpHostConfig> readConfig(
  1. Map<Object?, Object?> http
)

Reads and checks a dartvel.http block into its hosts, declaring nothing. The generator checks a pubspec with this before it writes a file, and the application declares with the same reader at startup, so the two cannot disagree about what the block says.

Throws an ArgumentError naming the first key it does not understand.

Implementation

static Map<String, DVHttpHostConfig> readConfig(Map<Object?, Object?> http) {
  _onlyKeys('dartvel.http', http, const <String>{'hosts'});
  final Map<Object?, Object?>? hosts = _block('dartvel.http', http, 'hosts');
  final Map<String, DVHttpHostConfig> out = <String, DVHttpHostConfig>{};
  if (hosts == null) return out;
  for (final MapEntry<Object?, Object?> entry in hosts.entries) {
    final String name = '${entry.key}';
    if (!RegExp(r'^[A-Za-z][A-Za-z0-9_-]*$').hasMatch(name)) {
      throw ArgumentError('dartvel.http.hosts."$name" is not a host name; a '
          'name starts with a letter and holds letters, digits, _ and -.');
    }
    final Object? value = entry.value;
    if (value is! Map) {
      throw ArgumentError('dartvel.http.hosts.$name must be a map.');
    }
    out[name] =
        DVHttpHostConfig.fromConfig(name, value.cast<String, Object?>());
  }
  return out;
}