From f2be160974a5a0dc14d7392e2a0de6cee241a498 Mon Sep 17 00:00:00 2001 From: Ryan Su Date: Sun, 14 Jan 2024 23:05:39 +0800 Subject: [PATCH] docs: add keywords concepts --- src/.vuepress/sidebar/en.ts | 9 +++++- src/.vuepress/sidebar/zh.ts | 9 +++++- src/guide/concepts/1-basic.md | 6 ---- src/guide/concepts/golang/1-basic.md | 41 ++++++++++++++++++++++++ src/zh/guide/concepts/1-basic.md | 7 ----- src/zh/guide/concepts/golang/1-basic.md | 42 +++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 15 deletions(-) delete mode 100644 src/guide/concepts/1-basic.md create mode 100644 src/guide/concepts/golang/1-basic.md delete mode 100644 src/zh/guide/concepts/1-basic.md create mode 100644 src/zh/guide/concepts/golang/1-basic.md diff --git a/src/.vuepress/sidebar/en.ts b/src/.vuepress/sidebar/en.ts index d2203b21..9f1d16d3 100644 --- a/src/.vuepress/sidebar/en.ts +++ b/src/.vuepress/sidebar/en.ts @@ -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", diff --git a/src/.vuepress/sidebar/zh.ts b/src/.vuepress/sidebar/zh.ts index e7c83f13..db67903f 100644 --- a/src/.vuepress/sidebar/zh.ts +++ b/src/.vuepress/sidebar/zh.ts @@ -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", diff --git a/src/guide/concepts/1-basic.md b/src/guide/concepts/1-basic.md deleted file mode 100644 index c5f0db92..00000000 --- a/src/guide/concepts/1-basic.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -order: 1 -title: 'Basic Concepts' ---- - -## Basic Concepts \ No newline at end of file diff --git a/src/guide/concepts/golang/1-basic.md b/src/guide/concepts/golang/1-basic.md new file mode 100644 index 00000000..965b735c --- /dev/null +++ b/src/guide/concepts/golang/1-basic.md @@ -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. + +
+Example + +```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 +``` +
\ No newline at end of file diff --git a/src/zh/guide/concepts/1-basic.md b/src/zh/guide/concepts/1-basic.md deleted file mode 100644 index ae645f0f..00000000 --- a/src/zh/guide/concepts/1-basic.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -order: 1 -title: '基础知识' ---- - -## 基础知识 - diff --git a/src/zh/guide/concepts/golang/1-basic.md b/src/zh/guide/concepts/golang/1-basic.md new file mode 100644 index 00000000..8a70b88e --- /dev/null +++ b/src/zh/guide/concepts/golang/1-basic.md @@ -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 用于声明常量,常量一经声明就不能被更改,声明常量必须指定初始值。 + +
+例子 + +```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 +``` +