Skip to content

Commit d7e8036

Browse files
committed
docusaurus preparations for the recipes
1 parent b938f08 commit d7e8036

File tree

77 files changed

+4159
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4159
-74
lines changed

sidebars.js renamed to default_sidebars.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// @ts-check
1313

1414
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
15-
const sidebars = {
16-
tutorialSidebar: [
15+
const default_sidebars = {
16+
left_sidebar: [
1717
{type: 'autogenerated', dirName: '.'}
1818
],
1919
};
2020

21-
module.exports = sidebars;
21+
module.exports = default_sidebars;

docs/recipes/404-handler/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Custom 404 Not Found Handler Example
2+
3+
This example demonstrates how to implement a custom 404 Not Found handler using the [Fiber](https://gofiber.io) web framework in Go. The purpose of this example is to show how to handle requests to undefined routes gracefully by returning a 404 status code.
4+
5+
## Description
6+
7+
In web applications, it's common to encounter requests to routes that do not exist. Handling these requests properly is important to provide a good user experience and to inform the user that the requested resource is not available. This example sets up a simple Fiber application with a custom 404 handler to manage such cases.
8+
9+
## Requirements
10+
11+
- [Go](https://golang.org/dl/) 1.18 or higher
12+
- [Git](https://git-scm.com/downloads)
13+
14+
## Running the Example
15+
16+
To run the example, use the following command:
17+
```bash
18+
go run main.go
19+
```
20+
21+
The server will start and listen on `localhost:3000`.
22+
23+
## Example Routes
24+
25+
- **GET /hello**: Returns a simple greeting message.
26+
- **Undefined Routes**: Any request to a route not defined will trigger the custom 404 handler.
27+
28+
## Custom 404 Handler
29+
30+
The custom 404 handler is defined to catch all undefined routes and return a 404 status code with a "Not Found" message.
31+
32+
## Code Overview
33+
34+
### `main.go`
35+
36+
```go
37+
package main
38+
39+
import (
40+
"log"
41+
"github.com/gofiber/fiber/v2"
42+
)
43+
44+
func main() {
45+
// Fiber instance
46+
app := fiber.New()
47+
48+
// Routes
49+
app.Get("/hello", hello)
50+
51+
// 404 Handler
52+
app.Use(func(c *fiber.Ctx) error {
53+
return c.SendStatus(404) // => 404 "Not Found"
54+
})
55+
56+
// Start server
57+
log.Fatal(app.Listen(":3000"))
58+
}
59+
60+
// Handler
61+
func hello(c *fiber.Ctx) error {
62+
return c.SendString("I made a ☕ for you!")
63+
}
64+
```
65+
66+
## Conclusion
67+
68+
This example provides a basic setup for handling 404 Not Found errors in a Fiber application. It can be extended and customized further to fit the needs of more complex applications.
69+
70+
## References
71+
72+
- [Fiber Documentation](https://docs.gofiber.io)
73+
- [GitHub Repository](https://github.com/gofiber/fiber)

docs/recipes/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
id: welcome
3+
title: 👋 Overview
4+
sidebar_position: 1
5+
---
6+
7+
# 🍳 Examples for [Fiber](https://github.com/gofiber/fiber)
8+
9+
**Welcome to the official Fiber cookbook**!
10+
11+
Here you can find the most **delicious** recipes to cook delicious meals using our web framework.
12+
13+
## 🌽 Table of contents
14+
15+
- [Amazon Web Services (AWS) Elastic Beanstalk](./aws-eb)
16+
- [AWS SAM](./aws-sam)
17+
- [Certificates from Let's Encrypt](./autocert)
18+
- [Clean Architecture](./clean-architecture)
19+
- [Cloud Run](./cloud-run)
20+
- [Colly Scraping using Fiber and PostgreSQL](./fiber-colly-gorm)
21+
- [CSRF-with-Session](./csrf-with-session)
22+
- [CSRF](./csrf)
23+
- [Custom 404 Not Found](./404-handler)
24+
- [Dependency Injection (with Parsley)](./parsley)
25+
- [Docker MariaDB Clean Architecture](./docker-mariadb-clean-arch)
26+
- [Docker Nginx Loadbalancer](./docker-nginx-loadbalancer)
27+
- [Docker Postgres-JWT](./auth-docker-postgres-jwt)
28+
- [DummyJson](./dummyjson/)
29+
- [Enable HTTPS/TLS using PKCS12 store](./https-pkcs12-tls)
30+
- [Enable HTTPS/TLS](./https-tls)
31+
- [Enable Preforking](./prefork)
32+
- [Ent Mysql Example](./ent-mysql)
33+
- [Entgo Sveltekit](./entgo-sveltekit)
34+
- [Firebase Functions](./firebase-functions)
35+
- [GeoIP (with MaxMind databases)](./geoip-maxmind)
36+
- [GeoIP](./geoip)
37+
- [GORM Mysql Example](./gorm-mysql)
38+
- [GORM](./gorm)
39+
- [Graceful shutdown](./graceful-shutdown)
40+
- [GraphQL](./graphql)
41+
- [Hello, World!](./hello-world)
42+
- [Heroku App](./heroku)
43+
- [Hexagonal Architecture](./hexagonal)
44+
- [i18n](./i18n)
45+
- [JWT](./jwt)
46+
- [Kubernetes](./k8s)
47+
- [Listen on Multiple Ports](./multiple-ports)
48+
- [Live Reloading (Air)](./air)
49+
- [Memgraph](./memgraph)
50+
- [MinIO](./minio)
51+
- [MongoDB](./mongodb)
52+
- [MVC Application Bootstrap](./fiber-bootstrap)
53+
- [Netlify Functions](fiber-svelte-netlify)
54+
- [OAuth2 Google](./oauth2-google)
55+
- [PostgreSQL](./postgresql)
56+
- [RabbitMQ](rabbitmq)
57+
- [React Router](./react-router)
58+
- [Recover from panic](./recover)
59+
- [RSS feed](./rss-feed)
60+
- [Serve Static Files](./file-server)
61+
- [Server Timing](./server-timing)
62+
- [Server-Sent Events](./sse)
63+
- [Sessions-SQLite3](./sessions-sqlite3)
64+
- [Single Page Application Example](./spa)
65+
- [Socket.io](./socketio)
66+
- [Sqlboiler](./sqlboiler)
67+
- [Sqlc](./sqlc)
68+
- [Streaming of the Request Body](./stream-request-body)
69+
- [Sveltekit Embed](./sveltekit-embed)
70+
- [Tableflip (Graceful updates)](./tableflip)
71+
- [Template Asset Bundling](./template-asset-bundling)
72+
- [Unit Test Example](./unit-test)
73+
- [Upload Multiple Files](./upload-file/multiple)
74+
- [Upload Single File](./upload-file/single)
75+
- [URL shortener API](./url-shortener-api)
76+
- [User Auth with JWT](./auth-jwt)
77+
- [Validation](./validation)
78+
- [Vercel](./vercel)
79+
- [WebSocket Chat Example](./websocket-chat)
80+
- [WebSockets](./websocket)
81+
82+
## 👩‍🍳 Have a delicious recipe?
83+
84+
If you have found an amazing recipe for **Fiber** — share it with others!
85+
We are ready to accept your [PR](https://github.com/gofiber/recipes/pulls) and add your recipe to the cookbook (both on [website](https://docs.gofiber.io) and this repository).

docs/recipes/air/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Live Reloading with Air Example
2+
3+
This example demonstrates how to set up live reloading for a Go application using the [Air](https://github.com/cosmtrek/air) tool. The purpose of this example is to show how to automatically reload your application during development whenever you make changes to the source code.
4+
5+
## Description
6+
7+
Live reloading is a useful feature during development as it saves time by automatically restarting the application whenever changes are detected. This example sets up a simple Fiber application and configures Air to watch for changes and reload the application.
8+
9+
## Requirements
10+
11+
- [Go](https://golang.org/dl/) 1.18 or higher
12+
- [Git](https://git-scm.com/downloads)
13+
- [Air](https://github.com/cosmtrek/air)
14+
15+
## Setup
16+
17+
1. Clone the repository:
18+
```bash
19+
git clone https://github.com/gofiber/recipes.git
20+
cd recipes/air
21+
```
22+
23+
2. Install the dependencies:
24+
```bash
25+
go mod download
26+
```
27+
28+
3. Install Air:
29+
```bash
30+
go install github.com/cosmtrek/air@latest
31+
```
32+
33+
## Configuration
34+
35+
Air is configured using the `air/.air.conf` file. This file specifies the build command, binary name, and directories to watch for changes. The configuration files for different operating systems are provided:
36+
37+
- `air/.air.windows.conf` for Windows
38+
- `air/.air.linux.conf` for Linux
39+
40+
## Running the Example
41+
42+
To run the example with live reloading, use the following command:
43+
```bash
44+
air -c .air.linux.conf
45+
```
46+
or for Windows:
47+
```bash
48+
air -c .air.windows.conf
49+
```
50+
51+
The server will start and listen on `localhost:3000`. Any changes to the source code will automatically trigger a rebuild and restart of the application.
52+
53+
## Example Routes
54+
55+
- **GET /**: Returns a simple greeting message.
56+
57+
## Code Overview
58+
59+
### `main.go`
60+
61+
```go
62+
package main
63+
64+
import (
65+
"log"
66+
"github.com/gofiber/fiber/v2"
67+
)
68+
69+
func main() {
70+
// Create new Fiber instance
71+
app := fiber.New()
72+
73+
// Create new GET route on path "/"
74+
app.Get("/", func(c *fiber.Ctx) error {
75+
return c.SendString("Hello, World!")
76+
})
77+
78+
// Start server on http://localhost:3000
79+
log.Fatal(app.Listen(":3000"))
80+
}
81+
```
82+
83+
## Conclusion
84+
85+
This example provides a basic setup for live reloading a Go application using Air. It can be extended and customized further to fit the needs of more complex applications.
86+
87+
## References
88+
89+
- [Air Documentation](https://github.com/cosmtrek/air)
90+
- [Fiber Documentation](https://docs.gofiber.io)
91+
- [GitHub Repository](https://github.com/gofiber/fiber)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Auth Docker Postgres JWT Example
2+
3+
This example demonstrates a boilerplate setup for a Go Fiber application that uses Docker, PostgreSQL, and JWT for authentication.
4+
5+
## Description
6+
7+
This project provides a starting point for building a web application with user authentication using JWT. It leverages Docker for containerization and PostgreSQL as the database.
8+
9+
## Requirements
10+
11+
- [Docker](https://www.docker.com/get-started)
12+
- [Docker Compose](https://docs.docker.com/compose/install/)
13+
- [Go](https://golang.org/dl/) 1.18 or higher
14+
15+
## Setup
16+
17+
1. Clone the repository:
18+
```bash
19+
git clone https://github.com/gofiber/recipes.git
20+
cd recipes/auth-docker-postgres-jwt
21+
```
22+
23+
2. Set the environment variables in a `.env` file:
24+
```env
25+
DB_PORT=5432
26+
DB_USER=example_user
27+
DB_PASSWORD=example_password
28+
DB_NAME=example_db
29+
SECRET=example_secret
30+
```
31+
32+
3. Build and start the Docker containers:
33+
```bash
34+
docker-compose build
35+
docker-compose up
36+
```
37+
38+
The API and the database should now be running.
39+
40+
## Database Management
41+
42+
You can manage the database via `psql` with the following command:
43+
```bash
44+
docker-compose exec db psql -U <DB_USER>
45+
```
46+
47+
Replace `<DB_USER>` with the value from your `.env` file.
48+
49+
## API Endpoints
50+
51+
The following endpoints are available in the API:
52+
53+
- **POST /api/auth/register**: Register a new user.
54+
- **POST /api/auth/login**: Authenticate a user and return a JWT.
55+
- **GET /api/user/:id**: Get a user (requires a valid JWT).
56+
- **PATCH /api/user/:id**: Update a user (requires a valid JWT).
57+
- **DELETE /api/user/:id**: Delete a user (requires a valid JWT).
58+
59+
## Example Usage
60+
61+
1. Register a new user:
62+
```bash
63+
curl -X POST http://localhost:3000/api/auth/register -d '{"username":"testuser", "password":"testpassword"}' -H "Content-Type: application/json"
64+
```
65+
66+
2. Login to get a JWT:
67+
```bash
68+
curl -X POST http://localhost:3000/api/auth/login -d '{"username":"testuser", "password":"testpassword"}' -H "Content-Type: application/json"
69+
```
70+
71+
3. Access a protected route:
72+
```bash
73+
curl -H "Authorization: Bearer <JWT>" http://localhost:3000/api/user/1
74+
```
75+
76+
Replace `<JWT>` with the token received from the login endpoint.
77+
78+
## Conclusion
79+
80+
This example provides a basic setup for a Go Fiber application with Docker, PostgreSQL, and JWT authentication. It can be extended and customized further to fit the needs of more complex applications.
81+
82+
## References
83+
84+
- [Fiber Documentation](https://docs.gofiber.io)
85+
- [Docker Documentation](https://docs.docker.com)
86+
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)
87+
- [JWT Documentation](https://jwt.io/introduction/)

0 commit comments

Comments
 (0)