Skip to content

Commit

Permalink
Added base documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 7, 2024
1 parent dfc1b51 commit 4001c81
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
title: Hello World
position: 1
order: 1
---

# Hello world
Expand Down
105 changes: 105 additions & 0 deletions documentation/docs/tutorials/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,111 @@

How to write simple CRUD operations.

:::tip

Fuego comes with a **generator** that can generates CRUD routes and controllers for you!

:::

## Generation

```bash
go install github.com/go-fuego/fuego/cmd/fuego@latest
fuego controller books

# or in one line:
go run github.com/go-fuego/fuego/cmd/fuego@latest controller books
```

## The routes

The generator will create the following routes:

- `GET /books`: list all books
- `POST /books`: create a new book
- `GET /books/:id`: get a book by id
- `PUT /books/:id`: update a book by id
- `PATCH /books/:id`: update a book by id
- `DELETE /books/:id`: delete a book by id

If you want to create the routes manually, you can use the following code:

```go title="main.go"
package main

import (
"github.com/go-fuego/fuego"
)

type Book struct {
ID string `json:"id"`
Title string `json:"title"`
}

func main() {
s := fuego.NewServer()

// List all books
fuego.Get(s, "/books", getBooks)

// Create a new book
fuego.Post(s, "/books", createBook)

// Get a book by id
fuego.Get(s, "/books/:id", getBook)

// Update a book by id
fuego.Put(s, "/books/:id", updateBook)

// Update a book by id
fuego.Patch(s, "/books/:id", updateBook)

// Delete a book by id
fuego.Delete(s, "/books/:id", deleteBook)

s.Run()
}
```

```go title="controllers/books.go"
package controllers

import (
"github.com/go-fuego/fuego"
)

type Book struct {
ID string `json:"id"`
Title string `json:"title"`
}

type BookToCreate struct {
Title string `json:"title"`
}

func getBooks(c fuego.ContextNoBody) ([]Book, error) {
// Your code here
return nil, nil
}

func createBook(c fuego.ContextWithBody[BookToCreate]) (Book, error) {
// Your code here
return Book{}, nil
}

func getBook(c fuego.ContextNoBody) (Book, error) {
// Your code here
return Book{}, nil
}

func updateBook(c fuego.ContextWithBody[Book]) (Book, error) {
// Your code here
return Book{}, nil
}

func deleteBook(c fuego.ContextNoBody) error {
// Your code here
return nil
}

```
20 changes: 20 additions & 0 deletions documentation/docs/tutorials/hot-reload.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# Hot reload

Hot reload is a feature that allows you to update your code and see the changes in real-time without restarting the server. This is very useful for development, as it allows you to see the changes you make to your code immediately.

To enable hot reload, you need to install the `air` command-line tool:

```sh
go install github.com/cosmtrek/air@latest
```

Then, create a `.air.toml` file in the root of your project with the following content:

```sh
air init
```

Finally, simply the following command to start the server with hot reload:

```sh
air
```

0 comments on commit 4001c81

Please sign in to comment.