【问题标题】:What is `<<` and `&` in yaml mean?yaml中的`<<`和`&`是什么意思?
【发布时间】:2018-03-20 08:30:50
【问题描述】:

当我查看 cryptogen(a fabric command) 配置文件时。我看到那里的符号。

Profiles:

    SampleInsecureSolo:
        Orderer:
            <<: *OrdererDefaults  ## what is the `<<`
            Organizations:
                - *ExampleCom     ## what is the `*`
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1ExampleCom
                    - *Org2ExampleCom

上面有两个符号&lt;&lt;*

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

    Organizations:

如您所见,还有另一个符号&amp;。 我不知道有什么意思。即使查看源代码我也没有得到任何信息 (fabric/common/configtx/tool/configtxgen/main.go)

【问题讨论】:

    标签: yaml hyperledger-fabric


    【解决方案1】:

    嗯,这些是 YAML 文件格式的元素,这里用于为configtxgen 提供配置文件。 “&”符号表示锚点,“*”表示锚点,这基本上是为了避免重复,例如:

    person: &person
        name: "John Doe"
    
    employee: &employee
        << : *person
        salary : 5000
    

    将重用 person 的字段,含义类似:

    employee: &employee
        name   : "John Doe"
        salary : 5000
    

    另一个例子是简单地重用值:

    key1: &key some very common value
    
    key2: *key
    

    相当于:

    key1: some very common value
    
    key2: some very common value
    

    由于abric/common/configtx/tool/configtxgen/main.go 使用了现成的 YAML 解析器,您不会在configtxgen 相关代码中找到对这些符号的任何引用。我建议阅读更多关于YAML file format 的内容。

    【讨论】:

    猜你喜欢
    • 2022-10-15
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多