yaml中的`<<`和`&`是什么意思?

bla*_*dog 8 yaml hyperledger-fabric

当我查看cryptogen(一个结构命令)配置文件.我看到那里的象征.

Profiles:

    SampleInsecureSolo:
        Orderer:
            <<: *OrdererDefaults  ## what is the `<<`
            Organizations:
                - *ExampleCom     ## what is the `*`
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1ExampleCom
                    - *Org2ExampleCom
Run Code Online (Sandbox Code Playgroud)

上面有两个符号<<*.

Application: &ApplicationDefaults  # what is the `&` mean

    Organizations:
Run Code Online (Sandbox Code Playgroud)

如你所见,还有另一个符号&.我不知道有什么意思.我甚至没有通过查看源代码获得任何信息(fabric/common/configtx/tool/configtxgen/main.go)

Art*_*ger 13

那些,这些是YAML文件格式的元素,这里用于提供配置文件configtxgen."&"符号意味着锚和"*"引用锚,这基本上用于避免重复,例如:

person: &person
    name: "John Doe"

employee: &employee
           : << *person
    salary : 5000
Run Code Online (Sandbox Code Playgroud)

将重用人的领域并具有类似的含义:

employee: &employee
    name   : "John Doe"
    salary : 5000
Run Code Online (Sandbox Code Playgroud)

另一个例子就是重用价值:

key1: &key some very common value

key2: *key
Run Code Online (Sandbox Code Playgroud)

相当于:

key1: some very common value

key2: some very common value
Run Code Online (Sandbox Code Playgroud)

由于abric/common/configtx/tool/configtxgen/main.go使用了架子YAML解析器,您在configtxgen相关代码中找不到对这些符号的任何引用.我建议您阅读更多关于YAML文件格式的内容.

  • @Wappenull:我可以确认您的修复并相应地更新了答案。 (3认同)
  • 在https://yaml-online-parser.appspot.com/中尝试了您的':&lt;&lt; * person'行,但编译失败。那行应该是'&lt;&lt;:* person'。而&lt;&lt;需要在下一行缩进薪水。 (2认同)