关于yaml:Y-分钟速成-yaml

源代码下载: learnyaml-cn.yaml YAML 是一种数据序列化语言,旨在让人类间接可写可读。 它是 JSON 的严格超集,减少了在语法上有意义的(syntactically significant)换行符和缩进,就像 Python 一样。但和 Python 的不同之处在于,YAML 不容许应用文字制表符(literal tab characters)来示意缩进。 --- # 文档结尾# YAML 中的正文看起来像这样。################# 标量类型 ################## 咱们的根对象 (贯通整个文档的始终) 是一个映射(map),# 它等价于其它语言中的一个字典(dictionary),哈希表(hash)或对象(object)。key: valueanother_key: Another value goes here.a_number_value: 100# 数字 1 会被解释为数值,而不是一个布尔值。# 如果你想要的是一个布尔值,应用 true。scientific_notation: 1e+12boolean: truenull_value: nullkey with spaces: value# 留神,字符串能够不括在引号里。当然,也能够括在引号里。however: 'A string, enclosed in quotes.''Keys can be quoted too.': "Useful if you want to put a ':' in your key."single quotes: 'have ''one'' escape pattern'double quotes: "have many: \", \0, \t, \u263A, \x0d\x0a == \r\n, and more."# UTF-8/16/32字符须要指明编码(通过\u)。Superscript two: \u00B2# 多行字符串既能够写成一个'字面量块'(应用 '|'),# 也能够写成一个'折叠块'(应用 '>')。literal_block: | This entire block of text will be the value of the 'literal_block' key, with line breaks being preserved. The literal continues until de-dented, and the leading indentation is stripped. Any lines that are 'more-indented' keep the rest of their indentation - these lines will be indented by 4 spaces.folded_style: > This entire block of text will be the value of 'folded_style', but this time, all newlines will be replaced with a single space. Blank lines, like above, are converted to a newline character. 'More-indented' lines keep their newlines, too - this text will appear over two lines.##################### 汇合类型 ###################### 嵌套是通过缩进实现的。举荐应用 2 个空格的缩进(但非必须)。a_nested_map: key: value another_key: Another Value another_nested_map: hello: hello# 映射的键不用是字符串。0.25: a float key# 键也能够是复合(complex)的,比方多行对象# 咱们用 '?' 后跟一个空格来示意一个复合键的开始。? | This is a key that has multiple lines: and this is its value# YAML 也容许应用简单键语法示意序列间的映射关系。# 但有些解析器可能会不反对。# 一个例子:? - Manchester United - Real Madrid: [ 2001-01-01, 2002-02-02 ]# 序列 (sequences,等价于列表 list 或数组 array ) 看起来像这样:# 留神 '-' 也算缩进:a_sequence: - Item 1 - Item 2 - 0.5 # 序列能够蕴含不同类型。 - Item 4 - key: value another_key: another_value - - This is a sequence - inside another sequence - - - Nested sequence indicators - can be collapsed# 因为 YAML 是 JSON 的超集,你也能够写 JSON 格调的映射和序列:json_map: {"key": "value"}json_seq: [3, 2, 1, "takeoff"]and quotes are optional: {key: [3, 2, 1, takeoff]}######################## 其余的 YAML 个性 ######################### YAML 还有一个不便的个性叫“锚”(anchors)。你能够应用它在文档中轻松地实现文本复用。# 如下两个键会有雷同的值:anchored_content: &anchor_name This string will appear as the value of two keys.other_anchor: *anchor_name# 锚也可被用来复制/继承属性base: &base name: Everyone has same name# '<<'称为语言无关的合并键类型(Merge Key Language-Independent Type).# 它表明一个或多个指定映射中的所有键值会插入到以后的映射中。foo: &foo <<: *base age: 10bar: &bar <<: *base age: 20# foo 和 bar 将都含有 name: Everyone has same name# YAML 还有标签(tags),你能够用它显式地申明类型。explicit_string: !!str 0.5# 一些解析器实现了特定语言的标签,就像这个针对Python的复数类型的标签。python_complex_number: !!python/complex 1+2j# 咱们也能够在 YAML 的复合键中应用特定语言的标签:? !!python/tuple [5, 7]: Fifty Seven# 将会是 Python 中的 {(5, 7): 'Fifty Seven'}##################### 其余的 YAML 类型 ###################### 除了字符串和数字,YAML 还反对其它标量。# ISO 格局的日期和工夫字面量也能够被解析。datetime: 2001-12-15T02:59:43.1Zdatetime_with_spaces: 2001-12-14 21:59:43.10 -5date: 2002-12-14# 这个 !!binary 标签表明这个字符串实际上# 是一个用 base64 编码表示的二进制 blob。gif_file: !!binary | R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5 OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=# YAML 还有一个汇合(set)类型,它看起来像这样:set: ? item1 ? item2 ? item3or: {item1, item2, item3}# 汇合只是值均为 null 的映射;下面的汇合等价于:set2: item1: null item2: null item3: null... # 文档完结更多资源YAML official websiteOnline YAML ConverterOnline YAML Validator有倡议?或者发现什么谬误?在Github上开一个 issue ,或者发动 pull request ! ...

December 15, 2022 · 3 min · jiezi

关于yaml:在线YAML转TOML工具

在线YAML转TOML工具在线YAML转TOML工具 TOML 是一种旨在成为一个小规模、易于应用的语义化的配置文件格式,它被设计为能够无二义性的转换为一个哈希表。 "TOML"这个名字是"Tom's Obvious, Minimal Language"的首字母略写词。YAML是一个可读性高,用来表白材料序列化的格局。YAML参考了其余多种语言,包含:C语言、Python、Perl,并从XML、电子邮件的数据格式中取得灵感。 https://tooltt.com/yaml2toml/

January 26, 2022 · 1 min · jiezi

关于yaml:使用yamlv2操作yaml文件

1.装置yaml.v2go get gopkg.in/yaml.v22.复制yaml文件到另外一个文件config/prometheus.yml global: scrape_interval: 15s evaluation_interval: 15salerting: alertmanagers: - static_configs: - targets: - "localhost:9093"rule_files: - "rules/*.yml"scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node' basic_auth: username: prometheus password: 123456 static_configs: - targets: ['localhost:9100']程序 package maintype PrometheusConfig struct{ Global interface{} `yaml:"global"` //具体节点能够具体定义,此处都有空接口进行定义 Alerting interface{} `yaml:"alerting"` RuleRiles []string `yaml:"rule_files"` ScrapeConfigs []interface{} `yaml:"scrape_configs"`}func main(){ f,err := os.Open("config/prometheus.yml") if err != nil { log.Fatal("open file err;",err) } defer f.Close() dec := yaml.NewDecoder(f) var prometheusConfig PrometheusConfig err = dec.Decode(&prometheusConfig) if err != nil { log.Fatal("transfer prometheus config err:",err) } log.Printf("prometheus config:%s \n",prometheusConfig) premetheusV2, err := os.Create("config/prometheus2.yml") if err != nil { log.Fatal("create premetheusV2 err:",err) } defer premetheusV2.Close() encoder := yaml.NewEncoder(premetheusV2) err = encoder.Encode(prometheusConfig) if err != nil { log.Fatal("save prometheus err:",err) }}3.应用例子官网文档 https://pkg.go.dev/gopkg.in/y... ...

July 31, 2021 · 1 min · jiezi

关于yaml:在线YAML转Properties工具

在线YAML转Properties工具在线YAML转Properties工具 YAML:(/jæml/,尾音相似camel骆驼)是一个可读性高,用来表白数据序列化的格局。YAML参考了其余多种语言,包含:C语言、Python、Perl,并从XML、电子邮件的数据格式(RFC 2822)中取得灵感 Properties:用Properties读取配置文件非常简单。Java默认配置文件以.properties为扩展名,每行以key=value示意,以#课结尾的是正文。 https://tooltt.com/yaml2properties/

May 18, 2021 · 1 min · jiezi

关于yaml:在线YAML转JSON工具

在线YAML转JSON工具YAML:(/jæml/,尾音相似camel骆驼)是一个可读性高,用来表白数据序列化的格局。YAML参考了其余多种语言,包含:C语言、Python、Perl,并从XML、电子邮件的数据格式(RFC 2822)中取得灵感JSON:(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格局。它基于 ECMAScript (欧洲计算机协会制订的js标准)的一个子集,采纳齐全独立于编程语言的文本格式来存储和示意数据。在线YAML转JSON工具 https://tooltt.com/yaml2json/

May 18, 2021 · 1 min · jiezi

关于yaml:在线YAML转HTML工具

在线YAML转HTML工具在线YAML转HTML工具 YAML:(/jæml/,尾音相似camel骆驼)是一个可读性高,用来表白数据序列化的格局。YAML参考了其余多种语言,包含:C语言、Python、Perl,并从XML、电子邮件的数据格式(RFC 2822)中取得灵感 HTML:的全称为超文本标记语言,是一种标记语言。它包含一系列标签.通过这些标签能够将网络上的文档格局对立,使扩散的Internet资源连贯为一个逻辑整体。 https://tooltt.com/yaml2html/

May 18, 2021 · 1 min · jiezi

关于yaml:在线YAML转CSV工具

在线YAML转CSV工具在线YAML转CSV工具 YAML:(/jæml/,尾音相似camel骆驼)是一个可读性高,用来表白数据序列化的格局。YAML参考了其余多种语言,包含:C语言、Python、Perl,并从XML、电子邮件的数据格式(RFC 2822)中取得灵感 CSV:逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也能够不是逗号),其文件以纯文本模式存储表格数据(数字和文本)。 https://tooltt.com/yaml2csv/

May 17, 2021 · 1 min · jiezi