Config.fromYaml constructor Null safety

Config.fromYaml(
  1. Map doc
)

Factory constructor to build your database configuration using a provided config.yaml file The config.yaml must have a layout like this one:

name: Test
port: 3031
db: db.json
statics: public
host: 0.0.0.0
auth:
  key: dasdrfgdfvkjbkhvjgfigiuhwiodfuhfiyq
  exp: 3600
  aud: test.dd
  scape:
    - animals
    - cities

Be aware that the Auth part is created from the Auth.fromYaml factory so it should have it's contents also ready if you are going to use the Auth Service in your database.

Implementation

factory Config.fromYaml(Map doc) {
  return Config(
    name: doc['name'],
    db: Database(doc['db']),
    port: doc['port'],
    statics: doc['statics'] ?? 'public',
    storage: doc['storage'] == null
        ? null
        : Storage.fromYaml(
            doc['storage'],
          ),
    auth: doc['auth'] == null
        ? null
        : AuthService.fromYaml(
            doc['auth'],
          ),
    host: doc['host'],
  );
}