Skip to content

Commit

Permalink
docs: add keywords concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Jan 14, 2024
1 parent 8bba838 commit f2be160
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/.vuepress/sidebar/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export const enSidebar = sidebar({
text: "Concepts",
icon: "solar:book-outline",
prefix: "concepts/",
children: "structure"
children: [
{
text: "Golang",
icon: "fa6-brands:golang",
prefix: "golang/",
children: "structure",
}
]
},
{
text: "Golang",
Expand Down
9 changes: 8 additions & 1 deletion src/.vuepress/sidebar/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export const zhSidebar = sidebar({
text: "必学概念",
icon: "solar:book-outline",
prefix: "concepts/",
children: "structure"
children: [
{
text: "Golang",
icon: "fa6-brands:golang",
prefix: "golang/",
children: "structure",
}
]
},
{
text: "Golang",
Expand Down
6 changes: 0 additions & 6 deletions src/guide/concepts/1-basic.md

This file was deleted.

41 changes: 41 additions & 0 deletions src/guide/concepts/golang/1-basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
order: 1
title: 'Keywords'
---

## Keywords

Golang has 25 reserved keywords that cannot be used as program identifiers.

| Type | Keywords | Introduction |
| ------------------ | ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| Declaration | `const` `func` `import` `package` `type` `var` | These keywords are used to declare various elements in the code. |
| Compound Types | `chan` `interface` `map` `struct` | These keywords are used to declare some special compound types. |
| Flow Control | `break` `case` `continue` `default` `else` `fallthrough` `for` `goto` `if` `range` `return` `select` `switch` | These keywords are used to control the flow of program execution. |
| Function Modifiers | `defer` `go` | Used to modify special functions. |

## Declaration Type Keywords

### **const**

`const` is used to declare constants, which once declared cannot be changed, and must specify an initial value when declaring a constant.

<details>
<summary>Example</summary>

```go
const identifier T = value // T is the data type, which can be omitted, and the compiler will infer it.
const identifier1, identifier2 = value1, value2 // Declare multiple, such as const a, b, c = "hello", 100, true

const (
FeMale = 0
Male = 1
) // Enumeration

const (
a = iota
b
c
) // iota
```
</details>
7 changes: 0 additions & 7 deletions src/zh/guide/concepts/1-basic.md

This file was deleted.

42 changes: 42 additions & 0 deletions src/zh/guide/concepts/golang/1-basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
order: 1
title: '保留关键字'
---

## 保留关键字

golang 有 25 个保留的关键字,这些关键字不能用作程序标识符。

| 类型 | 关键字 | 介绍 |
| -------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| 声明 | `const` `func` `import` `package` `type` `var` | 这些关键字用于声明代码中的各种元素 |
| 复合类型 | `chan` `interface` `map` `struct` | 这些关键字用于声明一些特殊的复合类型 |
| 流程控制 | `break` `case` `continue` `default` `else` `fallthrough` `for` `goto` `if` `range` `return` `select` `switch` | 这些关键字用于控制程序运行流程 |
| 功能修饰 | `defer` `go` | 用于修饰特殊的 function |


## 声明类型关键字

### **const**

const 用于声明常量,常量一经声明就不能被更改,声明常量必须指定初始值。

<details>
<summary>例子</summary>

```go
const identifier T = value // T 为数据类型,可以省略,编译器会自己推断。
const identifier1, identifier2 = value1, value2 // 声明多个,如 const a, b, c = "hello", 100, true

const (
FeMale = 0
Male = 1
) // 枚举

const (
a = iota
b
c
) // iota
```
</details>

0 comments on commit f2be160

Please sign in to comment.