Skip to content

Commit

Permalink
Cleans up the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Nov 29, 2024
1 parent 70d1d14 commit dfbe976
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
36 changes: 33 additions & 3 deletions documentation/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,47 @@ sidebar_position: 1

Let's discover **Fuego in less than 5 minutes**.

## Getting Started
## Quick peek without installing

Try our [Hello World](./tutorials/01-hello-world.md)!

```bash
go run github.com/go-fuego/fuego/examples/hello-world@latest
```

Or **try Fuego immediately** by cloning **[one of our examples](https://github.com/go-fuego/fuego/tree/main/examples)**.
This runs the code for a simple hello world server. Look at all it generates from a simple code! You'll get a URL to see the result in your browser.

```go showLineNumbers
package main

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

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

fuego.Get(s, "/", helloWorld)

s.Run()
}

func helloWorld(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
}
```

## Try example from real Fuego source code in 3 sec

Try Fuego immediately by cloning [the repo](https://github.com/go-fuego/fuego) and running one of our examples.

```bash
git clone git@github.com:go-fuego/fuego.git
cd fuego/examples/petstore
go run .
```

### What you'll need

- [Golang v1.22](https://golang.org/doc/go1.22) or above
_(Fuego relies on a new feature of the net/http package only available after 1.22)_.
_(Fuego relies on a new feature of the net/http package only available after 1.22)_.
30 changes: 21 additions & 9 deletions documentation/docs/tutorials/02-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ fuego controller books
go run github.com/go-fuego/fuego/cmd/fuego@latest controller books
```

After executing the above code,
you need to slightly modify the generated controllers/books.go and main.go files.
This generates a controller and a service for the `books` resource.

```go title="controllers/books.go" {8-9,28-39}
You then have to implement the service interface in the controller to be able to play with data. It's a form of **dependency injection** that we chose to use for the code generator of Fuego, but you can implement it in any way you want.

To implement the service, you need to slightly modify the generated controllers/books.go and main.go files.

```go title="controllers/books.go" {8-9,28-39} showLineNumbers
package controller

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

type BooksResources struct {
// CHANGE NEXT LINE (BooksService -> RealBooksService)
// Use a concrete struct that implements the service (BooksService -> RealBooksService)
BooksService RealBooksService
}

Expand All @@ -45,9 +48,9 @@ type BooksService interface {
}


// ADD THIS CODE BLOCK
// Implement the BooksService interface
type RealBooksService struct {
BooksService
BooksService // Embed the interface to satisfy it -this pattern is just there to make the code compile but you should implement all methods
}

func (s RealBooksService) GetBooks(id string) (Books, error) {
Expand All @@ -62,7 +65,9 @@ func (s RealBooksService) GetBooks(id string) (Books, error) {
// END OF CODE BLOCK
```
```go title="main.go" {4-5,13-14}
Then we'll inject this controller into the server.
```go title="main.go" {6-7,14-21}
package main

import (
Expand All @@ -76,8 +81,15 @@ func main() {
s := fuego.NewServer()
// ....

// ADD NEXT LINE
controllers.BooksResources{}.Routes(s)
// Declare the ressource
booksResources := controllers.BooksResources{
BooksService: controllers.RealBooksService{},
// Other services & dependencies, like a DB etc.
}

// Plug the controllers into the server
booksResources.Routes(s)

s.Run()
}
```
Expand Down

0 comments on commit dfbe976

Please sign in to comment.