Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Nov 24, 2024
1 parent f7d647a commit 7cb1378
Show file tree
Hide file tree
Showing 44 changed files with 162 additions and 161 deletions.
1 change: 1 addition & 0 deletions .scripts/ai-trans/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
不要对顶部的front matter内容使用代码标签包括。
不能删除markdown内容中的图片展示标签内容。
不能翻译链接中的文件路径中的中文名称。
接口的关键词应当翻译为API。
`
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
- 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)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7cb1378

Please sign in to comment.