From 7cb13786450c9e1b46e0ac36ffcb2d0c3f9398b5 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 24 Nov 2024 15:51:01 +0800 Subject: [PATCH] up --- .scripts/ai-trans/main.go | 1 + .../3-2022-01-27 Let's GoFrame.md" | 2 +- ...71\347\233\256\344\273\213\347\273\215.md" | 2 +- ...72\346\234\254\344\275\277\347\224\250.md" | 2 +- ...50\344\270\255\351\227\264\344\273\266.md" | 4 +-- ...07\344\273\266\344\270\212\344\274\240.md" | 8 ++--- .../HTTPClient/HTTPClient.md" | 2 +- ...45\345\217\243\345\274\200\345\217\221.md" | 14 ++++----- .../Session/Session.md" | 4 +-- ...02\345\270\270\345\244\204\347\220\206.md" | 2 +- ...\243\346\226\207\346\241\243-OpenAPIv3.md" | 30 +++++++++---------- ...\350\207\252\345\256\232\344\271\211UI.md" | 2 +- ...45\345\217\243\346\226\207\346\241\243.md" | 2 +- ...60\346\215\256\350\277\224\345\233\236.md" | 6 ++-- ...07\344\273\266\346\250\241\346\235\277.md" | 4 +-- ...61\202\350\276\223\345\205\245-Context.md" | 4 +-- ...67\346\261\202\346\240\241\351\252\214.md" | 6 ++-- ...67\346\261\202\350\276\223\345\205\245.md" | 2 +- ...77\347\224\250\347\244\272\344\276\213.md" | 2 +- ...72\346\234\254\344\273\213\347\273\215.md" | 2 +- ...71\350\261\241\346\263\250\345\206\214.md" | 4 +-- ...02\344\275\225\344\275\277\347\224\250.md" | 18 +++++------ ...70\350\247\201\351\227\256\351\242\230.md" | 14 ++++----- ...04\350\214\203\350\267\257\347\224\261.md" | 14 ++++----- ...57\347\224\261\346\263\250\345\206\214.md" | 8 ++--- ...57\347\224\261\350\247\204\345\210\231.md" | 6 ++-- ...50\345\237\237\345\244\204\347\220\206.md" | 14 ++++----- ...62\345\276\241\350\256\276\347\275\256.md" | 4 +-- ...13\344\273\266\345\233\236\350\260\203.md" | 18 +++++------ ...47\350\203\275\345\210\206\346\236\220.md" | 4 +-- .../WebSocket\346\234\215\345\212\241.md" | 8 ++--- ...15\345\220\257\347\211\271\346\200\247.md" | 8 ++--- ...01\347\240\201\345\244\204\347\220\206.md" | 2 +- ...7\243\350\247\204\350\214\203-gen ctrl.md" | 16 +++++----- ...\276\347\273\264\346\212\244-gen enums.md" | 4 +-- ...27\350\247\204\350\214\203-gen service.md" | 20 ++++++------- ...50\345\206\214\345\217\221\347\216\260.md" | 2 +- ...41\346\225\260\346\215\256\350\241\250.md" | 2 +- ...45\345\217\243\345\256\232\344\271\211.md" | 12 ++++---- ...\220controller\344\273\243\347\240\201.md" | 18 +++++------ ...73\350\276\221\345\256\236\347\216\260.md" | 4 +-- ...56\344\270\216\350\267\257\347\224\261.md" | 10 +++---- ...50\344\270\216\346\265\213\350\257\225.md" | 6 ++-- ...45\345\217\243\345\274\200\345\217\221.md" | 6 ++-- 44 files changed, 162 insertions(+), 161 deletions(-) diff --git a/.scripts/ai-trans/main.go b/.scripts/ai-trans/main.go index ba8628faed5..a39d1df5654 100644 --- a/.scripts/ai-trans/main.go +++ b/.scripts/ai-trans/main.go @@ -22,6 +22,7 @@ const ( 不要对顶部的front matter内容使用代码标签包括。 不能删除markdown内容中的图片展示标签内容。 不能翻译链接中的文件路径中的中文名称。 +接口的关键词应当翻译为API。 ` ) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/community/\347\244\276\345\214\272\344\272\244\346\265\201/\346\212\200\346\234\257\345\210\206\344\272\253\344\272\244\346\265\201/3-2022-01-27 Let's GoFrame.md" "b/i18n/en/docusaurus-plugin-content-docs/current/community/\347\244\276\345\214\272\344\272\244\346\265\201/\346\212\200\346\234\257\345\210\206\344\272\253\344\272\244\346\265\201/3-2022-01-27 Let's GoFrame.md" index 533ae503411..a0bbc761287 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/community/\347\244\276\345\214\272\344\272\244\346\265\201/\346\212\200\346\234\257\345\210\206\344\272\253\344\272\244\346\265\201/3-2022-01-27 Let's GoFrame.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/community/\347\244\276\345\214\272\344\272\244\346\265\201/\346\212\200\346\234\257\345\210\206\344\272\253\344\272\244\346\265\201/3-2022-01-27 Let's GoFrame.md" @@ -15,7 +15,7 @@ This Thursday at 8 PM `GOCN` Open Source Talk will feature the topic `Let's GoFr `GoFrame` is a modular, high-performance, enterprise-level `Go` foundational development framework. If you want to use `Golang` to develop a business project, whether it's small or medium to large scale, `GoFrame` is your top choice. If you're looking to develop a `Golang` component library, `GoFrame` provides an out-of-the-box, rich and powerful basic component library that can make your work more efficient. -`GoFrame` offers a unified and practical engineering development standard and supporting tools, automatic data model and database operation code generation, automatic `OpenAPIv3` interface document generation, support for `OpenTelemetry` observability standards, full error stack features, support for error codes, full interface design of core components, and more. Using `GoFrame`'s out-of-the-box basic components, rich development documentation, practical tools, and standards can help us focus our energy on the business itself, write more standardized, secure, and observable code, improve project development and maintenance efficiency, and enable teams and individuals to create more value. +`GoFrame` offers a unified and practical engineering development standard and supporting tools, automatic data model and database operation code generation, automatic `OpenAPIv3` document generation, support for `OpenTelemetry` observability standards, full error stack features, support for error codes, full API design of core components, and more. Using `GoFrame`'s out-of-the-box basic components, rich development documentation, practical tools, and standards can help us focus our energy on the business itself, write more standardized, secure, and observable code, improve project development and maintenance efficiency, and enable teams and individuals to create more value. PPT file download: [gocn-Let's GoFrame.pptx](https://wiki.goframe.org/download/attachments/35359084/gocn-Let%27s%20GoFrame.pptx?version=1&modificationDate=1643289965129&api=v2) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\200\347\253\240-\345\237\272\347\241\200\344\277\241\346\201\257/1.1.\351\241\271\347\233\256\344\273\213\347\273\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\200\347\253\240-\345\237\272\347\241\200\344\277\241\346\201\257/1.1.\351\241\271\347\233\256\344\273\213\347\273\215.md" index 02e2c4f051b..0f3a8113aa2 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\200\347\253\240-\345\237\272\347\241\200\344\277\241\346\201\257/1.1.\351\241\271\347\233\256\344\273\213\347\273\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/course/starbook/\347\254\254\344\270\200\347\253\240-\345\237\272\347\241\200\344\277\241\346\201\257/1.1.\351\241\271\347\233\256\344\273\213\347\273\215.md" @@ -27,7 +27,7 @@ Many years ago, there was no clear boundary between the front end and back end, The design purpose of **Star English Book** is to enable readers to quickly master `GoFrame`, so it also adopts the front-end and back-end separation model. All developed content does not directly output `HTML`, but bypasses the front end, directly outputting standard `JSON` format data. ### JSON -`JSON` is currently the most mainstream data format for front-end and back-end interaction. Data returned by a standard interface is as follows: +`JSON` is currently the most mainstream data format for front-end and back-end interaction. Data returned by a standard API is as follows: ```json { "code": 0, diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\345\237\272\346\234\254\344\275\277\347\224\250.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\345\237\272\346\234\254\344\275\277\347\224\250.md" index d947ad2c69c..aab088c1cdb 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\345\237\272\346\234\254\344\275\277\347\224\250.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\345\237\272\346\234\254\344\275\277\347\224\250.md" @@ -128,7 +128,7 @@ content := g.Client().PostContent( ## `*Var` Method -Request methods ending with the `Var` suffix directly request and obtain `HTTP` interface results as the generic type `g.Var`, **making it easy to execute type conversions, especially converting request results into struct objects**. It is generally used when the server returns data in `JSON/XML` format. By leveraging the returned `g.Var` generic object, you can perform automatic parsing based on your needs. Moreover, if the request fails or the request result is empty, an empty `g.Var` generic object will be returned, ensuring it doesn't affect the conversion method invocation. +Request methods ending with the `Var` suffix directly request and obtain `HTTP` API results as the generic type `g.Var`, **making it easy to execute type conversions, especially converting request results into struct objects**. It is generally used when the server returns data in `JSON/XML` format. By leveraging the returned `g.Var` generic object, you can perform automatic parsing based on your needs. Moreover, if the request fails or the request result is empty, an empty `g.Var` generic object will be returned, ensuring it doesn't affect the conversion method invocation. Example usage: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\213\246\346\210\252\345\231\250\344\270\255\351\227\264\344\273\266.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\213\246\346\210\252\345\231\250\344\270\255\351\227\264\344\273\266.md" index df704681773..11fab03485b 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\213\246\346\210\252\345\231\250\344\270\255\351\227\264\344\273\266.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\213\246\346\210\252\345\231\250\344\270\255\351\227\264\344\273\266.md" @@ -53,7 +53,7 @@ c.Use(func(c *gclient.Client, r *http.Request) (resp *gclient.Response, err erro ## Usage Example -Let's use a code example to better illustrate usage. This example adds an interceptor to the client, injecting custom additional parameters into the submitted JSON data. These additional parameters implement signature generation for the submitted parameters, essentially achieving a simple interface parameter security validation. +Let's use a code example to better illustrate usage. This example adds an interceptor to the client, injecting custom additional parameters into the submitted JSON data. These additional parameters implement signature generation for the submitted parameters, essentially achieving a simple API parameter security validation. ### Server @@ -111,7 +111,7 @@ const ( appSecret = "456" ) -// Inject unified interface signature parameters +// Inject unified API signature parameters func injectSignature(jsonContent []byte) []byte { var m map[string]interface{} _ = json.Unmarshal(jsonContent, &m) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\226\207\344\273\266\344\270\212\344\274\240.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\226\207\344\273\266\344\270\212\344\274\240.md" index 4bebdcc1d82..697e10c1db1 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\226\207\344\273\266\344\270\212\344\274\240.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient-\346\226\207\344\273\266\344\270\212\344\274\240.md" @@ -3,8 +3,8 @@ slug: '/docs/web/http-client-file-uploading' title: 'HTTPClient-File Uploading' sidebar_position: 1 hide_title: true -keywords: [GoFrame,HTTP Client,File Uploading,Server Interface,Form File,GoFrame Framework,Single File Upload,Multiple File Upload,File Path,Upload Parameters] -description: "Using the GoFrame framework for HTTP client file uploading, a convenient file upload feature is implemented, and three major interfaces are provided to support single and multiple file uploads. Detailed explanations of both server and client implementation code are provided, along with methods for custom file naming and standardized routing to receive uploaded files, suitable for scenarios requiring integration of file upload functionality." +keywords: [GoFrame,HTTP Client,File Uploading,Server API,Form File,GoFrame Framework,Single File Upload,Multiple File Upload,File Path,Upload Parameters] +description: "Using the GoFrame framework for HTTP client file uploading, a convenient file upload feature is implemented, and three major APIs are provided to support single and multiple file uploads. Detailed explanations of both server and client implementation code are provided, along with methods for custom file naming and standardized routing to receive uploaded files, suitable for scenarios requiring integration of file upload functionality." --- `GoFrame` supports very convenient form file uploading functionality, and the HTTP client has encapsulated the upload functionality to simplify the calling of the upload feature significantly. @@ -80,11 +80,11 @@ func main() { } ``` -The server provides three interfaces: +The server provides three APIs: 1. [http://127.0.0.1:8199/upload/show](http://127.0.0.1:8199/upload/show) for displaying a single file upload H5 page; 2. [http://127.0.0.1:8199/upload/batch](http://127.0.0.1:8199/upload/batch) for displaying a multiple files upload H5 page; -3. [http://127.0.0.1:8199/upload](http://127.0.0.1:8199/upload) interface for real form file uploading, supporting both single and multiple file uploads. +3. [http://127.0.0.1:8199/upload](http://127.0.0.1:8199/upload) API for real form file uploading, supporting both single and multiple file uploads. Visit [http://127.0.0.1:8199/upload/show](http://127.0.0.1:8199/upload/show) to choose a single file to upload. After submitting, you can see that the file has been successfully uploaded to the server. diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient.md" index 7124ff86829..93504c92f85 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/HTTPClient/HTTPClient.md" @@ -19,7 +19,7 @@ The `GoFrame` framework offers a powerful and easy-to-use `HTTP` client, impleme 2. The client provides a series of methods named after `HTTP Methods`. Invoking these methods will initiate the corresponding `HTTP Method` requests. The commonly used methods are `Get` and `Post`, while `DoRequest` is the core request method that users can call to implement custom `HTTP Method` requests. 3. The result of the request is a `*ClientResponse` object. You can obtain the corresponding return results through this object. The `ReadAll`/`ReadAllString` methods can be used to obtain the returned content. After use, this object needs to be closed through the `Close` method to prevent memory overflow. 4. The `*Bytes` method is used to obtain the binary data returned by the server. If the request fails, it returns `nil`; the `*Content` method is used to request string result data. If the request fails, it returns an empty string; the `Set*` method is for setting parameters of the `Client`. -5. The `*Var` method directly requests and retrieves HTTP interface results as a generic type for easy conversion. If the request fails or the request result is empty, an empty `g.Var` generic object is returned, which does not affect the invocation of conversion methods. +5. The `*Var` method directly requests and retrieves HTTP API results as a generic type for easy conversion. If the request fails or the request result is empty, an empty `g.Var` generic object is returned, which does not affect the invocation of conversion methods. 6. As can be seen, the data parameter `data` for the client's request parameters is of the `interface{}` type, meaning any data type can be passed. Common parameter data types are `string`/`map`. If the parameter is of `map` type, the parameter value will be automatically `urlencode` encoded. :::warning diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session-Storage\346\216\245\345\217\243\345\274\200\345\217\221.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session-Storage\346\216\245\345\217\243\345\274\200\345\217\221.md" index f757ce615f7..6f127d054c6 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session-Storage\346\216\245\345\217\243\345\274\200\345\217\221.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session-Storage\346\216\245\345\217\243\345\274\200\345\217\221.md" @@ -1,20 +1,20 @@ --- slug: '/docs/web/session-storage' -title: 'Session-Storage Interface Development' +title: 'Session-Storage API Development' sidebar_position: 4 hide_title: true -keywords: [GoFrame, GoFrame Framework, gsession, Session-Storage, custom storage, interface development, Storage interface, TTL, gmap, session management] -description: "Developing Session-Storage interfaces using the gsession component in the GoFrame framework. The built-in Storage implementation within the component can meet the needs of most business scenarios. Developers can also customize session storage according to specific cases. The article describes in detail the definition of the Storage interface and its invocation timing. To improve session performance, it is recommended to use the gmap container type. This guide will help developers better implement and optimize storage interfaces." +keywords: [GoFrame, GoFrame Framework, gsession, Session-Storage, custom storage, API development, Storage API, TTL, gmap, session management] +description: "Developing Session-Storage APIs using the gsession component in the GoFrame framework. The built-in Storage implementation within the component can meet the needs of most business scenarios. Developers can also customize session storage according to specific cases. The article describes in detail the definition of the Storage API and its invocation timing. To improve session performance, it is recommended to use the gmap container type. This guide will help developers better implement and optimize storage APIs." --- -In most scenarios, the common `Storage` implementations provided by the built-in `gsession` component are sufficient to meet requirements. If there are special scenarios that require the customization of `Storage`, it is certainly supported, as the functionality of `gsession` is designed with interfaces in mind. +In most scenarios, the common `Storage` implementations provided by the built-in `gsession` component are sufficient to meet requirements. If there are special scenarios that require the customization of `Storage`, it is certainly supported, as the functionality of `gsession` is designed with APIs in mind. ## Storage Definition [https://github.com/gogf/gf/v2/blob/master/os/gsession/gsession_storage.go](https://github.com/gogf/gf/v2/blob/master/os/gsession/gsession_storage.go) ```go -// Storage is the interface definition for session storage. +// Storage is the API definition for session storage. type Storage interface { // New creates a custom session id. // This function can be used for custom session creation. @@ -68,5 +68,5 @@ The timing of each method's invocation is explained in detail within the comment ## Considerations -- In the `Storage` interface, not all interface methods need to be implemented. Developers only need to implement some interfaces according to the specific invocation timing required by their business needs. -- To enhance the execution performance of `Session`, the interface uses the `gmap.StrAnyMap` container type. During development, you can refer to this section: [Dictionary Type - gmap](../../组件列表/数据结构/字典类型-gmap/字典类型-gmap.md) \ No newline at end of file +- In the `Storage` API, not all API methods need to be implemented. Developers only need to implement some APIs according to the specific invocation timing required by their business needs. +- To enhance the execution performance of `Session`, the API uses the `gmap.StrAnyMap` container type. During development, you can refer to this section: [Dictionary Type - gmap](../../组件列表/数据结构/字典类型-gmap/字典类型-gmap.md) \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session.md" index fefca7ea57d..a5343f2c86b 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/Session/Session.md" @@ -21,11 +21,11 @@ In addition, the `SessionId` in `ghttp.Server` is generated using the client's ` ## `gsession` Module -The management functionality of `Session` is implemented by the independent `gsession` module and is perfectly integrated into `ghttp.Server`. Since this module is decoupled and independent, it can be applied to more different scenarios, such as `TCP` communication, `gRPC` interface services, etc. The `gsession` module has three important objects/interfaces: +The management functionality of `Session` is implemented by the independent `gsession` module and is perfectly integrated into `ghttp.Server`. Since this module is decoupled and independent, it can be applied to more different scenarios, such as `TCP` communication, `gRPC` API services, etc. The `gsession` module has three important objects/APIs: 1. `gsession.Manager`: Manages `Session` objects, `Storage` persistence storage objects, and expiration time control. 2. `gsession.Session`: A single `Session` management object, used for CRUD operations on `Session` parameters and other data management operations. -3. `gsession.Storage`: This is an interface definition used for the persistent storage of `Session` objects, data writing/reading, and survival updates. Developers can implement customized persistent storage features based on this interface. For the interface definition, see: [https://github.com/gogf/gf/blob/master/os/gsession/gsession_storage.go](https://github.com/gogf/gf/blob/master/os/gsession/gsession_storage.go) +3. `gsession.Storage`: This is an API definition used for the persistent storage of `Session` objects, data writing/reading, and survival updates. Developers can implement customized persistent storage features based on this API. For the API definition, see: [https://github.com/gogf/gf/blob/master/os/gsession/gsession_storage.go](https://github.com/gogf/gf/blob/master/os/gsession/gsession_storage.go) ## Storage Implementations diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\345\274\202\345\270\270\345\244\204\347\220\206.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\345\274\202\345\270\270\345\244\204\347\220\206.md" index 7950b7df9d2..19ca8893ada 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\345\274\202\345\270\270\345\244\204\347\220\206.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\345\274\202\345\270\270\345\244\204\347\220\206.md" @@ -163,7 +163,7 @@ db error: sql is xxxxxxx ### Error Stack Information -If the thrown exception is an error object created via the `gerror` component, or an error object implementing the stack print interface, since the error object already contains complete stack information, the `WebServer` will directly return that error object and not automatically create a new error object. Let's look at an example. +If the thrown exception is an error object created via the `gerror` component, or an error object implementing the stack print API, since the error object already contains complete stack information, the `WebServer` will directly return that error object and not automatically create a new error object. Let's look at an example. ```go package main diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-OpenAPIv3.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-OpenAPIv3.md" index d445c8134de..a2b0b93c8c7 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-OpenAPIv3.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-OpenAPIv3.md" @@ -4,7 +4,7 @@ title: 'API Documentation - OpenAPIv3' sidebar_position: 0 hide_title: true keywords: [OpenAPIv3, GoFrame, API Documentation, Standard Routing, g.Meta, swagger, API, Framework, Metadata, Protocol] -description: "Use the OpenAPIv3 protocol in the GoFrame framework to standardize the generation of API documentation. By embedding the g.Meta metadata structure, you can automatically generate interface information with protocol tags. Additionally, the article shows how to customize extension tags and manually improve the API documentation." +description: "Use the OpenAPIv3 protocol in the GoFrame framework to standardize the generation of API documentation. By embedding the g.Meta metadata structure, you can automatically generate API information with protocol tags. Additionally, the article shows how to customize extension tags and manually improve the API documentation." --- :::tip The `OpenAPIv3` protocol is mainly used in standardized routing. Before reading the introduction to the API documentation protocol, please familiarize yourself with the standardized routing: [Routing Registration - Standard Routing](../路由管理/路由管理-路由注册/路由注册-规范路由/路由注册-规范路由.md) @@ -15,13 +15,13 @@ For a detailed introduction to the `OpenAPIv3` protocol, please refer to: [https ## II. `g.Meta` Metadata -Interface metadata information can be implemented by embedding the `g.Meta` structure in the input struct and using its attribute tags. +API metadata information can be implemented by embedding the `g.Meta` structure in the input struct and using its attribute tags. For an introduction to the metadata component, please refer to the section: [Metadata-gmeta](../../组件列表/实用工具/元数据-gmeta.md) ## III. Common Protocol Tags -The attribute tags in input and output structs fully support the `OpenAPIv3` protocol. Once the corresponding protocol tags are added, the generated `OpenAPIv3` interface information will automatically include the attribute. +The attribute tags in input and output structs fully support the `OpenAPIv3` protocol. Once the corresponding protocol tags are added, the generated `OpenAPIv3` information will automatically include the attribute. Most tag attributes are automatically generated by the `Server` component, and there are not many tags that developers need to set manually. @@ -31,22 +31,22 @@ Commonly used basic tags include: | Common OpenAPIv3 Tags | Description | Remarks | | --- | --- | --- | -| `path` | Combined with the prefix at registration to form the interface URI path | Used for `g.Meta` to mark interface metadata | -| `tags` | The tag to which the interface belongs for interface classification | Used for `g.Meta` to mark interface metadata | -| `method` | The request method for the interface: `GET/PUT/POST/DELETE...(case insensitive)` | Used for `g.Meta` to mark interface metadata | -| `deprecated` | Marks the interface as deprecated | Used for `g.Meta` to mark interface metadata | -| `summary` | Brief description of the interface/parameter | Abbreviation `sm` | -| `description` | Detailed description of the interface/parameter | Abbreviation `dc` | +| `path` | Combined with the prefix at registration to form the API URI path | Used for `g.Meta` to mark API metadata | +| `tags` | The tag to which the API belongs for API classification | Used for `g.Meta` to mark API metadata | +| `method` | The request method for the API: `GET/PUT/POST/DELETE...(case insensitive)` | Used for `g.Meta` to mark API metadata | +| `deprecated` | Marks the API as deprecated | Used for `g.Meta` to mark API metadata | +| `summary` | Brief description of the API/parameter | Abbreviation `sm` | +| `description` | Detailed description of the API/parameter | Abbreviation `dc` | | `in` | Parameter submission method | `header/path/query/cookie` | | `default` | Default value for the parameter | Abbreviation `d` | -| `mime` | The `MIME` type of the interface, such as `multipart/form-data`, generally set globally, defaults to `application/json`. | Used for `g.Meta` to mark interface metadata | +| `mime` | The `MIME` type of the API, such as `multipart/form-data`, generally set globally, defaults to `application/json`. | Used for `g.Meta` to mark API metadata | | `type` | The type of the parameter, generally not needed, special parameters may require manual setting, such as `file` | Only applicable to parameter attributes | :::tip For more tags, please refer to the standard `OpenAPIv3` protocol: [https://swagger.io/specification/](https://swagger.io/specification/) ::: ### 2. Extension Tags -In the `OpenAPI` specification, all tags prefixed with `x-` are customizable extension tags by developers. Extension tags can be defined in any interface or attribute using `Golang struct tag` format, and during the generation of interface documentation, they will be returned as independent fields. For example: +In the `OpenAPI` specification, all tags prefixed with `x-` are customizable extension tags by developers. Extension tags can be defined in any API or attribute using `Golang struct tag` format, and during the generation of API documentation, they will be returned as independent fields. For example: ```go package main @@ -85,7 +85,7 @@ func main() { } ``` -After execution, visit the address [http://127.0.0.1:8199/swagger](http://127.0.0.1:8199/swagger) to view the `swagger ui`, and visit [http://127.0.0.1:8199/api.json](http://127.0.0.1:8199/api.json) to view the corresponding `OpenAPIv3` interface documentation. The generated `OpenAPIv3` interface documentation is as follows: +After execution, visit the address [http://127.0.0.1:8199/swagger](http://127.0.0.1:8199/swagger) to view the `swagger ui`, and visit [http://127.0.0.1:8199/api.json](http://127.0.0.1:8199/api.json) to view the corresponding `OpenAPIv3` documentation. The generated `OpenAPIv3` documentation is as follows: ``` { @@ -181,12 +181,12 @@ After execution, visit the address [http://127.0.0.1:8199/swagger](http://127.0. } ``` -As you can see, the extension tags have been included in the interface documentation. +As you can see, the extension tags have been included in the API documentation. ## IV. Expanding `OpenAPIv3` Information -The core interface information has already been automatically generated. If developers want to further complete the interface information, they can obtain the `OpenAPIv3` struct object via `s.GetOpenApi()` and manually fill in the corresponding attribute content. Let's look at an example where we design a common data structure around each interface: +The core API information has already been automatically generated. If developers want to further complete the API information, they can obtain the `OpenAPIv3` struct object via `s.GetOpenApi()` and manually fill in the corresponding attribute content. Let's look at an example where we design a common data structure around each API: ![](/markdown/452372a121db73abd8c5027077b3026e.png) -From this, we can see that with the general `OpenAPIv3` object, we can customize its content and generate various other types of custom interface documentation based on it. \ No newline at end of file +From this, we can see that with the general `OpenAPIv3` object, we can customize its content and generate various other types of custom API documentation based on it. \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-\350\207\252\345\256\232\344\271\211UI.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-\350\207\252\345\256\232\344\271\211UI.md" index a8e2b16b5e5..08b9d1ed6fe 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-\350\207\252\345\256\232\344\271\211UI.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243-\350\207\252\345\256\232\344\271\211UI.md" @@ -11,7 +11,7 @@ description: "Use SwaggerUI in the GoFrame framework to customize the API docume The `OpenAPI` API documentation UI provided by default in `GoFrame`'s `Server` is the open-source `redoc` component, which does not support the `Try It Out` feature on the page. Many developers ask if it's possible to use the `SwaggerUI` page to display the `OpenAPI` API documentation. Some enterprises do not support connecting to certain external resources, so can the internal API documentation UI be replaced with resources accessible internally? -Anyone familiar with `OpenAPI` knows that it is merely a general interface definition specification, and the displayed API documentation UI can be easily replaced. Moreover, there are many such UI interfaces and platforms! Switching the API documentation UI page in `GoFrame Server`, or integrating the API documentation into a third-party documentation platform, is very simple! For details, see the example: [gf/example/httpserver/swagger-set-template/main.go](https://github.com/gogf/gf/blob/master/example/httpserver/swagger-set-template/main.go). +Anyone familiar with `OpenAPI` knows that it is merely a general API definition specification, and the displayed API documentation UI can be easily replaced. Moreover, there are many such UI APIs and platforms! Switching the API documentation UI page in `GoFrame Server`, or integrating the API documentation into a third-party documentation platform, is very simple! For details, see the example: [gf/example/httpserver/swagger-set-template/main.go](https://github.com/gogf/gf/blob/master/example/httpserver/swagger-set-template/main.go). ## Usage Example diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243.md" index e5c1d1f8631..7390b883b10 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\216\245\345\217\243\346\226\207\346\241\243/\346\216\245\345\217\243\346\226\207\346\241\243.md" @@ -4,7 +4,7 @@ title: 'API Document' sidebar_position: 2 hide_title: true keywords: [GoFrame, GoFrame Framework, API Document, Automation, OpenAPIv3, API Documentation Generation, Routing Features, Framework Specifications, Code Synchronization, Documentation Maintenance] -description: "The feature of generating automated API documentation using the GoFrame framework. The GoFrame framework supports generating API documentation in a standardized manner through the OpenAPIv3 protocol, ensuring that the code and documentation are updated synchronously. It is recommended that users familiarize themselves with the framework's standard routing features before using this functionality to better manage routing and interface registration." +description: "The feature of generating automated API documentation using the GoFrame framework. The GoFrame framework supports generating API documentation in a standardized manner through the OpenAPIv3 protocol, ensuring that the code and documentation are updated synchronously. It is recommended that users familiarize themselves with the framework's standard routing features before using this functionality to better manage routing and API registration." --- ## Basic Introduction diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\225\260\346\215\256\350\277\224\345\233\236/\346\225\260\346\215\256\350\277\224\345\233\236.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\225\260\346\215\256\350\277\224\345\233\236/\346\225\260\346\215\256\350\277\224\345\233\236.md" index e4208e7f531..a3f6af05929 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\225\260\346\215\256\350\277\224\345\233\236/\346\225\260\346\215\256\350\277\224\345\233\236.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\225\260\346\215\256\350\277\224\345\233\236/\346\225\260\346\215\256\350\277\224\345\233\236.md" @@ -10,9 +10,9 @@ description: "In the GoFrame framework, the HTTP Server's data return processing ## Basic Introduction -The data return of the `HTTP Server` is implemented through the `ghttp.Response` object, which implements the standard library's `http.ResponseWriter` interface. Data output is achieved using the `Write*` related methods, and the data output utilizes a `Buffer` mechanism, thus the processing efficiency of the data is relatively high. At any time, you can output buffered data to the client and clear buffer data through the `OutputBuffer` method. +The data return of the `HTTP Server` is implemented through the `ghttp.Response` object, which implements the standard library's `http.ResponseWriter` API. Data output is achieved using the `Write*` related methods, and the data output utilizes a `Buffer` mechanism, thus the processing efficiency of the data is relatively high. At any time, you can output buffered data to the client and clear buffer data through the `OutputBuffer` method. -Common methods: For a more detailed list of interfaces, please refer to [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response) +Common methods: For a more detailed list of APIs, please refer to [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response) ```go func (r *Response) Write(content ...interface{}) @@ -46,7 +46,7 @@ Brief Explanation: 4. The `WriteStatus*` methods are used to set the status code for the current request execution return. 5. The `WriteJson*`/ `WriteXml` methods are used for specific data format output, providing a convenient method for developers. 6. The `WriteTpl*` methods are used for template output, parsing and outputting template files, or parsing and outputting the given template content directly. -7. For other methods, see the interface documentation; +7. For other methods, see the API documentation; Additionally, it is worth mentioning that `Header` operations can be implemented using standard library methods, for example: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\351\205\215\347\275\256/\346\234\215\345\212\241\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266\346\250\241\346\235\277.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\351\205\215\347\275\256/\346\234\215\345\212\241\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266\346\250\241\346\235\277.md" index f6a004fde07..6a0fcb4120b 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\351\205\215\347\275\256/\346\234\215\345\212\241\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266\346\250\241\346\235\277.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\351\205\215\347\275\256/\346\234\215\345\212\241\351\205\215\347\275\256-\351\205\215\347\275\256\346\226\207\344\273\266\346\250\241\346\235\277.md" @@ -25,8 +25,8 @@ server: keepAlive: true # Whether to enable Keep-Alive. Default is true serverAgent: "GoFrame HTTP Server" # Server agent information. Default is "GoFrame HTTP Server" - # Interface Documentation - openapiPath: "/api.json" # OpenAPI interface document address + # API Documentation + openapiPath: "/api.json" # OpenAPI API document address swaggerPath: "/swagger" # Built-in SwaggerUI display address # Static Service Configuration diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-Context.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-Context.md" index ea9392e1242..1f7de890fba 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-Context.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-Context.md" @@ -3,13 +3,13 @@ slug: '/docs/web/request-context' title: 'Request Input-Context' sidebar_position: 6 hide_title: true -keywords: [GoFrame, GoFrame framework, request context, Context object, context variable, middleware, routing service, module method, context.Context interface, Golang] +keywords: [GoFrame, GoFrame framework, request context, Context object, context variable, middleware, routing service, module method, context.Context API, Golang] description: "Using the Context object in the GoFrame framework to handle context variable sharing in the request process. By providing necessary methods, developers can set custom variables at the beginning of a request and access them during subsequent processing. Additionally, this article includes example code and detailed steps on integrating third-party components to enhance functionality." --- ## Basic Introduction -In request processes, some custom set variables are often shared in the context, such as setting some variables through middleware before the request starts, which can then be accessed in the routing service method for corresponding processing. This requirement is very common. In the `GoFrame` framework, we recommend using the `Context` context object to handle context variables shared in the process, even passing this object further into various dependent module methods. The `Context` object type implements the standard library's `context.Context` interface, which is often used as the first parameter of module inter-call methods, and this interface parameter is also the recommended way by `Golang` official to pass context variables between modules. +In request processes, some custom set variables are often shared in the context, such as setting some variables through middleware before the request starts, which can then be accessed in the routing service method for corresponding processing. This requirement is very common. In the `GoFrame` framework, we recommend using the `Context` context object to handle context variables shared in the process, even passing this object further into various dependent module methods. The `Context` object type implements the standard library's `context.Context` API, which is often used as the first parameter of module inter-call methods, and this API parameter is also the recommended way by `Golang` official to pass context variables between modules. **Method List:** diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-\350\257\267\346\261\202\346\240\241\351\252\214.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-\350\257\267\346\261\202\346\240\241\351\252\214.md" index 59569127085..24bc4b57f4d 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-\350\257\267\346\261\202\346\240\241\351\252\214.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245-\350\257\267\346\261\202\346\240\241\351\252\214.md" @@ -4,7 +4,7 @@ title: 'Request Input - Request Validation' sidebar_position: 2 hide_title: true keywords: [GoFrame, Request Validation, GoFrame Framework, gvalid, Struct Validation, Route Registration, Request Parameters, Error Handling, Register Request, Data Validation] -description: "In the GoFrame framework, request input validation is implemented for struct attributes through the v tag. In the example, we explain how to use the gvalid module for validation, how to set and parse the registered request data structure, and how to handle validation errors. We also demonstrate how to test interface responses and error messages using curl. Additionally, we provide usage suggestions for different versions to improve user experience and code usability." +description: "In the GoFrame framework, request input validation is implemented for struct attributes through the v tag. In the example, we explain how to use the gvalid module for validation, how to set and parse the registered request data structure, and how to handle validation errors. We also demonstrate how to test API responses and error messages using curl. Additionally, we provide usage suggestions for different versions to improve user experience and code usability." --- The `Request` object offers excellent request validation capabilities by binding the `v` tag to struct attributes. Since the underlying validation functionality is achieved through the `gvalid` module, for more detailed validation rules and introduction, please refer to the [Data Validation - Struct Validation](../../%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6/%E6%95%B0%E6%8D%AE%E6%A0%A1%E9%AA%8C/%E6%95%B0%E6%8D%AE%E6%A0%A1%E9%AA%8C-%E5%8F%82%E6%95%B0%E7%B1%BB%E5%9E%8B/%E6%95%B0%E6%8D%AE%E6%A0%A1%E9%AA%8C-Struct%E6%A0%A1%E9%AA%8C/Struct%E6%A0%A1%E9%AA%8C-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8.md) section. @@ -59,7 +59,7 @@ func main() { } ``` -In this example, we define two structs: `RegisterReq` for receiving parameters and `RegisterRes` for returning data. Since the interface returns a `JSON` data structure, you can see that only the returned struct has the `json` tag, while the receiving struct only has the `p` tag. This is because `RegisterReq` is only used for receiving parameters and does not need to set the returned `json` tag. +In this example, we define two structs: `RegisterReq` for receiving parameters and `RegisterRes` for returning data. Since the API returns a `JSON` data structure, you can see that only the returned struct has the `json` tag, while the receiving struct only has the `p` tag. This is because `RegisterReq` is only used for receiving parameters and does not need to set the returned `json` tag. :::tip The `p` tag is optional; by default, property name matching and conversion are performed under the **ignore special characters and case-insensitive** rules, meeting most business scenarios' needs by default. ::: @@ -82,7 +82,7 @@ $ curl "http://127.0.0.1:8199/register" :::tip In the latest version, only the first error is returned. ::: -As shown in the above example, when a request validation error occurs, all validation failure errors are returned, which may not be very user-friendly. When an error occurs, we can convert the validation error into a `gvalid.Error` interface object and then control the error return flexibly. +As shown in the above example, when a request validation error occurs, all validation failure errors are returned, which may not be very user-friendly. When an error occurs, we can convert the validation error into a `gvalid.Error` API object and then control the error return flexibly. ```go package main diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245.md" index 3bd67232746..8a1dd42db2c 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\257\267\346\261\202\350\276\223\345\205\245/\350\257\267\346\261\202\350\276\223\345\205\245.md" @@ -160,7 +160,7 @@ func main() { } ``` -The original intention of the server-side interface design is to define a route parameter `path` and receive it through the `Path` attribute of the `API` object. +The original intention of the server-side API design is to define a route parameter `path` and receive it through the `Path` attribute of the `API` object. Client-side: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\344\275\277\347\224\250\347\244\272\344\276\213.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\344\275\277\347\224\250\347\244\272\344\276\213.md" index 09b4d631265..93c2ab29c88 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\344\275\277\347\224\250\347\244\272\344\276\213.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\344\275\277\347\224\250\347\244\272\344\276\213.md" @@ -178,7 +178,7 @@ We can see that only the service method of the `/admin/dashboard` route is bound ## Unified Error Handling -Based on middleware, we can perform some posterior judgments after the service function has been executed, especially for unified data format return, result processing, error judgment, etc. These requirements can be implemented using posterior middleware types. We use a simple example to demonstrate how to use middleware to do posterior judgment processing for all interface requests, serving as an inspiration. +Based on middleware, we can perform some posterior judgments after the service function has been executed, especially for unified data format return, result processing, error judgment, etc. These requirements can be implemented using posterior middleware types. We use a simple example to demonstrate how to use middleware to do posterior judgment processing for all API requests, serving as an inspiration. ```go package main diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\345\237\272\346\234\254\344\273\213\347\273\215.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\345\237\272\346\234\254\344\273\213\347\273\215.md" index f09a3b7dbad..81f6c1cb9ec 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\345\237\272\346\234\254\344\273\213\347\273\215.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250/\344\270\255\351\227\264\344\273\266\346\213\246\346\210\252\345\231\250-\345\237\272\346\234\254\344\273\213\347\273\215.md" @@ -54,7 +54,7 @@ func Middleware(r *ghttp.Request) { ## Middleware Registration -There are multiple ways to register middleware, refer to the interface documentation: [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp) +There are multiple ways to register middleware, refer to the API documentation: [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp) ### Global Middleware diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\345\257\271\350\261\241\346\263\250\345\206\214.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\345\257\271\350\261\241\346\263\250\345\206\214.md" index 936fcdfed33..2f03affba8a 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\345\257\271\350\261\241\346\263\250\345\206\214.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\345\257\271\350\261\241\346\263\250\345\206\214.md" @@ -26,7 +26,7 @@ func(r *ghttp.Request) Otherwise, registration cannot be completed, and there will be an error prompt during route registration, such as: ``` -panic: interface conversion: interface {} is xxx, not func(*ghttp.Request) +panic: API conversion: interface {} is xxx, not func(*ghttp.Request) ``` ## Object Registering - `BindObject` @@ -366,7 +366,7 @@ The `Init` and `Shut` methods in objects are special methods that are automatica 1. `Init` Callback Method -A method for initialization when the object receives a request, which is called back before the service interface is invoked. +A method for initialization when the object receives a request, which is called back before the service API is invoked. Method definition: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\246\202\344\275\225\344\275\277\347\224\250.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\246\202\344\275\225\344\275\277\347\224\250.md" index c8f0d6be11c..42dfceab66c 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\246\202\344\275\225\344\275\277\347\224\250.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\246\202\344\275\225\344\275\277\347\224\250.md" @@ -19,10 +19,10 @@ Among them, both the input and output parameters are two, and they are all requi | Parameter | Description | Note | | --- | --- | --- | -| `ctx context.Context` | Context | The `Server` component will automatically fetch and pass it to the interface method from the request. | -| `req *Request` | Request Object | Even if no parameters are received, it must be defined because the request structure not only contains the request parameter definition but also the request definition of the interface. | -| `res *Response` | Response Object | Even if there are no return parameters, it must be defined because the return structure not only contains the return parameter definition but also can include the interface return definition. | -| `err error` | Error Object | `Server` uses this parameter to determine whether the interface execution is successful or failed. | +| `ctx context.Context` | Context | The `Server` component will automatically fetch and pass it to the API method from the request. | +| `req *Request` | Request Object | Even if no parameters are received, it must be defined because the request structure not only contains the request parameter definition but also the request definition of the API. | +| `res *Response` | Response Object | Even if there are no return parameters, it must be defined because the return structure not only contains the return parameter definition but also can include the API return definition. | +| `err error` | Error Object | `Server` uses this parameter to determine whether the API execution is successful or failed. | ## Unified Router Registration @@ -45,9 +45,9 @@ s.BindHandler("/user/{uid}", func(ctx context.Context, req *SaveReq) (res *SaveR ## Standardized Parameter Structure -In normalized router registration, the definition of the request/response parameter structure is very important. This structure not only contains the input parameter definition but also includes the interface definition, especially information such as routing address, request method, and interface description. Maintaining parameter structures in a structured data approach facilitates richer interface capability expansion, team interface interaction, long-term interface maintenance, and automated interface documentation generation. +In normalized router registration, the definition of the request/response parameter structure is very important. This structure not only contains the input parameter definition but also includes the API definition, especially information such as routing address, request method, and API description. Maintaining parameter structures in a structured data approach facilitates richer API capability expansion, team API interaction, long-term API maintenance, and automated API documentation generation. -To ensure naming normalization, input data structures are named in the `XxxReq` way, and output data structures are named in the `XxxRes` way. Even when input or output parameters are null, the corresponding data structures need to be defined for future expansion and interface information management. For a description of the tags involved in `OpenAPIv3` in the structure, please refer to the subsequent chapters. +To ensure naming normalization, input data structures are named in the `XxxReq` way, and output data structures are named in the `XxxRes` way. Even when input or output parameters are null, the corresponding data structures need to be defined for future expansion and API information management. For a description of the tags involved in `OpenAPIv3` in the structure, please refer to the subsequent chapters. :::tip Request parameters are automatically converted to request data structures, and field mapping conversions are case insensitive and will automatically ignore special characters. ::: @@ -55,13 +55,13 @@ Request parameters are automatically converted to request data structures, and f ## Input Data Validation -The request structure will be automatically validated before being executed by the `API` interface. If one of the rule validations fails, the subsequent validations will be terminated (using the `bail` validation modification rule automatically). The validation function uses the unified validation component of the framework, please refer to: [Data Validation](../../../../核心组件/数据校验/数据校验.md) +The request structure will be automatically validated before being executed by the `API` API. If one of the rule validations fails, the subsequent validations will be terminated (using the `bail` validation modification rule automatically). The validation function uses the unified validation component of the framework, please refer to: [Data Validation](../../../../核心组件/数据校验/数据校验.md) :::warning Special attention should be paid: if there are multiple validation rules for parameter validation and there is a `required*` rule in the rules, it is recommended to place the `required*` validation rule before all rules. Otherwise, the feature of the `bail` validation rule enabled in the built-in standardized router (terminate further validation upon failure) may cause subsequent `required*` rules to be ineffective. ::: ## Unified Return Middleware -The data return processing for the interface requires setting up a **unified post-middleware**, and you can also use the data return middleware provided by `Server` by default. When developers customize middleware, they can refer to the middleware `MiddlewareHandlerResponse` provided by `Server`. +The data return processing for the API requires setting up a **unified post-middleware**, and you can also use the data return middleware provided by `Server` by default. When developers customize middleware, they can refer to the middleware `MiddlewareHandlerResponse` provided by `Server`. By the way, here is an important method when customizing the return middleware: @@ -76,7 +76,7 @@ When executing via the post-middleware, use the `GetHandlerResponse` method of t ### `OpenAPIv3` Protocol -The interface documentation automatically generated by the `Server` component uses the latest `OpenAPIv3` protocol. For more details, please refer to the chapter: [Interface Documentation](../../../接口文档/接口文档.md) +The API documentation automatically generated by the `Server` component uses the latest `OpenAPIv3` protocol. For more details, please refer to the chapter: [API Documentation](../../../接口文档/接口文档.md) ### `Request` Object in `Ctx` diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\270\270\350\247\201\351\227\256\351\242\230.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\270\270\350\247\201\351\227\256\351\242\230.md" index f90fe3b567a..9da2e66ad3c 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\270\270\350\247\201\351\227\256\351\242\230.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\247\204\350\214\203\350\267\257\347\224\261-\345\270\270\350\247\201\351\227\256\351\242\230.md" @@ -3,18 +3,18 @@ slug: '/docs/web/router-registering-strict-router-faq' title: 'Strict Routing - FAQ' sidebar_position: 2 hide_title: true -keywords: [GoFrame,GoFrame Framework,Strict Routing,HTTP Method,RESTful Interface,API Design,User Interface,CRUD operations,Meta Tags,Response Structure] -description: "How to support multiple HTTP Method submissions for the same interface under the strict routing of the GoFrame framework. When designing RESTful interfaces, each API should correspond to a specific HTTP Method, such as creating a user or retrieving a user list, etc. If multiple HTTP Methods need to be supported for an interface, it can be set through Meta tags. Additionally, learn how to use type aliasing to return array forms for the Data field in the Response structure." +keywords: [GoFrame,GoFrame Framework,Strict Routing,HTTP Method,RESTful API,API Design,User API,CRUD operations,Meta Tags,Response Structure] +description: "How to support multiple HTTP Method submissions for the same API under the strict routing of the GoFrame framework. When designing RESTful APIs, each API should correspond to a specific HTTP Method, such as creating a user or retrieving a user list, etc. If multiple HTTP Methods need to be supported for an API, it can be set through Meta tags. Additionally, learn how to use type aliasing to return array forms for the Data field in the Response structure." --- -## How to support multiple `HTTP Method` submissions for the same interface under strict routing +## How to support multiple `HTTP Method` submissions for the same API under strict routing -First, an interface should only perform one function. `HTTP Method` is meaningful (for example, in `RESTful` interface design). An interface supporting multiple `HTTP Method` types is usually a sign of poor interface design, and it's recommended to review the interface design. +First, an API should only perform one function. `HTTP Method` is meaningful (for example, in `RESTful` API design). An API supporting multiple `HTTP Method` types is usually a sign of poor API design, and it's recommended to review the API design. -Generally, there is no scenario where an `API` needs to be associated with multiple `HTTP Methods`. For example, for user interfaces, a `CRUD` interface in RESTful implementation should have `4-5` API definitions, each implementing different business logic. Therefore, there might be the following API definitions for a `RESTful` interface: +Generally, there is no scenario where an `API` needs to be associated with multiple `HTTP Methods`. For example, for user APIs, a `CRUD` API in RESTful implementation should have `4-5` API definitions, each implementing different business logic. Therefore, there might be the following API definitions for a `RESTful` API: ``` -Interface Name Method Path +API Name Method Path Create User PUT /user User List GET /user User Details GET /user/{uid} @@ -22,7 +22,7 @@ Modify User POST /user/{uid} Delete User DELETE /user/{uid} ``` -If indeed there is a scenario where an interface needs to support multiple `HTTP Methods`, it can be done by using a comma `,` to separate each `HTTP Method` in the `method` attribute of the `Meta` tag, for example: +If indeed there is a scenario where an API needs to support multiple `HTTP Methods`, it can be done by using a comma `,` to separate each `HTTP Method` in the `method` attribute of the `Meta` tag, for example: ```go type SaveReq struct { diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261.md" index 9ed89de59c4..9de3c8667b3 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261/\350\267\257\347\224\261\346\263\250\345\206\214-\350\247\204\350\214\203\350\267\257\347\224\261.md" @@ -3,8 +3,8 @@ slug: '/docs/web/router-registering-strict-router' title: 'Router Registration - Specified Router' sidebar_position: 3 hide_title: true -keywords: [GoFrame, GoFrame Framework, Router Registration, Specified Router, API Design, Interface Documentation, OpenAPIv3, SwaggerUI, HTTP Server, Team Collaboration] -description: "Standardized router registration method of GoFrame framework, suitable for complex projects and team collaboration. Supported from version v2.0, covering features like structured API design, parameter style definition, automatic generation and synchronized maintenance of interface documents, etc." +keywords: [GoFrame, GoFrame Framework, Router Registration, Specified Router, API Design, API Documentation, OpenAPIv3, SwaggerUI, HTTP Server, Team Collaboration] +description: "Standardized router registration method of GoFrame framework, suitable for complex projects and team collaboration. Supported from version v2.0, covering features like structured API design, parameter style definition, automatic generation and synchronized maintenance of API documents, etc." --- ## Basic Introduction @@ -12,15 +12,15 @@ description: "Standardized router registration method of GoFrame framework, suit Starting from version `v2.0`, the `Server` component of the framework provides an additional standardized router registration method, which is more suitable for scenarios that require team standardization and projects with higher business complexity. The specified router implements the following features: - Standardization of `API` design according to structured programming -- Specification of `API` interface method parameter style definitions +- Specification of `API` API method parameter style definitions - Simplified router registration and maintenance -- Unified interface return data format design -- Ensures synchronized maintenance of code and interface documentation +- Unified API return data format design +- Ensures synchronized maintenance of code and API documentation - Automatic reception and validation of `API` parameter objects -- Automatic generation of interface documentation based on the standard `OpenAPIv3` protocol +- Automatic generation of API documentation based on the standard `OpenAPIv3` protocol - Automatic generation of `SwaggerUI` pages :::tip -Please note that **specified router** along with the original **function, object, group** routing methods are all registration methods supported by the framework's `HTTP Server` component. They are designed to solve scenarios of standardized and automated interface management and are more suitable for multi-person team collaboration. Other routing methods, especially the function and object registration methods of the framework's `v1` version, are also supported in the new version! Choose reasonably based on personal usage habits. +Please note that **specified router** along with the original **function, object, group** routing methods are all registration methods supported by the framework's `HTTP Server` component. They are designed to solve scenarios of standardized and automated API management and are more suitable for multi-person team collaboration. Other routing methods, especially the function and object registration methods of the framework's `v1` version, are also supported in the new version! Choose reasonably based on personal usage habits. ::: ## Related Documentation diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214.md" index a0541f14c64..c8070bc859a 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\346\263\250\345\206\214.md" @@ -3,17 +3,17 @@ slug: '/docs/web/router-registering' title: 'Route Management - Route Registration' sidebar_position: 1 hide_title: true -keywords: [GoFrame,GoFrame框架,Route Management,Route Registration,WebServer,ghttp,Route Patterns,Interface Functionality,Standardized Routing,goframe] -description: "How to perform route registration and management in the GoFrame framework. The WebServer provides multiple route registration modes through the ghttp package and offers powerful interface functionality. Especially since version 2 of the framework, the feature of standardized routing has been added to enhance the engineering capabilities of projects and adapt to complex business scenarios. It is recommended that developers use standardized routing in complex business environments." +keywords: [GoFrame,GoFrame框架,Route Management,Route Registration,WebServer,ghttp,Route Patterns,API Functionality,Standardized Routing,goframe] +description: "How to perform route registration and management in the GoFrame framework. The WebServer provides multiple route registration modes through the ghttp package and offers powerful API functionality. Especially since version 2 of the framework, the feature of standardized routing has been added to enhance the engineering capabilities of projects and adapt to complex business scenarios. It is recommended that developers use standardized routing in complex business environments." --- ## Basic Introduction -`WebServer` requires the support of methods/objects to provide services. The `ghttp` package supports multiple route registration modes, providing developers with very powerful and flexible interface functionality. +`WebServer` requires the support of methods/objects to provide services. The `ghttp` package supports multiple route registration modes, providing developers with very powerful and flexible API functionality. Route registration is the most core part of the entire `WebServer` and one of the most carefully designed modules in the `goframe` framework. -Interface documentation: [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp) +API documentation: [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp) ## Considerations diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\350\247\204\345\210\231.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\350\247\204\345\210\231.md" index 03776987968..4a2de06eaa5 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\350\247\204\345\210\231.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\350\267\257\347\224\261\347\256\241\347\220\206/\350\267\257\347\224\261\347\256\241\347\220\206-\350\267\257\347\224\261\350\247\204\345\210\231.md" @@ -153,7 +153,7 @@ You can also use the `ghttp.Request.Get` method to retrieve matched routing para #### Named Matching Rules -Uses the `:name` method for matching (`name` is a custom match name) and performs a named match for parameters at a specified level of the `URI` (similar to regular `([^/]+)`, this `URI` level must have a value). The corresponding matched parameters will be parsed into `Router` parameters and passed to the registered service interface for use. +Uses the `:name` method for matching (`name` is a custom match name) and performs a named match for parameters at a specified level of the `URI` (similar to regular `([^/]+)`, this `URI` level must have a value). The corresponding matched parameters will be parsed into `Router` parameters and passed to the registered service API for use. Matching example 1: @@ -192,7 +192,7 @@ rule: /:name/:action #### Fuzzy Matching Rules -Uses the `*any` method for matching (`any` is a custom match name) for fuzzy matching of parameters after the specified position of the `URI` (similar to regular `(.*)`, this `URI` level can be empty), and parses matched parameters into `Router` parameters to be passed to the registered service interface for use. +Uses the `*any` method for matching (`any` is a custom match name) for fuzzy matching of parameters after the specified position of the `URI` (similar to regular `(.*)`, this `URI` level can be empty), and parses matched parameters into `Router` parameters to be passed to the registered service API for use. Matching example 1: @@ -232,7 +232,7 @@ rule: /src/*path/show #### Field Matching Rules -Uses the `{field}` method for matching (`field` is a custom match name), which can perform segment matches of parameters at **any position** in the `URI` (similar to regular `([\w\.\-]+)`, this `URI` level must have a value and multiple field matches can occur at the same level), and parses matched parameters into `Router` parameters to be passed to the registered service interface for use. +Uses the `{field}` method for matching (`field` is a custom match name), which can perform segment matches of parameters at **any position** in the `URI` (similar to regular `([\w\.\-]+)`, this `URI` level must have a value and multiple field matches can occur at the same level), and parses matched parameters into `Router` parameters to be passed to the registered service API for use. Matching example 1: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CORS\350\267\250\345\237\237\345\244\204\347\220\206.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CORS\350\267\250\345\237\237\345\244\204\347\220\206.md" index a5c555cfc7c..38005dc5e2f 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CORS\350\267\250\345\237\237\345\244\204\347\220\206.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CORS\350\267\250\345\237\237\345\244\204\347\220\206.md" @@ -7,7 +7,7 @@ keywords: [CORS, Cross-Domain Requests, GoFrame, Middleware, AJAX, Origin, CORSO description: "Handling CORS cross-domain requests using the GoFrame framework, setting cross-domain rules with routing management and middleware, allowing WebSocket cross-domain access. Provides CORS object and its configuration parameters, including default and restricted Origin settings. Additionally, it demonstrates basic usage methods, authorizing cross-domain Origin, and custom detection methods to achieve more flexible cross-domain request management." --- -Allowing cross-domain access to interfaces often requires using it in conjunction with [Routing Management - Middleware/Interceptors](../%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86/%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86-%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8/%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8-%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%BB%8D.md) to uniformly set which interface under certain routing rules can be accessed cross-domain. This method is also used to allow cross-domain access for `WebSocket` requests. +Allowing cross-domain access to APIs often requires using it in conjunction with [Routing Management - Middleware/Interceptors](../%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86/%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86-%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8/%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8-%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%BB%8D.md) to uniformly set which API under certain routing rules can be accessed cross-domain. This method is also used to allow cross-domain access for `WebSocket` requests. Related methods: [https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response](https://pkg.go.dev/github.com/gogf/gf/v2/net/ghttp#Response) @@ -42,7 +42,7 @@ For specific parameter introductions, please refer to the W3 organization [offic #### Default `CORSOptions` -For ease of cross-domain settings, the `ghttp` module also provides default cross-domain request options, available through the `DefaultCORSOptions` method. In most cases, we can directly use `CORSDefault()` to allow cross-domain access for interfaces that need to allow cross-domain requests (generally using middleware). +For ease of cross-domain settings, the `ghttp` module also provides default cross-domain request options, available through the `DefaultCORSOptions` method. In most cases, we can directly use `CORSDefault()` to allow cross-domain access for APIs that need to allow cross-domain requests (generally using middleware). #### Restricting `Origin` Sources @@ -64,7 +64,7 @@ Some clients and certain browsers will send an `OPTIONS` preflight request befor ### Example 1, Basic Usage -Let's look at a simple interface example: +Let's look at a simple API example: ```go package main @@ -88,7 +88,7 @@ func main() { } ``` -The interface address is [http://localhost/api.v1/order](http://localhost/api.v1/order), and of course, this interface does not allow cross-domain access. We open a different domain, for example, the Baidu homepage (which uses `jQuery`, convenient for debugging), then press `F12` to open the developer panel and execute the following `AJAX` request under `console`: +The API address is [http://localhost/api.v1/order](http://localhost/api.v1/order), and of course, this API does not allow cross-domain access. We open a different domain, for example, the Baidu homepage (which uses `jQuery`, convenient for debugging), then press `F12` to open the developer panel and execute the following `AJAX` request under `console`: ``` $.get("http://localhost:8199/api.v1/order", function(result){ @@ -100,7 +100,7 @@ The result is as follows: ![](/markdown/06b316cb2a487071cf4be67a3481dac3.png) -It returned an error indicating that cross-domain requests are not allowed. Next, we modify the server-side interface test code as follows: +It returned an error indicating that cross-domain requests are not allowed. Next, we modify the server-side API test code as follows: ```go package main @@ -130,7 +130,7 @@ func main() { } ``` -We added the pre-middleware `MiddlewareCORS` for the route `/api.v1`, which will be called before all services are executed. By calling the `CORSDefault` method, we use the default cross-domain settings to allow cross-domain requests. The bound event routing rule uses a fuzzy matching rule, indicating that all interface addresses starting with `/api.v1` allow cross-domain requests. +We added the pre-middleware `MiddlewareCORS` for the route `/api.v1`, which will be called before all services are executed. By calling the `CORSDefault` method, we use the default cross-domain settings to allow cross-domain requests. The bound event routing rule uses a fuzzy matching rule, indicating that all API addresses starting with `/api.v1` allow cross-domain requests. Returning to the Baidu homepage, executing the `AJAX` request again, this time it succeeds: @@ -174,7 +174,7 @@ func main() { ### Example 3, Custom Detection and Authorization -I wonder if you noticed a detail in the above examples: even if the current interface does not allow cross-domain access, once the interface is called, the complete logic of the interface will still be executed, and a full request process will have occurred on the server. To address this issue, we can customize the authorization `Origin` and use the `CORSAllowedOrigin` method in middleware to determine whether the current request `Origin` is allowed by the server to execute. Only then will the subsequent process be executed; otherwise, execution will be terminated. +I wonder if you noticed a detail in the above examples: even if the current API does not allow cross-domain access, once the API is called, the complete logic of the API will still be executed, and a full request process will have occurred on the server. To address this issue, we can customize the authorization `Origin` and use the `CORSAllowedOrigin` method in middleware to determine whether the current request `Origin` is allowed by the server to execute. Only then will the subsequent process be executed; otherwise, execution will be terminated. In the following example, only cross-domain requests from the `goframe.org` domain are allowed, while requests from other domains will fail and return `403`: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CSRF\351\230\262\345\276\241\350\256\276\347\275\256.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CSRF\351\230\262\345\276\241\350\256\276\347\275\256.md" index 2677e5ea9ea..c30698b6816 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CSRF\351\230\262\345\276\241\350\256\276\347\275\256.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/CSRF\351\230\262\345\276\241\350\256\276\347\275\256.md" @@ -13,7 +13,7 @@ description: "Explains how to protect web application security through CSRF defe Here, we choose to validate requests using `token` through middleware, with the `CSRF` cross-site defense plugin provided by the community package. -Developers can add middleware to the interface to include `token` verification functionality. +Developers can add middleware to the API to include `token` verification functionality. Interested parties can read the plugin source code at [https://github.com/gogf/csrf](https://github.com/gogf/csrf). @@ -25,7 +25,7 @@ Interested parties can read the plugin source code at [https://github.com/gogf/c import "github.com/gogf/csrf" ``` -### Configure Interface Middleware +### Configure API Middleware The `csrf` plugin supports custom `csrf.Config` configuration. In `Config`, `Cookie.Name` is the name of the `token` set by the middleware in the returned `Cookie`, `ExpireTime` is the timeout for the `token`, `TokenLength` is the `token` length, and `TokenRequestKey` is the name of the parameter required to be included in subsequent requests. diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/HOOK\344\272\213\344\273\266\345\233\236\350\260\203.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/HOOK\344\272\213\344\273\266\345\233\236\350\260\203.md" index 3177e8fce85..714ea16a837 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/HOOK\344\272\213\344\273\266\345\233\236\350\260\203.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/HOOK\344\272\213\344\273\266\345\233\236\350\260\203.md" @@ -4,7 +4,7 @@ title: 'HOOK Event Callback' sidebar_position: 6 hide_title: true keywords: [GoFrame, GoFrame Framework, HOOK Event, Event Callback, ghttp.Server, Middleware, Routing Priority, Permission Control, Cross-Origin Requests, API Authentication] -description: "The HOOK event callback function provided by the ghttp.Server in the GoFrame framework, similar to middleware, allows custom event listening and handling. Event callbacks can be registered in a specific order to determine the callback invocation priority. This document provides a detailed explanation of the usage, application in interface authentication control, cross-origin request handling, and showcases with example code the execution method and priority mechanism of event callbacks." +description: "The HOOK event callback function provided by the ghttp.Server in the GoFrame framework, similar to middleware, allows custom event listening and handling. Event callbacks can be registered in a specific order to determine the callback invocation priority. This document provides a detailed explanation of the usage, application in API authentication control, cross-origin request handling, and showcases with example code the execution method and priority mechanism of event callbacks." --- ![](/markdown/25a101c86afb67b0c4f69162657c7853.png) @@ -67,11 +67,11 @@ Although registering multiple identical `HOOK` callback functions can also fulfi When the route matches multiple `HOOK` methods, by default, `HOOK` methods are executed according to the priority of route matching. When calling the `Request.ExitHook` method within a `HOOK` method, subsequent `HOOK` methods will not be executed, which acts similar to `HOOK` function overriding. -## Interface Authentication Control +## API Authentication Control -A common application of event callback registration is to control authentication/permissions for the called interface. This requires binding the `ghttp.HookBeforeServe` event, where all matched interface requests are processed before service execution (e.g., binding `/*` event callback route). If authentication fails, call `r.ExitAll()` to exit subsequent service execution (including subsequent event callback execution). +A common application of event callback registration is to control authentication/permissions for the called API. This requires binding the `ghttp.HookBeforeServe` event, where all matched API requests are processed before service execution (e.g., binding `/*` event callback route). If authentication fails, call `r.ExitAll()` to exit subsequent service execution (including subsequent event callback execution). -Furthermore, executing `r.Redirect*` in the event callback function for permission verification without calling `r.ExitAll()` to exit the business execution often results in `http multiple response writeheader calls` error messages. This is because the `r.Redirect*` method writes the `Location` header in the header, and subsequent business service interfaces often write the `Content-Type`/`Content-Length` headers, causing a conflict. +Furthermore, executing `r.Redirect*` in the event callback function for permission verification without calling `r.ExitAll()` to exit the business execution often results in `http multiple response writeheader calls` error messages. This is because the `r.Redirect*` method writes the `Location` header in the header, and subsequent business service APIs often write the `Content-Type`/`Content-Length` headers, causing a conflict. ## Middleware vs. Event Callback @@ -85,11 +85,11 @@ Middleware (`Middleware`) and Event Callback (`HOOK`) are two major process cont `Request.Router` is the matched route object containing route registration information, which is typically not used by developers. `Request.URL` is the underlying URL object from the standard library `http.Request`, containing the request URL address information, especially `Request.URL.Path` representing the requested URI address. -Therefore, if used in a service callback function, `Request.Router` has a value because it will call the service callback method only when the route is matched. However, in an event callback function, this object may be `nil` (indicating no matched service callback function route). Especially when using event callback for request interface authentication, use the `Request.URL` object to obtain the request URL information instead of `Request.Router`. +Therefore, if used in a service callback function, `Request.Router` has a value because it will call the service callback method only when the route is matched. However, in an event callback function, this object may be `nil` (indicating no matched service callback function route). Especially when using event callback for request API authentication, use the `Request.URL` object to obtain the request URL information instead of `Request.Router`. ## Static File Events :::tip -If you are only providing API interface services (including front static file service proxies like `nginx`), which do not involve static file services, you can ignore this section. +If you are only providing API API services (including front static file service proxies like `nginx`), which do not involve static file services, you can ignore this section. ::: Note that event callbacks can also match static file accesses that meet routing rules ([Static Files](静态文件服务.md) feature is disabled by default in the `gf` framework, and we can manually enable it using `WebServer` related configuration. See [Service Configuration](../服务配置/服务配置.md) for details). @@ -287,7 +287,7 @@ priority service In the chapters [Route Management - Middleware/Interceptor](../%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86/%E8%B7%AF%E7%94%B1%E7%AE%A1%E7%90%86-%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8/%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%8B%A6%E6%88%AA%E5%99%A8-%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%BB%8D.md) and [CORS Cross-Origin Handling](CORS跨域处理.md), examples of cross-origin handling have also been introduced. In most cases, we use middleware to achieve cross-origin request handling. -Both `HOOK` and middleware can implement cross-origin request handling. Here, we'll use HOOK to achieve simple cross-origin processing. First, let's look at a simple interface example: +Both `HOOK` and middleware can implement cross-origin request handling. Here, we'll use HOOK to achieve simple cross-origin processing. First, let's look at a simple API example: ```go package main @@ -311,7 +311,7 @@ func main() { } ``` -The interface address is [http://localhost:8199/api.v1/order](http://localhost:8199/api.v1/order), and this interface is not allowed for cross-origin. Open a different domain name, such as the Baidu homepage (conveniently using `jQuery` for debugging), and press `F12` to open the developer panel, and execute the following `AJAX` request in `console`: +The API address is [http://localhost:8199/api.v1/order](http://localhost:8199/api.v1/order), and this API is not allowed for cross-origin. Open a different domain name, such as the Baidu homepage (conveniently using `jQuery` for debugging), and press `F12` to open the developer panel, and execute the following `AJAX` request in `console`: ``` $.get("http://localhost:8199/api.v1/order", function(result){ @@ -350,7 +350,7 @@ func main() { } ``` -We added a bound event `ghttp.HookBeforeServe` for the route `/api.v1/*any`. This event will be called before all service executions. In this event's callback method, we allow cross-origin requests by calling the `CORSDefault` method with default cross-origin settings. The bound event route rule uses a vague match rule, indicating that all interface addresses starting with `/api.v1` allow cross-origin requests. +We added a bound event `ghttp.HookBeforeServe` for the route `/api.v1/*any`. This event will be called before all service executions. In this event's callback method, we allow cross-origin requests by calling the `CORSDefault` method with default cross-origin settings. The bound event route rule uses a vague match rule, indicating that all API addresses starting with `/api.v1` allow cross-origin requests. Return to the Baidu homepage and execute the `AJAX` request again; this time, it is successful: diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/PProf\346\234\215\345\212\241\346\200\247\350\203\275\345\210\206\346\236\220.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/PProf\346\234\215\345\212\241\346\200\247\350\203\275\345\210\206\346\236\220.md" index 681ad4dc529..02e27bea6d3 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/PProf\346\234\215\345\212\241\346\200\247\350\203\275\345\210\206\346\236\220.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/PProf\346\234\215\345\212\241\346\200\247\350\203\275\345\210\206\346\236\220.md" @@ -140,7 +140,7 @@ curl http://127.0.0.1:8199/debug/pprof/profile > pprof.profile go tool pprof -http :8080 pprof.profile ``` -After approximately `30` seconds of interface data collection by the `pprof` tool (during which time the `WebServer` should have incoming traffic), a performance analysis report is generated. You can then view the report results using `top10`/`web` and other `pprof` commands. For more commands, use `go tool pprof`. For detailed usage of `pprof`, please refer to Golang's official documentation: [blog.golang.org/profiling-go-programs](https://blog.golang.org/profiling-go-programs) +After approximately `30` seconds of API data collection by the `pprof` tool (during which time the `WebServer` should have incoming traffic), a performance analysis report is generated. You can then view the report results using `top10`/`web` and other `pprof` commands. For more commands, use `go tool pprof`. For detailed usage of `pprof`, please refer to Golang's official documentation: [blog.golang.org/profiling-go-programs](https://blog.golang.org/profiling-go-programs) ### CPU Performance Analysis @@ -153,7 +153,7 @@ Serving web UI on http://localhost:8080 :::tip To display `pprof` graphically, the `Graphviz` graphical tool needs to be installed. For my current system, `Ubuntu`, install by executing `sudo apt-get install graphviz` (for `MacOS`, use `brew install Graphviz`). ::: -After running, it will open the following graphical interface using the default browser, displaying the CPU cost path captured during this period: +After running, it will open the following graphical API using the default browser, displaying the CPU cost path captured during this period: ![](/markdown/56387af30ed4e111df652c5918f36313.png) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/WebSocket\346\234\215\345\212\241.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/WebSocket\346\234\215\345\212\241.md" index 76538afb9d7..8cba3ad9dbd 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/WebSocket\346\234\215\345\212\241.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/WebSocket\346\234\215\345\212\241.md" @@ -115,8 +115,8 @@ Note that the server connection address here is: `ws://127.0.0.1:8199/ws`. The client's functionality is quite simple, mainly implementing these features: - Maintaining the connection status with the server's `websocket` and information display; -- Inputting content in the interface and sending information to the `websocket` server; -- Echoing the returned information from the `websocket` on the interface; +- Inputting content in the API and sending information to the `websocket` server; +- Echoing the returned information from the `websocket` on the API; ## WebSocket Server @@ -162,11 +162,11 @@ As you can see, the server code is quite simple. Here are a few points worth not 1. **WebSocket Method** -The route registration method for a `websocket` server is the same as that for a regular `http` callback function. However, in handling the interface, we need to convert the request into a `websocket` operation using the `ghttp.Request.WebSocket` method (using the pointer object `r.WebSocket()`) and return a `WebSocket object`, which is used for subsequent `websocket` communication operations. Of course, if the client's request is not a `websocket` operation, the conversion will fail. The method will return an error message, so please note to check the `error` return value when using this method. +The route registration method for a `websocket` server is the same as that for a regular `http` callback function. However, in handling the API, we need to convert the request into a `websocket` operation using the `ghttp.Request.WebSocket` method (using the pointer object `r.WebSocket()`) and return a `WebSocket object`, which is used for subsequent `websocket` communication operations. Of course, if the client's request is not a `websocket` operation, the conversion will fail. The method will return an error message, so please note to check the `error` return value when using this method. 1. **ReadMessage & WriteMessage** -Reading and writing messages correspond to the data reading and writing operations of `websocket` (`ReadMessage & WriteMessage`). It's important to note that both of these methods have a `msgType` variable that indicates the type of data to be read and written. The two common data types are: string data or binary data. During usage, since both sides of the interface will agree on a unified data format, the `msgType` for reading and writing is almost always the same. Therefore, in this example, when returning a message, the data type parameter directly uses the read `msgType`. +Reading and writing messages correspond to the data reading and writing operations of `websocket` (`ReadMessage & WriteMessage`). It's important to note that both of these methods have a `msgType` variable that indicates the type of data to be read and written. The two common data types are: string data or binary data. During usage, since both sides of the API will agree on a unified data format, the `msgType` for reading and writing is almost always the same. Therefore, in this example, when returning a message, the data type parameter directly uses the read `msgType`. ## HTTPS WebSocket diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\345\271\263\346\273\221\351\207\215\345\220\257\347\211\271\346\200\247.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\345\271\263\346\273\221\351\207\215\345\220\257\347\211\271\346\200\247.md" index 994a3aa1466..6ec63dc88ef 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\345\271\263\346\273\221\351\207\215\345\220\257\347\211\271\346\200\247.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\345\271\263\346\273\221\351\207\215\345\220\257\347\211\271\346\200\247.md" @@ -9,7 +9,7 @@ description: "Enable and manage smooth restart features while using the GoFrame `Smooth restart` (`hot reload`) means the `WebServer` can restart without interrupting existing request execution. This feature is especially useful during different project version releases. For instance, when needing to release two versions: `A` and `B`, during the execution of `A`, we can directly overwrite `A`'s program with `B` and use the smooth restart feature (using `Web` or `command line`) to seamlessly transition requests to the new version of the service. -The `GoFrame` framework supports very convenient `web management features`, which means we can directly manage `Server` restart/shutdown operations through a web page/interface. Additionally, the framework also supports `Server` restart/shutdown operations through `command line terminal commands` (limited to `*nix` systems). +The `GoFrame` framework supports very convenient `web management features`, which means we can directly manage `Server` restart/shutdown operations through a web page/API. Additionally, the framework also supports `Server` restart/shutdown operations through `command line terminal commands` (limited to `*nix` systems). ## Feature Activation @@ -55,9 +55,9 @@ The `Restart` parameter can specify the custom executable file path for restart ### EnableAdmin -- Firstly, this method provides users with a convenient page and interface for managing the `Server`, which is very convenient for managing a single `Server`. By directly accessing and clicking the corresponding links on the management page, operations can be performed. It is important to note that, due to the management features, if used in production environments, it is recommended to customize the management address to a private address. -- Additionally, the `restart` interface provided by `EnableAdmin` also supports custom executable file paths, directly passing the `newExeFilePath` variable to the restart interface through GET parameters, e.g., [http://127.0.0.1/debug/admin/restart?newExeFilePath=xxxxxxx](http://127.0.0.1/debug/admin/restart?newExeFilePath=xxxxxxx) -- Furthermore, in most cases, `Server` often has more than 1 node, so in most service management operations, such as restart operations, it is not directly accessing the `admin` page of each `Server` to manually execute the restart operation. Instead, it fully utilizes the functional interfaces provided by the `admin` page to achieve unified `Server` management control through interface control. +- Firstly, this method provides users with a convenient page and API for managing the `Server`, which is very convenient for managing a single `Server`. By directly accessing and clicking the corresponding links on the management page, operations can be performed. It is important to note that, due to the management features, if used in production environments, it is recommended to customize the management address to a private address. +- Additionally, the `restart` API provided by `EnableAdmin` also supports custom executable file paths, directly passing the `newExeFilePath` variable to the restart API through GET parameters, e.g., [http://127.0.0.1/debug/admin/restart?newExeFilePath=xxxxxxx](http://127.0.0.1/debug/admin/restart?newExeFilePath=xxxxxxx) +- Furthermore, in most cases, `Server` often has more than 1 node, so in most service management operations, such as restart operations, it is not directly accessing the `admin` page of each `Server` to manually execute the restart operation. Instead, it fully utilizes the functional APIs provided by the `admin` page to achieve unified `Server` management control through API control. ### Example 1: Basic Usage diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\350\207\252\345\256\232\344\271\211\347\212\266\346\200\201\347\240\201\345\244\204\347\220\206.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\350\207\252\345\256\232\344\271\211\347\212\266\346\200\201\347\240\201\345\244\204\347\220\206.md" index c1bb6471865..01e0de17bd0 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\350\207\252\345\256\232\344\271\211\347\212\266\346\200\201\347\240\201\345\244\204\347\220\206.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/WEB\346\234\215\345\212\241\345\274\200\345\217\221/\351\253\230\347\272\247\347\211\271\346\200\247/\350\207\252\345\256\232\344\271\211\347\212\266\346\200\201\347\240\201\345\244\204\347\220\206.md" @@ -93,7 +93,7 @@ func main() { } ``` -As we can see, we can use the `BindStatusHandlerByMap` method for batch settings of custom status codes. After the example program is executed, when the service interface returns status codes `403/404/500`, the interface will return the corresponding status code number. +As we can see, we can use the `BindStatusHandlerByMap` method for batch settings of custom status codes. After the example program is executed, when the service API returns status codes `403/404/500`, the API will return the corresponding status code number. ## Precautions diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\216\245\345\217\243\350\247\204\350\214\203-gen ctrl.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\216\245\345\217\243\350\247\204\350\214\203-gen ctrl.md" index ece04949610..1be36b711f4 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\216\245\345\217\243\350\247\204\350\214\203-gen ctrl.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\216\245\345\217\243\350\247\204\350\214\203-gen ctrl.md" @@ -34,7 +34,7 @@ When developing a project, it often starts with designing the `API` interface ba One of the purposes of this command is to standardize `api` code writing, which requires some important norms to be understood (otherwise the code cannot be generated): -- `api` layer's interface definition file path needs to satisfy `/api/module/version/definition_file.go`, for example: `/api/user/v1/user.go`, `/api/user/v1/user_delete.go`, etc. +- `api` layer's API definition file path needs to satisfy `/api/module/version/definition_file.go`, for example: `/api/user/v1/user.go`, `/api/user/v1/user_delete.go`, etc. - **Module** refers to the division of `API` modules, which can be split according to different **business attributes** for easier aggregation and maintenance. Modules can also be considered as specific business resources. - **Version** is usually defined as `v1`/`v2`, etc., for compatibility version control of `API`. Different versions are marked by different version numbers when compatibility updates occur. The first version is managed with `v1` by default. - **Definition file** refers to the `API` input and output definition files, where each `API` is usually maintained independently in a separate `go` file. Of course, it also supports putting multiple `APIs` in one `go` file for unified maintenance. @@ -47,7 +47,7 @@ Below is a `Hello` interface example in the project template: ### Suggested Naming -We provide some suggested naming conventions for common interface definitions for your reference: +We provide some suggested naming conventions for common API definitions for your reference: | Operation Name | Suggested Naming | Notes | | --- | --- | --- | @@ -59,11 +59,11 @@ We provide some suggested naming conventions for common interface definitions fo ## Command Usage -This command analyzes the code within the specified `api` interface definition directory and automatically generates the corresponding controller/`SDK Go` code files. +This command analyzes the code within the specified `api` API definition directory and automatically generates the corresponding controller/`SDK Go` code files. ### Manual Mode -To manually execute the command line, run `gf gen ctrl` in the project's root directory. It will completely scan the `api` interface definition directory and generate corresponding code. +To manually execute the command line, run `gf gen ctrl` in the project's root directory. It will completely scan the `api` API definition directory and generate corresponding code. ```text $ gf gen ctrl -h @@ -92,7 +92,7 @@ Parameter explanation: | Name | Required | Default Value | Meaning | | --- | --- | --- | --- | -| `srcFolder` | No | `api` | Points to the directory address of `api` interface definition files | +| `srcFolder` | No | `api` | Points to the directory address of `api` API definition files | | `dstFolder` | No | `internal/controller` | Points to the directory where the generated controller files are stored | | `watchFile` | No | | Used in IDE file monitoring, for automatic generation when files change | | `sdkPath` | No | | If `HTTP SDK` needs to be generated, this parameter specifies the directory path for storing generated SDK code | @@ -109,7 +109,7 @@ If using `GolandIDE`, the provided configuration file, [watchers.xml](gen-ctrl-w ## Usage Example -### Automatically generated interface definition files +### Automatically generated API definition files ![](/markdown/636aedc34da9bad1f84545dcfbeb38e6.png) @@ -138,13 +138,13 @@ For small or personal simple projects, or projects with only a few interfaces in - Finally, the `controller` layer code has its own responsibilities: - Validate input parameters: Client-submitted parameters are not trusted and usually require data validation in most scenarios. - Implement the interface logic: Either directly implement the interface logic in the `controller` or call one or more `service` interfaces or third-party service interfaces to implement the logic. Avoid implementing `api` interface logic in `service` layers as `api` interfaces are tied to specific business scenarios and are not reusable. 💀 **A common mistake is directly passing the request through the `controller` to the `service` interface, making the `controller` seemingly redundant and the `service` layer's implementation more cumbersome and non-reusable.** 💀 - - Generate return data: Organize internal result data and generate the returning data interface definition. + - Generate return data: Organize internal result data and generate the returning data API definition. - These responsibilities imply that `controller` code is also relatively complex. Maintaining them separately can alleviate developer mental burden and facilitate clear maintenance of `api` interface logic. **Some Suggestions**: -If there are too many interface files in an `api` module, consider further splitting complex `api` modules into sub-modules. This can decouple complex `api` modules, and maintaining `api` interface definitions and `controller` interface implementation files through multiple directories will make the structure clearer and facilitate better collaboration and version management. +If there are too many interface files in an `api` module, consider further splitting complex `api` modules into sub-modules. This can decouple complex `api` modules, and maintaining `api` API definitions and `controller` interface implementation files through multiple directories will make the structure clearer and facilitate better collaboration and version management. After reviewing the design, if you still prefer managing all interfaces using a single source file, consider the `merge` parameter. diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\236\232\344\270\276\347\273\264\346\212\244-gen enums.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\236\232\344\270\276\347\273\264\346\212\244-gen enums.md" index e85d553b455..fe8658c9c16 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\236\232\344\270\276\347\273\264\346\212\244-gen enums.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\236\232\344\270\276\347\273\264\346\212\244-gen enums.md" @@ -20,7 +20,7 @@ This command is used to analyze the source code in the specified code directory - The issue of not displaying the optional items of enum values in the `API` documentation. - The difficulty in maintaining enum values in the `API` documentation, and the issue of code and documentation being maintained separately. This reduces the collaboration efficiency with the caller, especially between frontend and backend. -> For example, in the following interface definition, tasks have multiple states which are enum values. It's costly for the backend to maintain and easy to miss states maintenance, causing incomplete state enum values. +> For example, in the following API definition, tasks have multiple states which are enum values. It's costly for the backend to maintain and easy to miss states maintenance, causing incomplete state enum values. ![](/markdown/3e2d58612c094dcf26ed2f17371ae482.png) @@ -28,7 +28,7 @@ This command is used to analyze the source code in the specified code directory The tool parses source code and generates enum values into the startup package `Go` file, automatically loading enum values when the service runs, reducing manual maintenance costs and avoiding omitted enum value maintenance. -> For example, in the following interface definition, using the tool to maintain enum values improves development efficiency. +> For example, in the following API definition, using the tool to maintain enum values improves development efficiency. ![](/markdown/4f5b0d82a3fa65b8c83fcd3f93a8c02a.png) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\250\241\345\235\227\350\247\204\350\214\203-gen service.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\250\241\345\235\227\350\247\204\350\214\203-gen service.md" index b3b6f90f8f7..9c250cd9359 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\250\241\345\235\227\350\247\204\350\214\203-gen service.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\274\200\345\217\221\345\267\245\345\205\267/\344\273\243\347\240\201\347\224\237\346\210\220-gen/\346\250\241\345\235\227\350\247\204\350\214\203-gen service.md" @@ -3,8 +3,8 @@ slug: '/docs/cli/gen-service' title: 'Module Generating - gen service' sidebar_position: 2 hide_title: true -keywords: [GoFrame,Golang,Business Logic,Module Management,Interface Definition,Code Generation,Circular Dependencies,Service Registration,Compiler,Microservices] -description: "Encapsulate and manage business logic in the GoFrame framework by generating module interface definitions and registration code to simplify the implementation process of separating business logic from interfaces. Improve module transparency through structured coding of logic and interfaces while avoiding circular dependencies. Provides both manual and automated implementation modes suitable for different development environments." +keywords: [GoFrame,Golang,Business Logic,Module Management,API Definition,Code Generation,Circular Dependencies,Service Registration,Compiler,Microservices] +description: "Encapsulate and manage business logic in the GoFrame framework by generating module API definitions and registration code to simplify the implementation process of separating business logic from interfaces. Improve module transparency through structured coding of logic and interfaces while avoiding circular dependencies. Provides both manual and automated implementation modes suitable for different development environments." --- :::warning This feature is an **experimental feature**. It is recommended for developers to focus on module division under `logic`, streamline inter-module relationship, avoid circular dependencies, and fully utilize the circular dependency detection feature of the `Golang` compiler to write higher quality project code. @@ -19,18 +19,18 @@ This feature is available from version `v2.1`. In business project practices, business logic encapsulation is often the most complex part. Meanwhile, dependencies between business modules are very complex and boundaries are vague, making it difficult to use the `Golang` package management form. Effectively managing the encapsulation part of business logic in a project is a challenge that every project developed with `Golang` is bound to encounter. -In a standard software design process, dependencies between modules first clarify interface definitions, and then the implementation is done through code during the software development process. However, in most high-paced internet engineering, there isn't a rigorous software design process, and the quality level of developers varies. Most developers first focus on how to implement the functional logic corresponding to the requirements scenario to maximize development efficiency. +In a standard software design process, dependencies between modules first clarify API definitions, and then the implementation is done through code during the software development process. However, in most high-paced internet engineering, there isn't a rigorous software design process, and the quality level of developers varies. Most developers first focus on how to implement the functional logic corresponding to the requirements scenario to maximize development efficiency. ### Design Objectives -1. Provide a code management method that can directly generate module interface definitions and module registration code through specific module implementation. -2. Simplify the implementation of separating business logic and interfaces, reduce the repetitive operation of module methods and interface definitions, and enhance module transparency and ease of invocation between modules. +1. Provide a code management method that can directly generate module API definitions and module registration code through specific module implementation. +2. Simplify the implementation of separating business logic and interfaces, reduce the repetitive operation of module methods and API definitions, and enhance module transparency and ease of invocation between modules. ### Design Implementation 1. Add a `logic` category directory, migrate all business logic code to the `logic` category directory, and manage business modules in the form of package management. 2. Dependencies between business modules are decoupled through interfaces, and the original `service` category is adjusted to an interface directory. Each business module will maintain its own, being more flexible. -3. Based on certain coding specifications, `service` interface definition code can be generated from the `logic` business logic code. It also allows for manual maintenance of this part of the `service` interface. +3. Based on certain coding specifications, `service` API definition code can be generated from the `logic` business logic code. It also allows for manual maintenance of this part of the `service` interface. ## Things to Note :::warning @@ -96,7 +96,7 @@ Parameter Description: | `srcFolder` | Yes | `internal/logic` | Points to the logic code directory address | | `dstFolder` | Yes | `internal/service` | Points to the directory where the generated interface files are stored | | `dstFileNameCase` | No | `Snake` | The format of the generated filename | -| `stPattern` | No | `s([A-A]\w+)` | Use regular expression to specify the business module struct definition format for easy parsing of business interface definition names. Under the default regex, all structs starting with lowercase `s` followed by uppercase letters will be treated as business module interface names. For example: +| `stPattern` | No | `s([A-A]\w+)` | Use regular expression to specify the business module struct definition format for easy parsing of business API definition names. Under the default regex, all structs starting with lowercase `s` followed by uppercase letters will be treated as business module interface names. For example: | Logic Struct Name | Service Interface Name | | --- | --- | @@ -144,7 +144,7 @@ We recommend using the configuration file: [watchers.xml](gen-service-watchers.x ### Step3: Generate Interface and Service Registration Files -If you have done the configuration in `Step1`, you can ignore this step. Because when you write code, `service` will generate the interface definition file at the same time. +If you have done the configuration in `Step1`, you can ignore this step. Because when you write code, `service` will generate the API definition file at the same time. Otherwise, every time you finish developing/updating the `logic` business module, you need to manually execute the `gf gen service` command. @@ -174,13 +174,13 @@ Simply start `main.go`. ### When a structure in `logic` has nested types, methods for the nested types cannot be automatically generated -In such cases, it is recommended to manually maintain the `service` interface definitions and not use the automatic generation tool. The manually maintained interface definition files will not be overwritten by the tool, and both manual and automatic methods can be used together. +In such cases, it is recommended to manually maintain the `service` API definitions and not use the automatic generation tool. The manually maintained API definition files will not be overwritten by the tool, and both manual and automatic methods can be used together. ### Quickly Locate Specific Implementations of Interfaces **After adopting interface-based decoupling for project business modules, the experience is fantastic! But if I want to quickly find the specific implementations of specified interfaces during development and debugging, it's a bit challenging. Any guiding thoughts?** -\> Here, I recommend using `Goland IDE`, which has an excellent interface implementation locating feature, as shown in the figure. After finding the interface definition, click the small icon on the left to quickly locate the specific implementations. If Goland doesn't show the small icon, try upgrading to the latest version of `Goland`. +\> Here, I recommend using `Goland IDE`, which has an excellent interface implementation locating feature, as shown in the figure. After finding the API definition, click the small icon on the left to quickly locate the specific implementations. If Goland doesn't show the small icon, try upgrading to the latest version of `Goland`. ![](/markdown/bbcc72eb46954b60c49be42a8ecebe35.png) diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\276\256\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\346\263\250\345\206\214\345\217\221\347\216\260.md" "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\276\256\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\346\263\250\345\206\214\345\217\221\347\216\260.md" index d297b991371..078be8baadf 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\276\256\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\346\263\250\345\206\214\345\217\221\347\216\260.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/docs/\345\276\256\346\234\215\345\212\241\345\274\200\345\217\221/\346\234\215\345\212\241\346\263\250\345\206\214\345\217\221\347\216\260.md" @@ -9,7 +9,7 @@ keywords: [GoFrame framework, service registry, service discovery, microservice ## Basic Introduction -The `GoFrame` framework provides service registry and discovery components managed by the `gsvc` component, which primarily defines the interface for registry and discovery. The specific implementation is provided by community components: [https://github.com/gogf/gf/tree/master/contrib/registry](https://github.com/gogf/gf/tree/master/contrib/registry). Currently, community components offer multiple implementations for registry and discovery, such as `etcd, zookeeper, polaris`, etc. Developers can use them interchangeably as needed or implement their own registry and discovery components according to the interface definition of the `gsvc` component. +The `GoFrame` framework provides service registry and discovery components managed by the `gsvc` component, which primarily defines the interface for registry and discovery. The specific implementation is provided by community components: [https://github.com/gogf/gf/tree/master/contrib/registry](https://github.com/gogf/gf/tree/master/contrib/registry). Currently, community components offer multiple implementations for registry and discovery, such as `etcd, zookeeper, polaris`, etc. Developers can use them interchangeably as needed or implement their own registry and discovery components according to the API definition of the `gsvc` component. ## Component Activation diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step1 - \350\256\276\350\256\241\346\225\260\346\215\256\350\241\250.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step1 - \350\256\276\350\256\241\346\225\260\346\215\256\350\241\250.md" index 5ee6821ca53..c9a6dc3f268 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step1 - \350\256\276\350\256\241\346\225\260\346\215\256\350\241\250.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step1 - \350\256\276\350\256\241\346\225\260\346\215\256\350\241\250.md" @@ -37,7 +37,7 @@ docker run -d --name mysql \ After starting, connect to the database and apply the table creation `sql` statements: ```text $ mysql -h127.0.0.1 -p3306 -uroot -p -mysql: [Warning] Using a password on the command line interface can be insecure. +mysql: [Warning] Using a password on the command line API can be insecure. Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 57 diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step3 - \347\274\226\345\206\231api\346\216\245\345\217\243\345\256\232\344\271\211.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step3 - \347\274\226\345\206\231api\346\216\245\345\217\243\345\256\232\344\271\211.md" index 3df8b8c3613..777c0575046 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step3 - \347\274\226\345\206\231api\346\216\245\345\217\243\345\256\232\344\271\211.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step3 - \347\274\226\345\206\231api\346\216\245\345\217\243\345\256\232\344\271\211.md" @@ -25,8 +25,8 @@ type CreateRes struct { } ``` Brief Introduction: -- In API definitions, `g.Meta` is used to manage interface metadata information, which are defined as tags on the `g.Meta` property. These metadata include `path` (route address), `method` (request method), `tags` (interface group for generating interface documentation), and `summary` (interface description). These metadata are part of `OpenAPIv3`, which we won't go into detail here. For those interested, refer to the chapter: [Interface Documentation - OpenAPIv3](../../../docs/WEB服务开发/接口文档/接口文档-OpenAPIv3.md). -- The `Name` and `Age` attributes here are the parameter definitions for our interface. The `dc` tag is a shorthand for `description`, indicating the meaning of the parameter; the `v` tag is a shorthand for `valid`, indicating the validation rules for the parameter. We use three built-in validation rules here: +- In API definitions, `g.Meta` is used to manage API metadata information, which are defined as tags on the `g.Meta` property. These metadata include `path` (route address), `method` (request method), `tags` (API group for generating API documentation), and `summary` (API description). These metadata are part of `OpenAPIv3`, which we won't go into detail here. For those interested, refer to the chapter: [API Documentation - OpenAPIv3](../../../docs/WEB服务开发/接口文档/接口文档-OpenAPIv3.md). +- The `Name` and `Age` attributes here are the parameter definitions for our API. The `dc` tag is a shorthand for `description`, indicating the meaning of the parameter; the `v` tag is a shorthand for `valid`, indicating the validation rules for the parameter. We use three built-in validation rules here: - `required`: The parameter is mandatory. - `length`: Validates the parameter's length. - `between`: Validates the parameter's range. @@ -35,7 +35,7 @@ Brief Introduction: - Only the return parameter structures have `json` tags because the returned data usually needs to be converted to `json` format for use by the frontend, and parameter naming in `snake` style is more in line with frontend naming conventions. :::tip -In a `RESTful` style interface design, we typically use `POST` from the `HTTP Method` to denote write operations and `PUT` to denote update operations. +In a `RESTful` style API design, we typically use `POST` from the `HTTP Method` to denote write operations and `PUT` to denote update operations. ::: ## `Delete` @@ -76,7 +76,7 @@ type UpdateRes struct{} Here: - We define a user status type `Status`, using the conventional `enums` definition style in `Golang`. Just for understanding here. - The validation for the `Status` parameter uses the `in:0,1` rule, which checks that the passed `Status` value must be one of the two constants we defined, `StatusOK/StatusDisabled`, i.e., `0/1`. -- The interface parameters use pointers to avoid default type values affecting our update interface. For example, if `Status` is not defined as a pointer, it will be affected by the default value `0`. During processing logic, it's hard to determine whether the caller has passed the parameter and whether to actually change the value to `0`. By using pointers, when users don't pass the parameter, its default value is `nil`, making it easy to judge in processing logic. +- The API parameters use pointers to avoid default type values affecting our update API. For example, if `Status` is not defined as a pointer, it will be affected by the default value `0`. During processing logic, it's hard to determine whether the caller has passed the parameter and whether to actually change the value to `0`. By using pointers, when users don't pass the parameter, its default value is `nil`, making it easy to judge in processing logic. ## `GetOne` @@ -104,12 +104,12 @@ type GetListRes struct { List []*entity.User `json:"list" dc:"user list"` } ``` -This interface can query by `Age` and `Status`, returning multiple records `List []*entity.User`. +This API can query by `Age` and `Status`, returning multiple records `List []*entity.User`. ## Learning Summary Sample code for this chapter: https://github.com/gogf/quick-demo/blob/main/api/user/v1/user.go -As shown, defining `api` interfaces in the `GoFrame` framework's scaffolding project is quite elegant, with support for automatic data validation, metadata injection, flexible route configuration, and other practical features. This method of interface definition allows for the automatic generation of interface documentation, where the code serves as documentation, ensuring consistency between code and documentation. +As shown, defining `api` APIs in the `GoFrame` framework's scaffolding project is quite elegant, with support for automatic data validation, metadata injection, flexible route configuration, and other practical features. This method of API definition allows for the automatic generation of API documentation, where the code serves as documentation, ensuring consistency between code and documentation. Moreover, this is not the full charm of `GoFrame`, just a single petal on the rose. Next, we will use scaffold tools to automatically generate the corresponding `controller` control code for us. \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step4 - \347\224\237\346\210\220controller\344\273\243\347\240\201.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step4 - \347\224\237\346\210\220controller\344\273\243\347\240\201.md" index 5debb30cf68..5261842dabe 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step4 - \347\224\237\346\210\220controller\344\273\243\347\240\201.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step4 - \347\224\237\346\210\220controller\344\273\243\347\240\201.md" @@ -3,8 +3,8 @@ slug: '/quick/scaffold-api-controller' title: 'Step4 - Generate Controller' hide_title: true sidebar_position: 4 -keywords: [GoFrame, API Code Generation, Controller Code, Generate Controller, Code Auto Generation, Interface Implementation, GoFrame Framework, Route Object Management, Interface Route Implementation, Code Template] -description: "Generate controller code based on API definition, including API interface files, route object management, and route implementation code, using GoFrame framework's command tool to quickly generate relevant code templates, ensuring complete implementation of the interface, and demonstrating how to implement specific business logic through files." +keywords: [GoFrame, API Code Generation, Controller Code, Generate Controller, Code Auto Generation, API Implementation, GoFrame Framework, Route Object Management, API Route Implementation, Code Template] +description: "Generate controller code based on API definition, including API API files, route object management, and route implementation code, using GoFrame framework's command tool to quickly generate relevant code templates, ensuring complete implementation of the API, and demonstrating how to implement specific business logic through files." --- ## Generate Codes From API Definition @@ -24,13 +24,13 @@ generated: /Users/john/Temp/demo/internal/controller/user/user_v1_get_list.go done! ``` -![goframe api interface controller](QQ_1731678085194.png) +![goframe api API controller](QQ_1731678085194.png) The generated codes mainly include `3` types of files. -## Abstraction Interface For API +## Abstraction API For API -Defines the `api interface` to ensure the completeness of the controller's interface implementation, avoiding issues of missing interface implementations in `controller`. Since `GoFrame` is a rigorous development framework, it controls such details well. Whether or not this feature is used by developers can be decided based on specific scenarios and needs. +Defines the `api API` to ensure the completeness of the controller's API implementation, avoiding issues of missing API implementations in `controller`. Since `GoFrame` is a rigorous development framework, it controls such details well. Whether or not this feature is used by developers can be decided based on specific scenarios and needs. ```text /Users/john/Temp/demo/api/user/user.go @@ -101,12 +101,12 @@ func NewV1() user.IUserV1 { Both of these files will only be generated once, after which developers can freely modify and extend them. :::tip -If later we need to define a `v2` interface, the `make ctrl` command will similarly generate a `type ControllerV2 struct{}` structure definition and a `func NewV2() user.IUserV2` initialization method. +If later we need to define a `v2` API, the `make ctrl` command will similarly generate a `type ControllerV2 struct{}` structure definition and a `func NewV2() user.IUserV2` initialization method. ::: ## Controller Router Implementation -Used for the implementation code files of specific `api` interfaces. By default, codes are generated in the form of one source file per `api` interface. Of course, it is also possible to control the aggregation of interfaces defined in `api` files into a corresponding single source file. For specific command introductions and configurations, please refer to the chapter [Interface Specification-gen ctrl](../../../docs/开发工具/代码生成-gen/接口规范-gen%20ctrl.md). +Used for the implementation code files of specific `api` APIs. By default, codes are generated in the form of one source file per `api` API. Of course, it is also possible to control the aggregation of APIs defined in `api` files into a corresponding single source file. For specific command introductions and configurations, please refer to the chapter [API Specification-gen ctrl](../../../docs/开发工具/代码生成-gen/接口规范-gen%20ctrl.md). ```text generated: /Users/john/Temp/demo/internal/controller/user/user_v1_create.go @@ -134,7 +134,7 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C return nil, gerror.NewCode(gcode.CodeNotImplemented) } ``` -As we can see, this is just the implementation template for the create interface we defined. We just need to complete the specific business logic of this route function. +As we can see, this is just the implementation template for the create API we defined. We just need to complete the specific business logic of this route function. ## Learning Summary @@ -146,4 +146,4 @@ Yes, the goal of the `GoFrame` scaffolding tool is to allow developers to focus Such a development method is extremely convenient, not too comfortable! Do you think that’s all? Of course not, in the Quick Start chapter we only introduce some beginner-level features. When you delve deeper into her, you will discover more of her goodness and her understanding nature. -Next, we will complete the business logic implementation of the interface and feel the charm of the `GoFrame` database `ORM` component. \ No newline at end of file +Next, we will complete the business logic implementation of the API and feel the charm of the `GoFrame` database `ORM` component. \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step5 - \345\256\214\346\210\220\346\216\245\345\217\243\351\200\273\350\276\221\345\256\236\347\216\260.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step5 - \345\256\214\346\210\220\346\216\245\345\217\243\351\200\273\350\276\221\345\256\236\347\216\260.md" index 412daaad959..fd5451e38c3 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step5 - \345\256\214\346\210\220\346\216\245\345\217\243\351\200\273\350\276\221\345\256\236\347\216\260.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step5 - \345\256\214\346\210\220\346\216\245\345\217\243\351\200\273\350\276\221\345\256\236\347\216\260.md" @@ -104,7 +104,7 @@ func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.U return } ``` -The update interface is also straightforward. Besides the already introduced `WherePri` method, it also requires using the `Data` method to pass the data to be updated when updating the data. +The update API is also straightforward. Besides the already introduced `WherePri` method, it also requires using the `Data` method to pass the data to be updated when updating the data. ## `GetOne` @@ -124,7 +124,7 @@ func (c *ControllerV1) GetOne(ctx context.Context, req *v1.GetOneReq) (res *v1.G return } ``` -In the data retrieval interface, we use a `Scan` method, which can intelligently map the retrieved single data table record to a structure object. It should be noted that the `User` attribute object in `&res.User` is actually not initialized and its value is `nil`. If data is retrieved, the `Scan` method will initialize and assign it. If no data is retrieved, the `Scan` method will do nothing, and its value will remain `nil`. +In the data retrieval API, we use a `Scan` method, which can intelligently map the retrieved single data table record to a structure object. It should be noted that the `User` attribute object in `&res.User` is actually not initialized and its value is `nil`. If data is retrieved, the `Scan` method will initialize and assign it. If no data is retrieved, the `Scan` method will do nothing, and its value will remain `nil`. ## `GetList` diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step6 - \351\205\215\347\275\256\344\270\216\350\267\257\347\224\261.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step6 - \351\205\215\347\275\256\344\270\216\350\267\257\347\224\261.md" index 9b9a66553dd..3f3f7b670ef 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step6 - \351\205\215\347\275\256\344\270\216\350\267\257\347\224\261.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step6 - \351\205\215\347\275\256\344\270\216\350\267\257\347\224\261.md" @@ -9,7 +9,7 @@ description: "Introduce MySQL database driver, with steps for adding database co ## Import Database Driver -The `GoFrame` database component uses an interface-based design, separating interface and implementation to provide better abstraction and extensibility. Here, we use the `MySQL` database, so we need to import the specific `MySQL` driver implementation. We can add `_ "github.com/gogf/gf/contrib/drivers/mysql/v2"` in `main.go`. +The `GoFrame` database component uses an API-based design, separating API and implementation to provide better abstraction and extensibility. Here, we use the `MySQL` database, so we need to import the specific `MySQL` driver implementation. We can add `_ "github.com/gogf/gf/contrib/drivers/mysql/v2"` in `main.go`. Sample source code: https://github.com/gogf/quick-demo/blob/main/main.go @@ -90,7 +90,7 @@ In the `group.Bind` method of the grouped routes, you can add our route object t Sample source code: https://github.com/gogf/quick-demo/blob/main/internal/cmd/cmd.go -At this point, our interface development is complete. The next step is to start the service and perform some interface testing to see the effect. +At this point, our API development is complete. The next step is to start the service and perform some API testing to see the effect. ## Learning Summary @@ -98,10 +98,10 @@ When we use database functionality, we need to introduce the specific database d Route registration is very simple; just add a `controller` object to the group route registration through `group.Bind`. -So far, we have completed the development of the `CRUD` interface. 👏👏 We mainly focused on the following tasks: +So far, we have completed the development of the `CRUD` API. 👏👏 We mainly focused on the following tasks: - Database table design -- `API` interface definition -- Implementation of interface business logic +- `API` API definition +- Implementation of API business logic - Simple configuration and route registration Next, let's start the program to see the effect. \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step7 - \345\220\257\345\212\250\344\270\216\346\265\213\350\257\225.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step7 - \345\220\257\345\212\250\344\270\216\346\265\213\350\257\225.md" index 28e1c947c7b..b23748eca8d 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step7 - \345\220\257\345\212\250\344\270\216\346\265\213\350\257\225.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/Step7 - \345\220\257\345\212\250\344\270\216\346\265\213\350\257\225.md" @@ -4,7 +4,7 @@ title: 'Step7 - Run and Test' hide_title: true sidebar_position: 6 keywords: [GoFrame, start service, API documentation, API testing, RESTful API, CRUD, API validation, data query, data modification, data deletion] -description: "Start the service through the command line and generate API documentation using Swagger. Supports RESTful API interfaces for creating users, querying user information, modifying user data, and deleting users. Also supports API testing using the curl command, providing detailed validation rules and error codes to ensure data accuracy and reliability." +description: "Start the service through the command line and generate API documentation using Swagger. Supports RESTful API APIs for creating users, querying user information, modifying user data, and deleting users. Also supports API testing using the curl command, providing detailed validation rules and error codes to ensure data accuracy and reliability." --- ## Start the Service @@ -37,7 +37,7 @@ $ go run main.go ----------|--------|------------|-------------------------------------------------------|---------------------------------- ``` -As we can see, the `CRUD` interfaces we developed have been successfully registered on the `Web Server` and displayed correctly on the terminal. Meanwhile, we have enabled the API documentation feature, so let's look at the auto-generated API documentation. +As we can see, the `CRUD` APIs we developed have been successfully registered on the `Web Server` and displayed correctly on the terminal. Meanwhile, we have enabled the API documentation feature, so let's look at the auto-generated API documentation. ## API Documentation @@ -140,4 +140,4 @@ As we can see, the data has been successfully deleted. As we can see, using the scaffold tool of the `GoFrame` framework, we can efficiently and quickly complete API development work with the project template generated, and it can automatically generate API documentation for convenient frontend-backend collaboration. -With this, a `CRUD` interface project using the `GoFrame` framework has been quickly completed. However, the excellence of the `GoFrame` framework is far more than this; more features await your further exploration. \ No newline at end of file +With this, a `CRUD` API project using the `GoFrame` framework has been quickly completed. However, the excellence of the `GoFrame` framework is far more than this; more features await your further exploration. \ No newline at end of file diff --git "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/\346\216\245\345\217\243\345\274\200\345\217\221.md" "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/\346\216\245\345\217\243\345\274\200\345\217\221.md" index 844874e3341..235352d5638 100644 --- "a/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/\346\216\245\345\217\243\345\274\200\345\217\221.md" +++ "b/i18n/en/docusaurus-plugin-content-docs/current/quick/\351\241\271\347\233\256\350\204\232\346\211\213\346\236\266/\346\216\245\345\217\243\345\274\200\345\217\221/\346\216\245\345\217\243\345\274\200\345\217\221.md" @@ -3,11 +3,11 @@ slug: '/quick/scaffold-api' title: 'API Development Tutorial🌟' hide_title: true sidebar_position: 1 -keywords: [API Development, Golang, CURD Interface, GoFrame, GoFrame Framework, API Development, Scaffolding Tool, Quick Demo, Source Code Example, Go Development] -description: "Learn to use tools provided by the GoFrame framework to develop CURD interfaces, including the basic steps and techniques of API development. Complete example source code is provided for reference to help beginners quickly get started with interface development." +keywords: [API Development, Golang, CURD API, GoFrame, GoFrame Framework, API Development, Scaffolding Tool, Quick Demo, Source Code Example, Go Development] +description: "Learn to use tools provided by the GoFrame framework to develop CURD APIs, including the basic steps and techniques of API development. Complete example source code is provided for reference to help beginners quickly get started with API development." --- -In this chapter, we will learn the basic skills of a `Golang` engineer to develop `CURD` interfaces. Using the scaffolding tools provided by the `GoFrame` framework to develop `API` interfaces is very simple. Let's get started! +In this chapter, we will learn the basic skills of a `Golang` engineer to develop `CURD` APIs. Using the scaffolding tools provided by the `GoFrame` framework to develop `API` APIs is very simple. Let's get started! :::tip The complete example source code for this chapter can be found here: https://github.com/gogf/quick-demo