-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleans up the documentation, puts data flow on its own page
- Loading branch information
Showing
14 changed files
with
154 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import FlowChart from '@site/src/components/FlowChart'; | ||
|
||
# Data Flow | ||
|
||
Here's a high-level overview of how data flows through a Fuego application. | ||
|
||
Please note that every step can send an error to the error handler. | ||
|
||
<FlowChart /> |
3 changes: 0 additions & 3 deletions
3
documentation/docs/guides/controllers.mdx → documentation/docs/guides/controllers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
documentation/docs/guides/errors.mdx → documentation/docs/guides/errors.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Validation | ||
|
||
Validation is the process of ensuring that the data provided to the application | ||
is correct and meaningful. | ||
|
||
With fuego, you have several options for validating data. | ||
|
||
- struct tags with `go-validator` | ||
- custom validation functions | ||
|
||
## Struct tags | ||
|
||
You can use struct tags to validate the data coming into your application. | ||
This is a common pattern in Go and is used by many libraries, | ||
and we use [`go-playground/validator`](https://github.com/go-playground/validator) to do so. | ||
|
||
```go | ||
type User struct { | ||
FirstName string `json:"first_name" validate:"required"` | ||
LastName string `json:"last_name" validate:"required"` | ||
Age int `json:"age" validate:"gte=0,lte=130"` | ||
Email string `json:"email" validate:"email"` | ||
} | ||
``` | ||
|
||
## Custom validation | ||
|
||
You can also use Fuego's [Transformation](./transformation.md) methods to validate the data. | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/go-fuego/fuego" | ||
) | ||
|
||
type User struct { | ||
FirstName string `json:"first_name"` | ||
LastName string `json:"last_name"` | ||
} | ||
|
||
func (u *User) InTransform(ctx context.Context) error { | ||
u.FirstName = strings.ToUpper(u.FirstName) | ||
u.LastName = strings.TrimSpace(u.LastName) | ||
|
||
if u.FirstName == "" { | ||
return errors.New("first name is required") | ||
} | ||
return nil | ||
} | ||
|
||
var _ fuego.InTransformer = (*User)(nil) // Ensure *User implements fuego.InTransformer | ||
// This check is a classic example of Go's interface implementation check and we highly recommend to use it | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters