From 029e3c5c1d258a5c07d84fc2405105232f26c8fd Mon Sep 17 00:00:00 2001 From: Ryan Su Date: Tue, 16 Jan 2024 10:06:20 +0800 Subject: [PATCH] refactor: optimize locale --- src/.vuepress/config.ts | 4 +- src/.vuepress/navbar/en.ts | 2 +- src/.vuepress/navbar/zh.ts | 2 +- src/.vuepress/sidebar/en.ts | 21 +++-- src/.vuepress/sidebar/zh.ts | 19 +++-- src/.vuepress/theme.ts | 4 +- src/README.md | 10 +-- src/en/README.md | 15 ++++ src/en/guide/README.md | 8 ++ src/en/guide/concepts/golang/1-basic.md | 41 +++++++++ .../guide/interview/golang}/basic/1-basic.md | 0 src/guide/README.md | 6 +- src/guide/concepts/golang/1-basic.md | 77 +++++++++++++---- .../interview/golang}/basic/1-basic.md | 0 src/zh/README.md | 15 ---- src/zh/guide/README.md | 8 -- src/zh/guide/concepts/golang/1-basic.md | 84 ------------------- 17 files changed, 165 insertions(+), 151 deletions(-) create mode 100644 src/en/README.md create mode 100644 src/en/guide/README.md create mode 100644 src/en/guide/concepts/golang/1-basic.md rename src/{guide => en/guide/interview/golang}/basic/1-basic.md (100%) rename src/{zh/guide => guide/interview/golang}/basic/1-basic.md (100%) delete mode 100644 src/zh/README.md delete mode 100644 src/zh/guide/README.md delete mode 100644 src/zh/guide/concepts/golang/1-basic.md diff --git a/src/.vuepress/config.ts b/src/.vuepress/config.ts index 0b6866f3..bc65febc 100644 --- a/src/.vuepress/config.ts +++ b/src/.vuepress/config.ts @@ -5,12 +5,12 @@ export default defineUserConfig({ base: "/", locales: { - "/": { + "/en/": { lang: "en-US", title: "Go Guide", description: "Golang guide for interview", }, - "/zh/": { + "/": { lang: "zh-CN", title: "Go 面试宝典", description: "Golang 面试宝典,面试题和基础", diff --git a/src/.vuepress/navbar/en.ts b/src/.vuepress/navbar/en.ts index 265f26b4..5cf034b5 100644 --- a/src/.vuepress/navbar/en.ts +++ b/src/.vuepress/navbar/en.ts @@ -1,7 +1,7 @@ import { navbar } from "vuepress-theme-hope"; export const enNavbar = navbar([ - "/", + "/en/", { text: "Guide", icon: "icon-park-outline:mountain", diff --git a/src/.vuepress/navbar/zh.ts b/src/.vuepress/navbar/zh.ts index 8395a8b1..16a9a2f7 100644 --- a/src/.vuepress/navbar/zh.ts +++ b/src/.vuepress/navbar/zh.ts @@ -1,7 +1,7 @@ import { navbar } from "vuepress-theme-hope"; export const zhNavbar = navbar([ - "/zh/", + "/", { text: "指南", icon: "icon-park-outline:mountain", diff --git a/src/.vuepress/sidebar/en.ts b/src/.vuepress/sidebar/en.ts index 9f1d16d3..9a6c42c3 100644 --- a/src/.vuepress/sidebar/en.ts +++ b/src/.vuepress/sidebar/en.ts @@ -1,7 +1,7 @@ import { sidebar } from "vuepress-theme-hope"; export const enSidebar = sidebar({ - "/": [ + "/en/": [ { text: "Guide", icon: "mingcute:book-line", @@ -19,13 +19,20 @@ export const enSidebar = sidebar({ children: "structure", } ] - }, + }, { - text: "Golang", - icon: "grommet-icons:golang", - prefix: "basic/", - children: "structure" - }, + text: "Interview Question", + icon: "solar:book-outline", + prefix: "interview/", + children: [ + { + text: "Golang", + icon: "grommet-icons:golang", + prefix: "golang/basic/", + children: "structure" + } + ] + }, ], }, ], diff --git a/src/.vuepress/sidebar/zh.ts b/src/.vuepress/sidebar/zh.ts index db67903f..e32f5cb8 100644 --- a/src/.vuepress/sidebar/zh.ts +++ b/src/.vuepress/sidebar/zh.ts @@ -1,7 +1,7 @@ import { sidebar } from "vuepress-theme-hope"; export const zhSidebar = sidebar({ - "/zh/": [ + "/": [ { text: "面试宝典", icon: "mingcute:book-line", @@ -21,11 +21,18 @@ export const zhSidebar = sidebar({ ] }, { - text: "Golang", - icon: "grommet-icons:golang", - prefix: "basic/", - children: "structure" - } + text: "面试题", + icon: "solar:book-outline", + prefix: "interview/", + children: [ + { + text: "Golang", + icon: "grommet-icons:golang", + prefix: "golang/basic/", + children: "structure" + } + ] + }, ], }, ], diff --git a/src/.vuepress/theme.ts b/src/.vuepress/theme.ts index 8362c46a..7124d39a 100644 --- a/src/.vuepress/theme.ts +++ b/src/.vuepress/theme.ts @@ -21,7 +21,7 @@ export default hopeTheme({ breadcrumb: false, locales: { - "/": { + "/en/": { // navbar navbar: enNavbar, @@ -40,7 +40,7 @@ export default hopeTheme({ /** * Chinese locale config */ - "/zh/": { + "/": { // navbar navbar: zhNavbar, diff --git a/src/README.md b/src/README.md index 689ba6fb..c9128e5f 100644 --- a/src/README.md +++ b/src/README.md @@ -1,15 +1,15 @@ --- home: true icon: home -title: Go Guide +title: Go 面试宝典 heroImage: /logo.svg -heroText: Go Guide -tagline: Golang interview guide +heroText: Go 面试宝典 +tagline: Golang 面试基础,常见面试题。 actions: - - text: Guide + - text: 指南 link: ./guide/ type: primary copyright: false -footer: Apache2.0 license, Copyright © 2024-present Go Guide \ No newline at end of file +footer: Apache2.0 协议, 版权所有 © 2024-present Go Guide diff --git a/src/en/README.md b/src/en/README.md new file mode 100644 index 00000000..689ba6fb --- /dev/null +++ b/src/en/README.md @@ -0,0 +1,15 @@ +--- +home: true +icon: home +title: Go Guide +heroImage: /logo.svg +heroText: Go Guide +tagline: Golang interview guide +actions: + - text: Guide + link: ./guide/ + type: primary + + +copyright: false +footer: Apache2.0 license, Copyright © 2024-present Go Guide \ No newline at end of file diff --git a/src/en/guide/README.md b/src/en/guide/README.md new file mode 100644 index 00000000..2472b7f6 --- /dev/null +++ b/src/en/guide/README.md @@ -0,0 +1,8 @@ +--- +title: Guide +icon: mingcute:book-line +--- + +## introduce + +This website mainly provides Golang interview frequently asked questions and basic knowledge. \ No newline at end of file diff --git a/src/en/guide/concepts/golang/1-basic.md b/src/en/guide/concepts/golang/1-basic.md new file mode 100644 index 00000000..965b735c --- /dev/null +++ b/src/en/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/guide/basic/1-basic.md b/src/en/guide/interview/golang/basic/1-basic.md similarity index 100% rename from src/guide/basic/1-basic.md rename to src/en/guide/interview/golang/basic/1-basic.md diff --git a/src/guide/README.md b/src/guide/README.md index 2472b7f6..22cfe835 100644 --- a/src/guide/README.md +++ b/src/guide/README.md @@ -1,8 +1,8 @@ --- -title: Guide +title: 指南 icon: mingcute:book-line --- -## introduce +## 介绍 -This website mainly provides Golang interview frequently asked questions and basic knowledge. \ No newline at end of file +本栏目主要提供 Golang 面试常见问题。 \ No newline at end of file diff --git a/src/guide/concepts/golang/1-basic.md b/src/guide/concepts/golang/1-basic.md index 965b735c..fded6c94 100644 --- a/src/guide/concepts/golang/1-basic.md +++ b/src/guide/concepts/golang/1-basic.md @@ -1,36 +1,37 @@ --- order: 1 -title: 'Keywords' +title: '保留关键字' --- -## Keywords +## 1. 保留关键字 -Golang has 25 reserved keywords that cannot be used as program identifiers. +golang 有 25 个保留的关键字,这些关键字不能用作程序标识符。 -| 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. | +| 类型 | 关键字 | 介绍 | +| -------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------ | +| 声明 | `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 | -## Declaration Type Keywords -### **const** +## 2. 声明类型关键字 -`const` is used to declare constants, which once declared cannot be changed, and must specify an initial value when declaring a constant. +### 2.1. **const** + +`const` 用于声明常量,常量一经声明就不能被更改,声明常量必须指定初始值。
-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 identifier T = value // T 为数据类型,可以省略,编译器会自己推断。 +const identifier1, identifier2 = value1, value2 // 声明多个,如 const a, b, c = "hello", 100, true const ( FeMale = 0 Male = 1 -) // Enumeration +) // 枚举 const ( a = iota @@ -38,4 +39,46 @@ const ( c ) // iota ``` -
\ No newline at end of file + + +#### 2.1.1. **func** + +`func` 用于声明函数,支持多个返回值,不支持默认参数。 + + +
+例子 + +```go +// p 为参数, T 为类型 +func Test(p T) {} +func Test(p T) (T1, T2) {} +func Test (p T, p1, T1, list ...T3) (T4, T5) {} // 不定参数 +``` + +
+ +#### 2.1.2. **import** + +`import` 用于导入包,使用其公开的标识符。 + +`import` 支持单行和多行导入。 + +```go +import "flag" // 单个导入 + +import ( + "flag" + "fmt" +) // 多个导入 +``` + +我们还可以使用 `.`, `_` 和别名修饰导入的包。 + +| 导入命令 | 使用方法 | 解析 | +| ---------------------- | -------- | --------------------------------------------- | +| `import "lib/math"` | math.Sin | 普通导入需要使用包名 | +| `import m "lib/math"` | m.Sin | 可以在导入时设置别名 | +| `import . "lib/math" ` | Sin | 使用 `.` 导入本地可以直接使用函数,不需要包名 | + +我们还可以使用 `_` 来修饰导入的包,这样只会执行导入包的初始化函数 `init()` diff --git a/src/zh/guide/basic/1-basic.md b/src/guide/interview/golang/basic/1-basic.md similarity index 100% rename from src/zh/guide/basic/1-basic.md rename to src/guide/interview/golang/basic/1-basic.md diff --git a/src/zh/README.md b/src/zh/README.md deleted file mode 100644 index c9128e5f..00000000 --- a/src/zh/README.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -home: true -icon: home -title: Go 面试宝典 -heroImage: /logo.svg -heroText: Go 面试宝典 -tagline: Golang 面试基础,常见面试题。 -actions: - - text: 指南 - link: ./guide/ - type: primary - - -copyright: false -footer: Apache2.0 协议, 版权所有 © 2024-present Go Guide diff --git a/src/zh/guide/README.md b/src/zh/guide/README.md deleted file mode 100644 index 22cfe835..00000000 --- a/src/zh/guide/README.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: 指南 -icon: mingcute:book-line ---- - -## 介绍 - -本栏目主要提供 Golang 面试常见问题。 \ No newline at end of file diff --git a/src/zh/guide/concepts/golang/1-basic.md b/src/zh/guide/concepts/golang/1-basic.md deleted file mode 100644 index fded6c94..00000000 --- a/src/zh/guide/concepts/golang/1-basic.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -order: 1 -title: '保留关键字' ---- - -## 1. 保留关键字 - -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 | - - -## 2. 声明类型关键字 - -### 2.1. **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 -``` -
- -#### 2.1.1. **func** - -`func` 用于声明函数,支持多个返回值,不支持默认参数。 - - -
-例子 - -```go -// p 为参数, T 为类型 -func Test(p T) {} -func Test(p T) (T1, T2) {} -func Test (p T, p1, T1, list ...T3) (T4, T5) {} // 不定参数 -``` - -
- -#### 2.1.2. **import** - -`import` 用于导入包,使用其公开的标识符。 - -`import` 支持单行和多行导入。 - -```go -import "flag" // 单个导入 - -import ( - "flag" - "fmt" -) // 多个导入 -``` - -我们还可以使用 `.`, `_` 和别名修饰导入的包。 - -| 导入命令 | 使用方法 | 解析 | -| ---------------------- | -------- | --------------------------------------------- | -| `import "lib/math"` | math.Sin | 普通导入需要使用包名 | -| `import m "lib/math"` | m.Sin | 可以在导入时设置别名 | -| `import . "lib/math" ` | Sin | 使用 `.` 导入本地可以直接使用函数,不需要包名 | - -我们还可以使用 `_` 来修饰导入的包,这样只会执行导入包的初始化函数 `init()`