Introduction

gvar is a runtime generic implementation that enhances development convenience and efficiency with minimal runtime overhead. It supports various built-in data type conversions and can be used as an alternative to the interface{} type. This type supports concurrency safety toggles.

Generic - 图1tip

The framework also provides the g.Var data type, which is essentially an alias for the gvar.Var data type.

Usage Scenarios:

Scenarios where interface{} is used, various data formats that are not fixed, or scenarios that require frequent data type conversion.

Usage:

  1. import "github.com/gogf/gf/v2/container/gvar"

Interface Documentation:

https://pkg.go.dev/github.com/gogf/gf/v2/container/gvar

Documentation

📄️ Generic - UsageWhen using the GoFrame framework, utilize the gvar.Var container for the basic usage of generic types, including basic type conversion and slice conversion. It also demonstrates how to perform JSON format data serialization and deserialization operations. With the interfaces provided by the GoFrame framework, users can easily manipulate complex data structures to achieve efficient data processing.

📄️ Generic - MethodsCommon methods in the GoFrame framework, including operations such as creating new variables, cloning variables, setting variables, and getting variable values. The usage of each method is explained through example code to help users better understand and apply these methods.

📄️ Generic - PrecautionsPrecautions for using generic types in the GoFrame framework. Although generics improve development convenience, they may affect long-term maintenance in complex business projects. It is recommended to use generics in foundational components and middleware projects while clearly defining the data types of business models to leverage the advantages of compiled languages.