yaml中的`<<`和`&`是什么意思?
What is `<<` and `&` in yaml mean?
当我查看 cryptogen
(a fabric 命令) 配置文件时。我看到那个符号了。
Profiles:
SampleInsecureSolo:
Orderer:
<<: *OrdererDefaults ## what is the `<<`
Organizations:
- *ExampleCom ## what is the `*`
Consortiums:
SampleConsortium:
Organizations:
- *Org1ExampleCom
- *Org2ExampleCom
上面有两个符号<<
和*
。
Application: &ApplicationDefaults # what is the `&` mean
Organizations:
如您所见,还有另一个符号 &
。
我不知道那是什么意思。我查看源代码也没有得到任何信息(fabric/common/configtx/tool/configtxgen/main.go
)
嗯,这些是 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.
的内容
当我查看 cryptogen
(a fabric 命令) 配置文件时。我看到那个符号了。
Profiles:
SampleInsecureSolo:
Orderer:
<<: *OrdererDefaults ## what is the `<<`
Organizations:
- *ExampleCom ## what is the `*`
Consortiums:
SampleConsortium:
Organizations:
- *Org1ExampleCom
- *Org2ExampleCom
上面有两个符号<<
和*
。
Application: &ApplicationDefaults # what is the `&` mean
Organizations:
如您所见,还有另一个符号 &
。
我不知道那是什么意思。我查看源代码也没有得到任何信息(fabric/common/configtx/tool/configtxgen/main.go
)
嗯,这些是 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.