More complex inheritance in YAML?

后端 未结 3 1997
南方客
南方客 2021-01-31 02:00

YAML has inheritance. The most clear example I have ever seen is here: http://blog.101ideas.cz/posts/dry-your-yaml-files.html

I need something more complex: I need to ov

3条回答
  •  萌比男神i
    2021-01-31 02:16

    How about this? Use multiple anchors.

    database: &default
      server: &server
        ip: 192.168.1.5
        port: 2000
      db_name: test
      user: &user
        name: root
        password: root
    
    foo_database:
      <<: *default
      server:
        << : *server
        port: 2001
      db_name: foo
      user:
        << : *user
        password: foo_root
    

    It's just a little extra work, and slightly harder to read than if what you wanted were built into YAML as you suggested (I thought it would work that way too). But overall not bad.

提交回复
热议问题