Skip to content

Commit

Permalink
code block lang
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Oct 29, 2024
1 parent 6af0d08 commit d235c7d
Show file tree
Hide file tree
Showing 59 changed files with 229 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hide_title: true

示例配置:

```
```yaml
viewpath: "/home/www/templates/"
database:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *AdapterFile) ClearContent()

在默认提供的文件系统接口实现下, `gcfg` 组件支持按层级获取配置数据,层级访问默认通过英文 `.` 号指定,其中 `pattern` 参数和 [通用编解码-gjson](/docs/组件列表/编码解码/通用编解码-gjson) 的 `pattern` 参数一致。例如以下配置( `config.yaml`):

```
```yaml
server:
address: ":8199"
serverRoot: "resource/public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hide_title: true

`config.yaml`

```
```yaml
server:
address: ":8888"
openapiPath: "/api.json"
Expand Down Expand Up @@ -59,7 +59,7 @@ map[debug:true link:mysql:root:12345678@tcp(127.0.0.1:3306)/test]
`config.yaml`
```
```yaml
server:
address: ":8888"
openapiPath: "/api.json"
Expand Down
34 changes: 17 additions & 17 deletions docs/4-核心组件/3-配置管理/5-配置管理-TOML格式.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hide_title: true

## 基础语法

```
```toml
title = "TOML 例子"

[owner]
Expand Down Expand Up @@ -73,7 +73,7 @@ hosts = [

使用 `#` 表示注释:

```
```toml
# I am a comment. Hear me roar. Roar.
key = "value" # Yeah, you can do this.
```
Expand All @@ -90,7 +90,7 @@ key = "value" # Yeah, you can do this.

由三个双引号包裹,除了分隔符开始的换行外,字符串内的换行将被保留:

```
```toml
str1 = """
Roses are red
Violets are blue"""
Expand All @@ -100,31 +100,31 @@ Violets are blue"""

由单引号包裹,其内不允许转义,因此可以方便的表示基本字符串中需要转义的内容:

```
```toml
winpath = 'C:\Users\nodejs\templates'
```

### 4\. 多行-字面量字符串

与多行-基本字符串相似:

```
```toml
str1 = '''
Roses are red
Violets are blue'''
```

## 数值与BOOL值

```
```toml
int1 = +99
flt3 = -0.01
bool1 = true
```

## 日期时间

```
```toml
date = 1979-05-27T07:32:00Z
```

Expand All @@ -134,7 +134,7 @@ date = 1979-05-27T07:32:00Z

注意,同一个数组下不允许混用数据类型。

```
```toml
array1 = [ 1, 2, 3 ]
array2 = [ "red", "yellow", "green" ]
array3 = [ [ 1, 2 ], [3, 4, 5] ]
Expand All @@ -146,13 +146,13 @@ array5 = [ 1, 2.0 ] # 注意:这是不行的。

表格(也叫哈希表或字典)是键值对的集合。它们在方括号内,自成一行。注意和数组相区分,数组只有值。

```
```toml
[table]
```

在此之下,直到下一个 `table` 或 `EOF` 之前,是这个表格的键值对。键在左,值在右,等号在中间。键以非空字符开始,以等号前的非空字符为结尾。键值对是无序的。

```
```toml
[table]
key = "value"
```
Expand All @@ -161,7 +161,7 @@ key = "value"

嵌套表格的表格名称中使用 `.` 符号。你可以任意命名你的表格,只是不要用点,点是保留的。

```
```toml
[dog.tater]
type = "pug"
```
Expand All @@ -174,7 +174,7 @@ type = "pug"

如果你不想的话,你不用声明所有的父表。TOML 知道该如何处理。

```
```toml
# [x] 你
# [x.y] 不需要
# [x.y.z] 这些
Expand All @@ -185,7 +185,7 @@ type = "pug"

只要父表没有被直接定义,而且没有定义一个特定的键,你可以继续写入:

```
```toml
[a.b]
c = 1

Expand All @@ -195,7 +195,7 @@ d = 2

然而你不能多次定义键和表格。这么做是不合法的。

```
```toml
# 别这么干!

[a]
Expand All @@ -216,7 +216,7 @@ c = 2

最后要介绍的类型是表格数组。表格数组可以通过包裹在双方括号内的表格名来表达。使用相同的双方括号名称的表格是同一个数组的元素。表格按照书写的顺序插入。双方括号表格如果没有键值对,会被当成空表。

```
```toml
[[products]]
name = "Hammer"
sku = 738594937
Expand All @@ -243,7 +243,7 @@ color = "gray"

表格数组同样可以嵌套。只需在子表格上使用相同的双方括号语法。每一个双方括号子表格从属于最近定义的上层表格元素。

```
```toml
[[fruit]]
name = "apple"

Expand Down Expand Up @@ -292,7 +292,7 @@ color = "gray"

尝试定义一个普通的表格,使用已经定义的数组的名称,将抛出一个解析错误:

```
```toml
# 不合法的 TOML

[[fruit]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ hide_title: true

这里使用 `YAML` 配置文件: `config.yaml`

```
```yaml
server:
address: ":8199"
openapiPath: "/api.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ AccessLogPattern string // Error log file pattern like: access-{Ymd}

官方推荐使用配置文件的方式来管理服务配置以及日志日志配置。 一个参考的日志配置内容示例(以 `yaml` 格式为例):

```
```yaml
server:
LogPath: "/var/log/gf-demos/server"
LogStdout: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {

config.yaml

```
```yaml
server:
address: ":8199"
openapiPath: "/api.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hide_title: true

## 示例1,默认配置项

```
```yaml
server:
address: ":80"
serverRoot: "/var/www/Server"
Expand All @@ -26,7 +26,7 @@ server:

多个 `Server` 的配置示例:

```
```yaml
server:
address: ":80"
serverRoot: "/var/www/Server"
Expand Down Expand Up @@ -55,7 +55,7 @@ s4 := g.Server()

比如上一个章节的示例,对应的配置文件如下:

```
```yaml
server:
address: ":8199"
serverRoot: "/var/www/Server"
Expand All @@ -72,7 +72,7 @@ server:

同理,配置属性项的名称也不区分大小写,单词间也支持使用 `-`/ `_` 符号连接。也就是说以下配置文件效果和上面的配置文件一致:

```
```yaml
server:
address: ":8199"
serverRoot: "/var/www/Server"
Expand All @@ -98,7 +98,7 @@ server:

由于安全性的考虑,默认的上传限制都不是很高,特别是 `ClientMaxBodySize` 的大小限制,在需要文件上传的场景可适当考虑调整,通过配置文件配置即可,例如:

```
```yaml
server:
maxHeaderBytes: "20KB"
clientMaxBodySize: "200MB"
Expand All @@ -110,7 +110,7 @@ server:

从 `v2` 版本开始, `Server` 增加了对配置文件中 `Logger` 的配置项支持,主要是为了统一日志组件配置、并解决日志滚动切分的问题。配置示例:

```
```yaml
server:
address: ":8080"
logger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ hide_title: true

以下为配置文件模板:

```
```yaml
server:
# 基本配置
address: ":80" # 本地监听地址。默认":80",多个地址以","号分隔。例如:"192.168.2.3:8000,10.0.3.10:8001"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hide_title: true

示例配置:

```
```yaml
viewpath: "/home/www/templates/"
database:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *AdapterFile) ClearContent()

在默认提供的文件系统接口实现下, `gcfg` 组件支持按层级获取配置数据,层级访问默认通过英文 `.` 号指定,其中 `pattern` 参数和 [通用编解码-gjson](output/goframe-v2.0-md/组件列表/编码解码/通用编解码-gjson) 的 `pattern` 参数一致。例如以下配置( `config.yaml`):

```
```yaml
server:
address: ":8199"
serverRoot: "resource/public"
Expand Down
Loading

0 comments on commit d235c7d

Please sign in to comment.