Skip to content

Commit 63353ca

Browse files
authored
Merge pull request #187 from keob/translate
update chinese README
2 parents 69f00ef + da7cbd8 commit 63353ca

File tree

1 file changed

+126
-35
lines changed

1 file changed

+126
-35
lines changed

.github/README_zh-CN.md

Lines changed: 126 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</a>
5555
</p>
5656
<p align="center">
57-
<strong>Fiber</strong>是一个基于<a href="https://github.com/expressjs/express">Express的</a> <strong>Web框架,<strong>建立在<a href="https://github.com/valyala/fasthttp">Fasthttp</a> ( <a href="https://golang.org/doc/">Go</a> <strong>最快的</strong> HTTP引擎)的基础上。皆在</strong>简化</strong> <strong>零内存分配</strong>和<strong>提高性能</strong>,以便<strong>快速</strong>开发。
57+
<b>Fiber</b>是一个基于<a href="https://github.com/expressjs/express">Express的</a> <b>Web框架</b>,建立在<a href="https://golang.org/doc/">Go</a>语言写的 <b>最快的</b><a href="https://github.com/valyala/fasthttp">Fasthttp</a>HTTP引擎的基础上。皆在</b>简化</b> <b>零内存分配</b>和<b>提高性能</b>,以便<b>快速</b>开发。
5858
</p>
5959

6060
## ⚡️ 快速入门
@@ -82,6 +82,7 @@ func main() {
8282
使用[`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them)命令完成安装:
8383

8484
```bash
85+
export GO111MODULE=on
8586
export GOPROXY=https://goproxy.cn
8687
go get github.com/gofiber/fiber
8788
```
@@ -109,36 +110,15 @@ go get github.com/gofiber/fiber
109110

110111
## 💡 哲学
111112

112-
[Node.js](https://nodejs.org/en/about/)切换到[Go的](https://golang.org/doc/)新gopher在开始构建Web应用程序或微服务之前正在应对学习过程。 Fiber作为一个**Web框架** ,是按照**极简主义**的思想并遵循**UNIX方式创建的** ,因此新的gopher可以以热烈和可信赖的欢迎**方式**迅速进入Go的世界。
113+
[Node.js](https://nodejs.org/en/about/)切换到[Go的](https://golang.org/doc/)新gopher在开始构建Web应用程序或微服务之前正在应对学习过程。 Fiber作为一个**Web框架** ,是按照**极简主义**的思想并遵循**UNIX方式创建的**,因此新的gopher可以以热烈和可信赖的欢迎**方式**迅速进入Go的世界。
113114

114-
Fiber **** Internet上最流行的Web框架Expressjs的**启发** 。我们结合了Express的**易用**性和Go的**原始性能** 。如果您曾经在Node.js上实现过Web应用程序*使用Express.js或类似工具*,那么许多方法和原理对您来说似乎**非常易懂**
115+
Fiber **** Internet上最流行的Web框架Expressjs的**启发** 。我们结合了Express的**易用**性和Go的**原始性能** 。如果您曾经在Node.js上实现过Web应用程序(*使用Express.js或类似工具*),那么许多方法和原理对您来说似乎**非常易懂**
115116

116-
## 👀 例子
117+
## 👀 示例
117118

118119
下面列出了一些常见示例。如果您想查看更多代码示例,请访问我们的[Recipes存储库](https://github.com/gofiber/recipes)或访问我们的[API文档](https://fiber.wiki)
119120

120-
### Serve static files
121-
122-
```go
123-
func main() {
124-
app := fiber.New()
125-
126-
app.Static("/public")
127-
// => http://localhost:3000/js/script.js
128-
// => http://localhost:3000/css/style.css
129-
130-
app.Static("/prefix", "/public")
131-
// => http://localhost:3000/prefix/js/script.js
132-
// => http://localhost:3000/prefix/css/style.css
133-
134-
app.Static("*", "/public/index.html")
135-
// => http://localhost:3000/any/path/shows/index/html
136-
137-
app.Listen(3000)
138-
}
139-
```
140-
141-
### Routing
121+
### 路由
142122

143123
```go
144124
func main() {
@@ -166,7 +146,28 @@ func main() {
166146
}
167147
```
168148

169-
### Middleware & Next
149+
### 静态文件
150+
151+
```go
152+
func main() {
153+
app := fiber.New()
154+
155+
app.Static("/public")
156+
// => http://localhost:3000/js/script.js
157+
// => http://localhost:3000/css/style.css
158+
159+
app.Static("/prefix", "/public")
160+
// => http://localhost:3000/prefix/js/script.js
161+
// => http://localhost:3000/prefix/css/style.css
162+
163+
app.Static("*", "/public/index.html")
164+
// => http://localhost:3000/any/path/shows/index/html
165+
166+
app.Listen(3000)
167+
}
168+
```
169+
170+
### 中间件
170171

171172
```go
172173
func main() {
@@ -195,9 +196,68 @@ func main() {
195196
```
196197

197198
<details>
198-
<summary>📜 Show more code examples</summary>
199+
<summary>📚 显示更多代码示例</summary>
200+
201+
### 模板引擎
202+
203+
已经支持的:
204+
205+
- [html](https://golang.org/pkg/html/template/)
206+
- [amber](https://github.com/eknkc/amber)
207+
- [handlebars](https://github.com/aymerick/raymond)
208+
- [mustache](https://github.com/cbroglie/mustache)
209+
- [pug](https://github.com/Joker/jade)
210+
211+
```go
212+
func main() {
213+
// You can setup template engine before initiation app:
214+
app := fiber.New(&fiber.Settings{
215+
ViewEngine: "mustache",
216+
ViewFolder: "./views",
217+
ViewExtension: ".tmpl",
218+
})
219+
220+
// OR after initiation app at any convenient location:
221+
app.Settings.ViewEngine = "mustache"
222+
app.Settings.ViewFolder = "./views"
223+
app.Settings.ViewExtension = ".tmpl"
224+
225+
// And now, you can call template `./views/home.tmpl` like this:
226+
app.Get("/", func(c *fiber.Ctx) {
227+
c.Render("home", fiber.Map{
228+
"title": "Homepage",
229+
"year": 1999,
230+
})
231+
})
232+
233+
// ...
234+
}
235+
```
199236

200-
### Custom 404 response
237+
### 组路由
238+
239+
```go
240+
func main() {
241+
app := fiber.New()
242+
243+
// Root API route
244+
api := app.Group("/api", cors()) // /api
245+
246+
// API v1 routes
247+
v1 := api.Group("/v1", mysql()) // /api/v1
248+
v1.Get("/list", handler) // /api/v1/list
249+
v1.Get("/user", handler) // /api/v1/user
250+
251+
// API v2 routes
252+
v2 := api.Group("/v2", mongodb()) // /api/v2
253+
v2.Get("/list", handler) // /api/v2/list
254+
v2.Get("/user", handler) // /api/v2/user
255+
256+
// ...
257+
}
258+
```
259+
260+
### 自定义 404 响应
201261

202262
```go
203263
func main() {
@@ -220,7 +280,7 @@ func main() {
220280
}
221281
```
222282

223-
### JSON Response
283+
### JSON
224284

225285
```go
226286
func main() {
@@ -241,8 +301,38 @@ func main() {
241301
}
242302
```
243303

304+
### WebSocket
305+
306+
```go
307+
func main() {
308+
app := fiber.New()
309+
310+
app.WebSocket("/ws/:name", func(c *fiber.Conn) {
311+
log.Println(c.Params("name"))
312+
313+
for {
314+
mt, msg, err := c.ReadMessage()
315+
if err != nil {
316+
log.Println("read:", err)
317+
break
318+
}
319+
320+
log.Printf("recovery: %s", msg)
321+
322+
err = c.WriteMessage(mt, msg)
323+
if err != nil {
324+
log.Println("write:", err)
325+
break
326+
}
327+
}
328+
})
329+
330+
// Listen on ws://localhost:3000/ws/john
331+
app.Listen(3000)
332+
}
333+
```
244334

245-
### Recover from panic
335+
### panic 中恢复
246336

247337
```go
248338
func main() {
@@ -265,16 +355,17 @@ func main() {
265355

266356
## 💬 媒体
267357

268-
- [欢迎使用Fiber —用Go语言编写的Express.js风格的Web框架](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) *作者[维克·肖斯塔克(VicShóstak)](https://github.com/koddr),2020年2月3日*
358+
- [欢迎使用Fiber —用Go语言编写的Express.js风格的Web框架 ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) *作者[维克·肖斯塔克(VicShóstak)](https://github.com/koddr),2020年2月3日*
359+
- [Fiber 1.7 已经发布! 🎉 他仍然快速、灵活且友善](https://dev.to/koddr/fiber-v2-is-out-now-what-s-new-and-is-he-still-fast-flexible-and-friendly-3ipf) *作者[维克·肖斯塔克(VicShóstak)](https://github.com/koddr), 2020年2月21日)
269360

270361
## 👍 贡献
271362

272363
如果您要说声**谢谢**或支持`Fiber`的积极发展:
273364

274365
1.[GitHub Star](https://github.com/gofiber/fiber/stargazers)添加到项目中。
275-
2. [在Twitter上](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber)发布有关项目[的推文](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber)
276-
3.[Medium](https://medium.com/)[Dev.to](https://dev.to/)或个人博客上写评论或教程。
277-
4. 帮助我们将此`README` [文件](https://fiber.wiki/)[API文档](https://fiber.wiki/)翻译成另一种语言
366+
2. [在Twitter上](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber)发布有关项目[的推文](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20%E2%80%94%20is%20an%20Express.js%20inspired%20web%20framework%20build%20on%20Fasthttp%20for%20%23Go%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber)
367+
3.[Medium](https://medium.com/)[Dev.to](https://dev.to/)或个人博客上写评论或教程。
368+
4. 帮助我们将此`README文件`翻译成其它语言。
278369

279370
## ☕ Supporters
280371

0 commit comments

Comments
 (0)