Skip to content

Commit

Permalink
initial docusaurus migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Nov 14, 2022
1 parent 553b721 commit 9b2c8a1
Show file tree
Hide file tree
Showing 202 changed files with 24,611 additions and 8,255 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .gitbook/assets/benchmark (2) (2) (2) (2) (2).png
Binary file not shown.
Binary file removed .gitbook/assets/benchmark-pipeline (2) (1) (1).png
Binary file not shown.
Binary file removed .gitbook/assets/benchmark-pipeline (2) (1).png
Binary file not shown.
Binary file removed .gitbook/assets/benchmark_alloc (2) (1).png
Binary file not shown.
Binary file removed .gitbook/assets/benchmark_alloc (2).png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .gitbook/assets/concurrency (2) (2) (2) (2) (1).png
Binary file not shown.
Binary file removed .gitbook/assets/concurrency (2) (2) (2) (2) (2).png
Binary file not shown.
Binary file removed .gitbook/assets/concurrency (2) (2) (2) (2).png
Binary file not shown.
Binary file removed .gitbook/assets/concurrency-pipeline (2) (1) (1).png
Binary file not shown.
Binary file removed .gitbook/assets/concurrency-pipeline (2) (1).png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .gitbook/assets/cpubound_benchmark (1).png
Binary file not shown.
Binary file removed .gitbook/assets/cpubound_benchmark.png
Binary file not shown.
Binary file removed .gitbook/assets/cpubound_concurrency (1).png
Binary file not shown.
Binary file removed .gitbook/assets/cpubound_concurrency.png
Binary file not shown.
Binary file removed .gitbook/assets/data_updates_express.png
Diff not rendered.
Binary file removed .gitbook/assets/data_updates_old.png
Diff not rendered.
Binary file removed .gitbook/assets/json_old.png
Diff not rendered.
Binary file removed .gitbook/assets/logo_320px_trans.png
Diff not rendered.
Binary file removed .gitbook/assets/multiple_queries_old.png
Diff not rendered.
Binary file removed .gitbook/assets/plaintext (1).png
Diff not rendered.
Diff not rendered.
Binary file removed .gitbook/assets/single_query (1) (1).png
Diff not rendered.
Binary file removed .gitbook/assets/single_query.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed .gitbook/assets/techempower-json.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed .gitbook/assets/techempower-multiple-queries.png
Diff not rendered.
Binary file removed .gitbook/assets/techempower-plaintext (1).png
Diff not rendered.
Binary file removed .gitbook/assets/techempower-plaintext-latency.png
Diff not rendered.
Binary file removed .gitbook/assets/techempower-plaintext.png
Diff not rendered.
Diff not rendered.
Binary file removed .gitbook/assets/techempower-single-query.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed .gitbook/assets/techempower-updates.png
Diff not rendered.
22 changes: 19 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# macOS files
**/.DS_Store
# Dependencies
/node_modules

.idea
# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
179 changes: 15 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,190 +1,41 @@
## 👋 Welcome to Fiber Docs
An online API documentation with examples so you can start building web apps with Fiber right away!
# Website

**Fiber** is an [Express](https://github.com/expressjs/express) inspired **web framework** built on top of [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for [Go](https://go.dev/doc/). Designed to **ease** things up for **fast** development with **zero memory allocation** and **performance** in mind.

These docs are for **Fiber v2**, which was released on **September 15th, 2020**.
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.

### Installation

First of all, [download](https://go.dev/dl/) and install Go. `1.14` or higher is required.

Installation is done using the [`go get`](https://pkg.go.dev/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) command:

```
go get github.com/gofiber/fiber/v2
$ yarn
```

### Zero Allocation
Some values returned from \***fiber.Ctx** are **not** immutable by default.

Because fiber is optimized for **high-performance**, values returned from **fiber.Ctx** are **not** immutable by default and **will** be re-used across requests. As a rule of thumb, you **must** only use context values within the handler, and you **must not** keep any references. As soon as you return from the handler, any values you have obtained from the context will be re-used in future requests and will change below your feet. Here is an example:
### Local Development

```go
func handler(c *fiber.Ctx) error {
// Variable is only valid within this handler
result := c.Params("foo")

// ...
}
```

If you need to persist such values outside the handler, make copies of their **underlying buffer** using the [copy](https://pkg.go.dev/builtin/#copy) builtin. Here is an example for persisting a string:

```go
func handler(c *fiber.Ctx) error {
// Variable is only valid within this handler
result := c.Params("foo")

// Make a copy
buffer := make([]byte, len(result))
copy(buffer, result)
resultCopy := string(buffer)
// Variable is now valid forever

// ...
}
$ yarn start
```

We created a custom `CopyString` function that does the above and is available under [gofiber/utils](https://github.com/gofiber/fiber/tree/master/utils).
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

```go
app.Get("/:foo", func(c *fiber.Ctx) error {
// Variable is now immutable
result := utils.CopyString(c.Params("foo"))
### Build

// ...
})
```

Alternatively, you can also use the `Immutable` setting. It will make all values returned from the context immutable, allowing you to persist them anywhere. Of course, this comes at the cost of performance.

```go
app := fiber.New(fiber.Config{
Immutable: true,
})
$ yarn build
```

For more information, please check [**\#426**](https://github.com/gofiber/fiber/issues/426) and [**\#185**](https://github.com/gofiber/fiber/issues/185).

### Hello, World!

Embedded below is essentially the most straightforward **Fiber** app you can create:
This command generates static content into the `build` directory and can be served using any static contents hosting service.

```go
package main
### Deployment

import "github.com/gofiber/fiber/v2"
Using SSH:

func main() {
app := fiber.New()

app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})

app.Listen(":3000")
}
```

```text
go run server.go
$ USE_SSH=true yarn deploy
```

Browse to `http://localhost:3000` and you should see `Hello, World!` on the page.

### Basic routing

Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (`GET`, `PUT`, `POST`, etc.).

Each route can have **multiple handler functions** that are executed when the route is matched.
Not using SSH:

Route definition takes the following structures:

```go
// Function signature
app.Method(path string, ...func(*fiber.Ctx) error)
```

- `app` is an instance of **Fiber**
- `Method` is an [HTTP request method](https://docs.gofiber.io/api/app#route-handlers): `GET`, `PUT`, `POST`, etc.
- `path` is a virtual path on the server
- `func(*fiber.Ctx) error` is a callback function containing the [Context](https://docs.gofiber.io/api/ctx) executed when the route is matched

**Simple route**

```go
// Respond with "Hello, World!" on root path, "/"
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
$ GIT_USER=<Your GitHub username> yarn deploy
```

**Parameters**

```go
// GET http://localhost:8080/hello%20world

app.Get("/:value", func(c *fiber.Ctx) error {
return c.SendString("value: " + c.Params("value"))
// => Get request with value: hello world
})
```

**Optional parameter**

```go
// GET http://localhost:3000/john

app.Get("/:name?", func(c *fiber.Ctx) error {
if c.Params("name") != "" {
return c.SendString("Hello " + c.Params("name"))
// => Hello john
}
return c.SendString("Where is john?")
})
```

**Wildcards**

```go
// GET http://localhost:3000/api/user/john

app.Get("/api/*", func(c *fiber.Ctx) error {
return c.SendString("API path: " + c.Params("*"))
// => API path: user/john
})
```

### Static files

To serve static files such as **images**, **CSS**, and **JavaScript** files, replace your function handler with a file or directory string.

Function signature:

```go
app.Static(prefix, root string, config ...Static)
```

Use the following code to serve files in a directory named `./public`:

```go
app := fiber.New()

app.Static("/", "./public")

app.Listen(":3000")
```

Now, you can load the files that are in the `./public` directory:

```bash
http://localhost:8080/hello.html
http://localhost:8080/js/jquery.js
http://localhost:8080/css/style.css
```

### Note

For more information on how to build APIs in Go with Fiber, please check out this excellent article
[on building an express-style API in Go with Fiber](https://blog.logrocket.com/express-style-api-go-fiber/).
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
51 changes: 0 additions & 51 deletions SUMMARY.md

This file was deleted.

Loading

0 comments on commit 9b2c8a1

Please sign in to comment.