Skip to content

Commit c2e7606

Browse files
author
Vic Shóstak
authored
Merge pull request #174 from koddr/master
Add media link, Add new v1 code examples
2 parents 1aca495 + a1269b0 commit c2e7606

File tree

2 files changed

+155
-2
lines changed

2 files changed

+155
-2
lines changed

.github/README.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,65 @@ func main() {
204204
<details>
205205
<summary>📚 Show more code examples</summary>
206206

207+
### Template engines
208+
209+
Already supports:
210+
211+
- [html](https://golang.org/pkg/html/template/)
212+
- [amber](https://github.com/eknkc/amber)
213+
- [handlebars](https://github.com/aymerick/raymond)
214+
- [mustache](https://github.com/cbroglie/mustache)
215+
- [pug](https://github.com/Joker/jade)
216+
217+
```go
218+
func main() {
219+
// You can setup template engine before initiation app:
220+
app := fiber.New(&fiber.Settings{
221+
ViewEngine: "mustache",
222+
ViewFolder: "./views",
223+
ViewExtension: ".tmpl",
224+
})
225+
226+
// OR after initiation app at any convenient location:
227+
app.Settings.ViewEngine = "mustache"
228+
app.Settings.ViewFolder = "./views"
229+
app.Settings.ViewExtension = ".tmpl"
230+
231+
// And now, you can call template `./views/home.tmpl` like this:
232+
app.Get("/", func(c *fiber.Ctx) {
233+
c.Render("home", fiber.Map{
234+
"title": "Homepage",
235+
"year": 1999,
236+
})
237+
})
238+
239+
// ...
240+
}
241+
```
242+
243+
### Grouping routes into chains
244+
245+
```go
246+
func main() {
247+
app := fiber.New()
248+
249+
// Root API route
250+
api := app.Group("/api", cors()) // /api
251+
252+
// API v1 routes
253+
v1 := api.Group("/v1", mysql()) // /api/v1
254+
v1.Get("/list", handler) // /api/v1/list
255+
v1.Get("/user", handler) // /api/v1/user
256+
257+
// API v2 routes
258+
v2 := api.Group("/v2", mongodb()) // /api/v2
259+
v2.Get("/list", handler) // /api/v2/list
260+
v2.Get("/user", handler) // /api/v2/user
261+
262+
// ...
263+
}
264+
```
265+
207266
### Custom 404 response
208267

209268
```go
@@ -250,6 +309,37 @@ func main() {
250309
}
251310
```
252311

312+
### WebSocket support
313+
314+
```go
315+
func main() {
316+
app := fiber.New()
317+
318+
app.WebSocket("/ws/:name", func(c *fiber.Conn) {
319+
log.Println(c.Params("name"))
320+
321+
for {
322+
mt, msg, err := c.ReadMessage()
323+
if err != nil {
324+
log.Println("read:", err)
325+
break
326+
}
327+
328+
log.Printf("recovery: %s", msg)
329+
330+
err = c.WriteMessage(mt, msg)
331+
if err != nil {
332+
log.Println("write:", err)
333+
break
334+
}
335+
}
336+
})
337+
338+
// Listen on ws://localhost:3000/ws/john
339+
app.Listen(3000)
340+
}
341+
```
342+
253343
### Recover from `panic`
254344

255345
```go
@@ -272,7 +362,8 @@ func main() {
272362

273363
## 💬 Media
274364

275-
- [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) _by [Vic Shóstak](https://github.com/koddr), 03 Feb 2020_
365+
- [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) (_by [Vic Shóstak](https://github.com/koddr), 03 Feb 2020_)
366+
- [Fiber official release is out now! 🎉 What's new and is he still fast, flexible and friendly?](https://dev.to/koddr/fiber-v2-is-out-now-what-s-new-and-is-he-still-fast-flexible-and-friendly-3ipf) (_by [Vic Shóstak](https://github.com/koddr), 21 Feb 2020_)
276367

277368
## 👍 Contribute
278369

.github/README_ru.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,67 @@ func main() {
204204
<details>
205205
<summary>📚 Показать больше примеров кода</summary>
206206

207+
### Работа с шаблонами
208+
209+
Поддерживаемые движки шаблонов:
210+
211+
- [html](https://golang.org/pkg/html/template/)
212+
- [amber](https://github.com/eknkc/amber)
213+
- [handlebars](https://github.com/aymerick/raymond)
214+
- [mustache](https://github.com/cbroglie/mustache)
215+
- [pug](https://github.com/Joker/jade)
216+
217+
```go
218+
func main() {
219+
// Вы можете настроить нужный движок для шаблонов
220+
// перед инициализацией приложения:
221+
app := fiber.New(&fiber.Settings{
222+
ViewEngine: "mustache",
223+
ViewFolder: "./views",
224+
ViewExtension: ".tmpl",
225+
})
226+
227+
// ИЛИ уже после инициализации приложения,
228+
// в любом удобном месте:
229+
app.Settings.ViewEngine = "mustache"
230+
app.Settings.ViewFolder = "./views"
231+
app.Settings.ViewExtension = ".tmpl"
232+
233+
// Теперь, вы сможете вызывать шаблон `./views/home.tmpl` вот так:
234+
app.Get("/", func(c *fiber.Ctx) {
235+
c.Render("home", fiber.Map{
236+
"title": "Homepage",
237+
"year": 1999,
238+
})
239+
})
240+
241+
// ...
242+
}
243+
```
244+
245+
### Группировка роутов в цепочки
246+
247+
```go
248+
func main() {
249+
app := fiber.New()
250+
251+
// Корневой API роут
252+
api := app.Group("/api", cors()) // /api
253+
254+
// Роуты для API v1
255+
v1 := api.Group("/v1", mysql()) // /api/v1
256+
v1.Get("/list", handler) // /api/v1/list
257+
v1.Get("/user", handler) // /api/v1/user
258+
259+
// Роуты для API v2
260+
v2 := api.Group("/v2", mongodb()) // /api/v2
261+
v2.Get("/list", handler) // /api/v2/list
262+
v2.Get("/user", handler) // /api/v2/user
263+
264+
// ...
265+
}
266+
```
267+
207268
### Обработка 404 ошибки
208269

209270
```go
@@ -272,7 +333,8 @@ func main() {
272333

273334
## 💬 Медиа
274335

275-
- [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) *[Vic Shóstak](https://github.com/koddr), 3 февраля 2020 г.*
336+
- [Welcome to Fiber — an Express.js styled web framework written in Go with ❤️](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) (_by [Vic Shóstak](https://github.com/koddr), 03 Feb 2020_)
337+
- [Fiber official release is out now! 🎉 What's new and is he still fast, flexible and friendly?](https://dev.to/koddr/fiber-v2-is-out-now-what-s-new-and-is-he-still-fast-flexible-and-friendly-3ipf) (_by [Vic Shóstak](https://github.com/koddr), 21 Feb 2020_)
276338

277339
## 👍 Помощь проекту
278340

0 commit comments

Comments
 (0)