Skip to content

Commit

Permalink
Merge pull request #88 from chenjunqian/feat/en
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn authored Nov 26, 2024
2 parents 15c4e2d + 6a808b0 commit e3dbd76
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ slug: /quick-next
title: "What's Next"
hide_title: true
sidebar_position: 10
keywords: [GoFrame,GoFrame Framework,Web Server,Development Manual,Modular Design,Low Coupling,Video Tutorial,Project Scaffold,Business Project,Development Process]
description: "Quickly understand the development process and features of the Web Server API by viewing the development manual sections to resolve any doubts. GoFrame is a low-coupling, modular design framework with independent module designs, and independently written documentation. The community provides introductory video tutorials, and later a complete business project will be developed using the GoFrame framework project scaffold."
keywords: [GoFrame,GoFrame Framework,Web Server,Documents,Modular Design,Low Coupling,Video Tutorial,Project Scaffold,Business Project,Development Process]
description: "Quickly understand the development process and features of the Web Server API by viewing the Documents sections to resolve any doubts. GoFrame is a low-coupling, modular design framework with independent module designs, and independently written documentation. The community provides introductory video tutorials, and later a complete business project will be developed using the GoFrame framework project scaffold."
---

## Learning Summary
Through the quick sections, you should have understood the complete development process of the `Web Server` API and mastered some practical features. In these sections, we only touched on them briefly; for more detailed explanations and introductions to functional features, please refer to the corresponding development manual sections. When you feel confused about the use of a particular module, it is recommended to carefully read the corresponding development manual sections, which provide detailed explanations of the important functional features, usage methods, and common issues of each component.
Through the quick sections, you should have understood the complete development process of the `Web Server` API and mastered some practical features. In these sections, we only touched on them briefly; for more detailed explanations and introductions to functional features, please refer to the corresponding Documents sections. When you feel confused about the use of a particular module, it is recommended to carefully read the corresponding Documents sections, which provide detailed explanations of the important functional features, usage methods, and common issues of each component.

:::info
If you start browsing the development manual, it should be noted that since `GoFrame` is a low-coupling, modular design, each module is relatively independent. Therefore, the documentation in the development manual is also written based on modularity, with each chapter introducing only the usage of the corresponding component itself.
If you start browsing the Documents, it should be noted that since `GoFrame` is a low-coupling, modular design, each module is relatively independent. Therefore, the documentation in the Documents is also written based on modularity, with each chapter introducing only the usage of the corresponding component itself.
:::

What should we do next?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ We access http://127.0.0.1:8000/?name=john&age=18 and can see that the page outp

![img.png](img.png)

We try an incorrect parameter request http://127.0.0.1:8000/ and can see that the page output also matches the expectation.
We try an invalid parameter request http://127.0.0.1:8000/ and can see that the page output also matches the expectation.

![img_4.png](img_4.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ slug: '/quick/strict-router'
title: 'Standard Routing'
hide_title: true
sidebar_position: 5
keywords: [GoFrame, GoFrame framework, strict routing, route registration, data structure, route object management, Go language, web server, HTTP methods, route callbacks]
description: "Use strict routing in the GoFrame framework to simplify route registration, focusing on business logic. Standardize route registration by defining request and response data structures, and manage routes using an object-oriented approach to enhance code maintainability. Provides complete sample code and execution results to guide readers in applying it to real projects."
keywords: [GoFrame, GoFrame framework, standard routing, route registration, data structure, route object management, Go language, web server, HTTP methods, route callbacks]
description: "Use standard routing in the GoFrame framework to simplify route registration, focusing on business logic. Standardize route registration by defining request and response data structures, and manage routes using an object-oriented approach to enhance code maintainability. Provides complete sample code and execution results to guide readers in applying it to real projects."
---

To simplify the route registration method and avoid some tedious parameter handling details, allowing developers to focus on the business logic itself, the `GoFrame` framework provides a standardized route registration method. We name this standardized route registration method **Strict Routing** to make it straightforward and intuitive.
To simplify the route registration method and avoid some tedious parameter handling details, allowing developers to focus on the business logic itself, the `GoFrame` framework provides a standardized route registration method. We name this standardized route registration method **Standard Routing** to make it straightforward and intuitive.

## Data Structure Definition

In strict routing, we define a request data structure to receive parameters submitted by the client, and at the same time, we need to define a return object. The purpose is for future return parameter extensions and to standardize API documentation generation.
In standard routing, we define a request data structure to receive parameters submitted by the client, and at the same time, we need to define a return object. The purpose is for future return parameter extensions and to standardize API documentation generation.
```go
type HelloReq struct {
g.Meta `path:"/" method:"get"`
Expand Down Expand Up @@ -107,7 +107,7 @@ After running, we visit http://127.0.0.1:8000/?name=john&age=18 and see that the

![img.png](img.png)

We try an incorrect parameter request http://127.0.0.1:8000/ but find that the page does not output any results. **This is because the parameter validation failed and did not enter our route callback function, but was directly returned by the `Server`.**
We try an invalid parameter request http://127.0.0.1:8000/ but find that the page does not output any results. **This is because the parameter validation failed and did not enter our route callback function, but was directly returned by the `Server`.**

## Learning Summary

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ After running, we visit http://127.0.0.1:8000/?name=john&age=18 and see that the

![img_3.png](img_3.png)

We try an incorrect parameter request http://127.0.0.1:8000/ and see that the page output still matches the expectation.
We try an invalid parameter request http://127.0.0.1:8000/ and see that the page output still matches the expectation.

![img_5.png](img_5.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
}
```
In this example:
- We use the `r.Parse` method to map request parameters onto a request object, allowing us to use parameters in an object-oriented manner. The `r.Parse` method automatically parses client-submitted parameters and assigns them to the specified object. There is a fixed name mapping logic internally, which you will learn in detail in the type conversion component of the development manual, and it is not elaborated on here.
- We use the `r.Parse` method to map request parameters onto a request object, allowing us to use parameters in an object-oriented manner. The `r.Parse` method automatically parses client-submitted parameters and assigns them to the specified object. There is a fixed name mapping logic internally, which you will learn in detail in the type conversion component of the documents, and it is not elaborated on here.
- Additionally, we have added validation logic in this example to ensure that the `Name` and `Age` parameters cannot be empty.

## Execution Result
Expand All @@ -72,7 +72,7 @@ After running it, when we visit http://127.0.0.1:8000/?name=john&age=18, we can

![img.png](img.png)

Let's try an erroneous parameter request at http://127.0.0.1:8000/, and we can see that parameters are validated as expected, with the page output also matching expectations.
Let's try an invalid parameter request at http://127.0.0.1:8000/, and we can see that parameters are validated as expected, with the page output also matching expectations.

![img_2.png](img_2.png)

Expand All @@ -81,7 +81,7 @@ Let's try an erroneous parameter request at http://127.0.0.1:8000/, and we can s
In this chapter, we learned to avoid the problem of hardcoding parameter names by using structured request objects, allowing for better maintenance of parameter names, descriptions, and type definitions.

However, there are still areas for improvement in this sample code:
- The `r.Parse` operation is business-independent and should be handled separately from business logic.
- The `r.Parse` is non-business operation and should be handled separately from business logic.
- If there are many APIs, performing `r.Parse` in all of them becomes cumbersome.
- Regarding data validation, if there are many API parameters, performing numerous `if` data validation operations becomes overly cumbersome.

Expand Down

0 comments on commit e3dbd76

Please sign in to comment.