You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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
+
funcmain() {
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
+
207
266
### Custom 404 response
208
267
209
268
```go
@@ -250,6 +309,37 @@ func main() {
250
309
}
251
310
```
252
311
312
+
### WebSocket support
313
+
314
+
```go
315
+
funcmain() {
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
+
253
343
### Recover from `panic`
254
344
255
345
```go
@@ -272,7 +362,8 @@ func main() {
272
362
273
363
## 💬 Media
274
364
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_)
// Теперь, вы сможете вызывать шаблон `./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
+
funcmain() {
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
+
207
268
### Обработка 404 ошибки
208
269
209
270
```go
@@ -272,7 +333,8 @@ func main() {
272
333
273
334
## 💬 Медиа
274
335
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_)
0 commit comments