mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
chore: upgrade golangci-lint configuration and optimize codebase (#4236)
This PR includes the following changes: - **Upgrade `.golangci.yml`**: Updated the configuration file to align with the latest golangci-lint version, ensuring compatibility and leveraging new features. - **Refactor GitHub Action workflow**: Modified `golangci-lint.yml` in the GitHub Actions workflow to reflect the updated configuration and improve CI performance. - **Codebase optimization**: Refactored code to address issues and warnings raised by the updated golangci-lint rules, including: - Improved function length and complexity. - Enhanced error handling and variable naming conventions. - Fixed minor issues such as unused imports and formatting inconsistencies. These changes aim to maintain code quality, ensure compatibility with the latest tools, and improve overall maintainability.
This commit is contained in:
@ -246,7 +246,7 @@ func (c *Converter) doScanForComplicatedTypes(
|
||||
option ScanOption,
|
||||
) error {
|
||||
// Try JSON conversion first
|
||||
ok, err := c.doConvertWithJsonCheck(srcValue, dstPointer)
|
||||
ok, err := c.doConvertWithJSONCheck(srcValue, dstPointer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -355,7 +355,7 @@ func (c *Converter) doConvertWithTypeCheck(srcValueReflectValue, dstPointerRefle
|
||||
}
|
||||
}
|
||||
|
||||
// doConvertWithJsonCheck attempts to convert the source value to the destination
|
||||
// doConvertWithJSONCheck attempts to convert the source value to the destination
|
||||
// using JSON marshaling and unmarshaling. This is particularly useful for complex
|
||||
// types that can be represented as JSON.
|
||||
//
|
||||
@ -366,7 +366,7 @@ func (c *Converter) doConvertWithTypeCheck(srcValueReflectValue, dstPointerRefle
|
||||
// Returns:
|
||||
// - bool: true if JSON conversion was successful
|
||||
// - error: any error that occurred during conversion
|
||||
func (c *Converter) doConvertWithJsonCheck(srcValue any, dstPointer any) (ok bool, err error) {
|
||||
func (c *Converter) doConvertWithJSONCheck(srcValue any, dstPointer any) (ok bool, err error) {
|
||||
switch valueResult := srcValue.(type) {
|
||||
case []byte:
|
||||
if json.Valid(valueResult) {
|
||||
@ -403,7 +403,7 @@ func (c *Converter) doConvertWithJsonCheck(srcValue any, dstPointer any) (ok boo
|
||||
default:
|
||||
// The `params` might be struct that implements interface function Interface, eg: gvar.Var.
|
||||
if v, ok := srcValue.(localinterface.IInterface); ok {
|
||||
return c.doConvertWithJsonCheck(v.Interface(), dstPointer)
|
||||
return c.doConvertWithJSONCheck(v.Interface(), dstPointer)
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
|
||||
@ -50,7 +50,7 @@ func (c *Converter) Struct(params, pointer any, option ...StructOption) (err err
|
||||
}
|
||||
|
||||
// JSON content converting.
|
||||
ok, err := c.doConvertWithJsonCheck(params, pointer)
|
||||
ok, err := c.doConvertWithJSONCheck(params, pointer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -474,7 +474,7 @@ func bindVarToReflectValueWithInterfaceCheck(reflectValue reflect.Value, value a
|
||||
// bindVarToReflectValue sets `value` to reflect value object `structFieldValue`.
|
||||
func (c *Converter) bindVarToReflectValue(structFieldValue reflect.Value, value any, option StructOption) (err error) {
|
||||
// JSON content converting.
|
||||
ok, err := c.doConvertWithJsonCheck(value, structFieldValue)
|
||||
ok, err := c.doConvertWithJSONCheck(value, structFieldValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ func (cf *Converter) checkTypeImplInterface(t reflect.Type) AnyConvertFunc {
|
||||
|
||||
var (
|
||||
implUnmarshalText = reflect.TypeOf((*localinterface.IUnmarshalText)(nil)).Elem()
|
||||
implUnmarshalJson = reflect.TypeOf((*localinterface.IUnmarshalJSON)(nil)).Elem()
|
||||
implUnmarshalJSON = reflect.TypeOf((*localinterface.IUnmarshalJSON)(nil)).Elem()
|
||||
implUnmarshalValue = reflect.TypeOf((*localinterface.IUnmarshalValue)(nil)).Elem()
|
||||
)
|
||||
|
||||
@ -131,7 +131,7 @@ func checkTypeIsCommonInterface(field reflect.StructField) bool {
|
||||
case field.Type.Implements(implUnmarshalText):
|
||||
isCommonInterface = true
|
||||
|
||||
case field.Type.Implements(implUnmarshalJson):
|
||||
case field.Type.Implements(implUnmarshalJSON):
|
||||
isCommonInterface = true
|
||||
|
||||
case field.Type.Implements(implUnmarshalValue):
|
||||
|
||||
@ -15,8 +15,8 @@ var enumsMap = make(map[string]json.RawMessage)
|
||||
|
||||
// SetGlobalEnums sets the global enums into package.
|
||||
// Note that this operation is not concurrent safety.
|
||||
func SetGlobalEnums(enumsJson string) error {
|
||||
return json.Unmarshal([]byte(enumsJson), &enumsMap)
|
||||
func SetGlobalEnums(enumsJSON string) error {
|
||||
return json.Unmarshal([]byte(enumsJSON), &enumsMap)
|
||||
}
|
||||
|
||||
// GetGlobalEnums retrieves and returns the global enums.
|
||||
|
||||
@ -476,20 +476,20 @@ func addSlashesForString(s string) string {
|
||||
func DumpJson(value any) {
|
||||
switch result := value.(type) {
|
||||
case []byte:
|
||||
doDumpJson(result)
|
||||
doDumpJSON(result)
|
||||
case string:
|
||||
doDumpJson([]byte(result))
|
||||
doDumpJSON([]byte(result))
|
||||
default:
|
||||
jsonContent, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
doDumpJson(jsonContent)
|
||||
doDumpJSON(jsonContent)
|
||||
}
|
||||
}
|
||||
|
||||
func doDumpJson(jsonContent []byte) {
|
||||
func doDumpJSON(jsonContent []byte) {
|
||||
var (
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
jsonBytes = jsonContent
|
||||
|
||||
@ -40,7 +40,7 @@ func (r RuleSize) Run(in RunInput) error {
|
||||
)
|
||||
size, err := strconv.Atoi(in.RulePattern)
|
||||
if valueLen != size || err != nil {
|
||||
return errors.New(strings.Replace(in.Message, "{size}", strconv.Itoa(size), -1))
|
||||
return errors.New(strings.ReplaceAll(in.Message, "{size}", strconv.Itoa(size)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user