Skip to content

Commit

Permalink
[v3-Maintenance]-Consolidate-and-Document-Core-Changes-in-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Apr 20, 2024
1 parent 22786d2 commit bd348c4
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 99 deletions.
4 changes: 2 additions & 2 deletions docs/core/api/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "\uD83D\uDEE0\uFE0F Api",
"position": 2,
"label": "\uD83D\uDEE0\uFE0F API",
"position": 3,
"link": {
"type": "generated-index",
"description": "API documentation for Fiber."
Expand Down
6 changes: 4 additions & 2 deletions docs/core/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ app.Static("/", "./public", fiber.Static{
<RoutingHandler />
### Mount
### Mounting
You can Mount Fiber instance by creating a `*Mount`
[//]: # (TODO: not there anymore -> use app.Use&#40;"/prefix", app&#41; instead)
You can Mount Fiber instance using the [`app.Use`](./app.md#use) method similar to [`express`](https://expressjs.com/en/api.html#router.use).
```go title="Signature"
func (a *App) Mount(prefix string, app *App) Router
Expand Down
4 changes: 2 additions & 2 deletions docs/core/api/bind.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ app.Get("/", func(c fiber.Ctx) error {
```

:::info
For more parser settings please look here [Config](fiber.md#config)
For more parser settings please look here [Config](fiber.md#enablesplittingonparsers)
:::


Expand Down Expand Up @@ -547,7 +547,7 @@ app.Get("/query", func(c fiber.Ctx) error {

Validation is also possible with the binding methods. You can specify your validation rules using the `validate` struct tag.

Specify your struct validator in the [config](./fiber.md#config)
Specify your struct validator in the [config](./fiber.md#structvalidator)

Setup your validator in the config:

Expand Down
6 changes: 3 additions & 3 deletions docs/core/api/ctx.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ app.Get("/", func(c fiber.Ctx) error {
})
```

When registering the proxy request header in the fiber app, the ip address of the header is returned [(Fiber configuration)](fiber.md#config)
When registering the proxy request header in the fiber app, the ip address of the header is returned [(Fiber configuration)](fiber.md#proxyheader)

```go
app := fiber.New(fiber.Config{
Expand Down Expand Up @@ -811,7 +811,7 @@ app.Get("/", func(c fiber.Ctx) error {
## IsProxyTrusted
Checks trustworthiness of remote ip.
If [`EnableTrustedProxyCheck`](fiber.md#config) false, it returns true
If [`EnableTrustedProxyCheck`](fiber.md#enabletrustedproxycheck) false, it returns true
IsProxyTrusted can check remote ip by proxy ranges and ip map.
```go title="Signature"
Expand Down Expand Up @@ -1621,7 +1621,7 @@ app.Post("/", func(c fiber.Ctx) error {
Contains the request protocol string: http or https for TLS requests.
:::info
Please use [`Config.EnableTrustedProxyCheck`](fiber.md#config) to prevent header spoofing, in case when your app is behind the proxy.
Please use [`Config.EnableTrustedProxyCheck`](fiber.md#enabletrustedproxycheck) to prevent header spoofing, in case when your app is behind the proxy.
:::
```go title="Signature"
Expand Down
110 changes: 56 additions & 54 deletions docs/core/api/fiber.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/core/extra/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "\uD83E\uDDE9 Extra",
"position": 5,
"position": 6,
"link": {
"type": "generated-index",
"description": "Extra contents for Fiber."
Expand Down
2 changes: 1 addition & 1 deletion docs/core/extra/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ A complete example demonstrating the use of Air with Fiber can be found in the [

## How do I set up an error handler?

To override the default error handler, you can override the default when providing a [Config](../api/fiber.md#config) when initiating a new [Fiber instance](../api/fiber.md#new).
To override the default error handler, you can override the default when providing a [Config](../api/fiber.md#errorhandler) when initiating a new [Fiber instance](../api/fiber.md#new).

```go title="Example"
app := fiber.New(fiber.Config{
Expand Down
2 changes: 1 addition & 1 deletion docs/core/guide/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "\uD83D\uDCD6 Guide",
"position": 4,
"position": 5,
"link": {
"type": "generated-index",
"description": "Guides for Fiber."
Expand Down
2 changes: 1 addition & 1 deletion docs/core/guide/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var DefaultErrorHandler = func(c fiber.Ctx, err error) error {

## Custom Error Handler

A custom error handler can be set using a [Config ](../api/fiber.md#config)when initializing a [Fiber instance](../api/fiber.md#new).
A custom error handler can be set using a [Config](../api/fiber.md#errorhandler) when initializing a [Fiber instance](../api/fiber.md#new).

In most cases, the default error handler should be sufficient. However, a custom error handler can come in handy if you want to capture different types of errors and take action accordingly e.g., send a notification email or log an error to the centralized system. You can also send customized responses to the client e.g., error page or just a JSON response.

Expand Down
5 changes: 3 additions & 2 deletions docs/core/guide/faster-fiber.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func main() {
```

### References

- [Set custom JSON encoder for client](../api/client.md#jsonencoder)
- [Set custom JSON decoder for client](../api/client.md#jsondecoder)
- [Set custom JSON encoder for application](../api/fiber.md#config)
- [Set custom JSON decoder for application](../api/fiber.md#config)
- [Set custom JSON encoder for application](../api/fiber.md#jsonencoder)
- [Set custom JSON decoder for application](../api/fiber.md#jsondecoder)
4 changes: 2 additions & 2 deletions docs/core/middleware/_category_.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"label": "🧬 Middleware",
"position": 3,
"label": "\uD83E\uDDEC Middleware",
"position": 4,
"collapsed": true,
"link": {
"type": "generated-index",
Expand Down
37 changes: 25 additions & 12 deletions docs/core/partials/routing/handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ id: route-handlers
title: Route Handlers
---

import Reference from '@site/src/components/reference';

Registers a route bound to a specific [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods).

```go title="Signatures"
// HTTP methods
func (app *App) Get(path string, handlers ...Handler) Router
func (app *App) Head(path string, handlers ...Handler) Router
func (app *App) Post(path string, handlers ...Handler) Router
func (app *App) Put(path string, handlers ...Handler) Router
func (app *App) Delete(path string, handlers ...Handler) Router
func (app *App) Connect(path string, handlers ...Handler) Router
func (app *App) Options(path string, handlers ...Handler) Router
func (app *App) Trace(path string, handlers ...Handler) Router
func (app *App) Patch(path string, handlers ...Handler) Router
func (app *App) Get(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Head(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Post(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Put(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Delete(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Connect(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Options(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Trace(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Patch(path string, handler Handler, middlewares ...Handler) Router

// Add allows you to specify a method as value
func (app *App) Add(method, path string, handlers ...Handler) Router
func (app *App) Add(method, path string, handler Handler, middlewares ...Handler) Router

// All will register the route on all HTTP methods
// Almost the same as app.Use but not bound to prefixes
func (app *App) All(path string, handlers ...Handler) Router
func (app *App) All(path string, handler Handler, middlewares ...Handler) Router
```

```go title="Examples"
Expand All @@ -37,10 +39,18 @@ app.Post("/api/register", func(c fiber.Ctx) error {
})
```

**Use** can be used for middleware packages and prefix catchers. These routes will only match the beginning of each path i.e. `/john` will match `/john/doe`, `/johnnnnn` etc
<Reference id="use">**Use**</Reference>

Can be used for middleware packages and prefix catchers. These routes will only match the beginning of each path i.e. `/john` will match `/john/doe`, `/johnnnnn` etc

```go title="Signature"
func (app *App) Use(args ...any) Router

// Different usage variations
func (app *App) Use(handler Handler, middlewares ...Handler) Router
func (app *App) Use(path string, handler Handler, middlewares ...Handler) Router
func (app *App) Use(paths []string, handler Handler, middlewares ...Handler) Router
func (app *App) Use(path string, app *App) Router
```

```go title="Examples"
Expand All @@ -66,4 +76,7 @@ app.Use("/api", func(c fiber.Ctx) error {
}, func(c fiber.Ctx) error {
return c.Next()
})

// Mount a sub-app
app.Use("/api", api)
```
9 changes: 8 additions & 1 deletion docs/core/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ Fiber v3 is a major release with a lot of new features, improvements, and breaki
## 🚀 Highlights

### Drop for old Go versions

Fiber v3 drops support for Go versions below 1.21. We recommend upgrading to Go 1.21 or higher to use Fiber v3.

### App changes

- Listen functions reduced
We have made several changes to the Fiber app, including:

Listen
Mount


### Context change
#### interface
Expand Down
19 changes: 12 additions & 7 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,14 @@ const config = {
editUrl: (params) => {
// console.log(params);
if (params.version === 'current') {
return 'https://github.com/gofiber/fiber/edit/master/docs/' + params.docPath;
return 'https://github.com/gofiber/fiber/edit/main/docs/' + params.docPath;
}
return undefined;
},
sidebarItemsGenerator: async function ({defaultSidebarItemsGenerator, ...args}) {
// filter partials from sidebar
return (await defaultSidebarItemsGenerator(args)).filter((item) => !(item.label === 'partials' || item.id === 'partials'));
},
showLastUpdateAuthor: false,
showLastUpdateTime: true,
versions: {
Expand All @@ -172,12 +176,13 @@ const config = {
src: 'img/logo.svg',
srcDark: 'img/logo-dark.svg',
},
items: [{
type: 'doc',
docId: 'welcome',
label: '🏠 Home',
position: 'left',
},
items: [
{
type: 'doc',
docId: 'welcome',
label: '🏠 Home',
position: 'left',
},
{
type: 'dropdown',
label: '🧩 Extra',
Expand Down
9 changes: 1 addition & 8 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
tutorialSidebar: [
{type: 'doc', id: 'welcome'},
{type: 'doc', id: 'whats_new'},
{type: 'category', label: '🛠️ Api', link: {type: 'generated-index', description: 'API documentation for Fiber.'}, items: [{type: 'autogenerated', dirName: 'api'}]},
{type: 'category', label: '🧬 Middleware', link: {type: 'generated-index', description: 'Middleware is a function chained in the HTTP request cycle with access to the Context which it uses to perform a specific action, for example, logging every request or enabling CORS.'}, items: [{type: 'autogenerated', dirName: 'middleware'}], collapsed: true},
{type: 'category', label: '📖 Guide', link: {type: 'generated-index', description: 'Guides for Fiber.'}, items: [{type: 'autogenerated', dirName: 'guide'}]},
{type: 'category', label: '🧩 Extra', link: {type: 'generated-index', description: 'Extra contents for Fiber.'}, items: [{type: 'autogenerated', dirName: 'extra'}]},
// replace this without partials folder when the exclude feature is there fo rthe autogenerated feature
// {type: 'autogenerated', dirName: '.'}
{type: 'autogenerated', dirName: '.'}
],
};

Expand Down
14 changes: 14 additions & 0 deletions src/components/reference/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import Link from '@docusaurus/Link';
import useBrokenLinks from '@docusaurus/useBrokenLinks';

export default function Reference({children, id}) {
const brokenLinks = useBrokenLinks();
brokenLinks.collectAnchor(id);

return (
<>
<div id={id} className={'reference anchor'}>{children}<Link to={'#' + id} className={'hash-link'}></Link></div>
</>
);
}
4 changes: 4 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ table {
.margin-between > *:not(:first-child) {
margin-top: 1rem;
}

div.reference {
scroll-margin-top: calc(var(--ifm-navbar-height) + 3rem);
}

0 comments on commit bd348c4

Please sign in to comment.