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:
houseme
2025-08-22 13:29:09 +08:00
committed by GitHub
parent 24083b865d
commit 7ffdff37e4
33 changed files with 290 additions and 425 deletions

View File

@ -24,9 +24,9 @@ import (
type ContentType string
const (
ContentTypeJson ContentType = `json`
ContentTypeJSON ContentType = `json`
ContentTypeJs ContentType = `js`
ContentTypeXml ContentType = `xml`
ContentTypeXML ContentType = `xml`
ContentTypeIni ContentType = `ini`
ContentTypeYaml ContentType = `yaml`
ContentTypeYml ContentType = `yml`
@ -92,7 +92,7 @@ func (j *Json) setValue(pattern string, value interface{}, removed bool) error {
}
var (
pparent *interface{} = nil // Parent pointer.
pointer *interface{} = j.p // Current pointer.
pointer = j.p // Current pointer.
)
j.mu.Lock()
defer j.mu.Unlock()

View File

@ -20,7 +20,7 @@ import (
// The parameter `safe` specifies whether using this Json object in concurrent-safe context,
// which is false in default.
func New(data interface{}, safe ...bool) *Json {
return NewWithTag(data, string(ContentTypeJson), safe...)
return NewWithTag(data, string(ContentTypeJSON), safe...)
}
// NewWithTag creates a Json object with any variable type of `data`, but `data` should be a map

View File

@ -29,7 +29,7 @@ func LoadWithOptions(data []byte, options Options) (*Json, error) {
// LoadJson creates a Json object from given JSON format content.
func LoadJson(data []byte, safe ...bool) (*Json, error) {
var option = Options{
Type: ContentTypeJson,
Type: ContentTypeJSON,
}
if len(safe) > 0 && safe[0] {
option.Safe = true
@ -40,7 +40,7 @@ func LoadJson(data []byte, safe ...bool) (*Json, error) {
// LoadXml creates a Json object from given XML format content.
func LoadXml(data []byte, safe ...bool) (*Json, error) {
var option = Options{
Type: ContentTypeXml,
Type: ContentTypeXML,
}
if len(safe) > 0 && safe[0] {
option.Safe = true
@ -126,9 +126,9 @@ func IsValidDataType(dataType ContentType) bool {
}
switch dataType {
case
ContentTypeJson,
ContentTypeJSON,
ContentTypeJs,
ContentTypeXml,
ContentTypeXML,
ContentTypeYaml,
ContentTypeYml,
ContentTypeToml,
@ -171,9 +171,9 @@ func loadContentWithOptions(data []byte, options Options) (*Json, error) {
string(options.Type), "."),
)
switch options.Type {
case ContentTypeJson, ContentTypeJs:
case ContentTypeJSON, ContentTypeJs:
case ContentTypeXml:
case ContentTypeXML:
data, err = gxml.ToJson(data)
case ContentTypeYaml, ContentTypeYml:
@ -221,10 +221,10 @@ func loadContentWithOptions(data []byte, options Options) (*Json, error) {
func checkDataType(data []byte) (ContentType, error) {
switch {
case json.Valid(data):
return ContentTypeJson, nil
return ContentTypeJSON, nil
case isXmlContent(data):
return ContentTypeXml, nil
case isXMLContent(data):
return ContentTypeXML, nil
case isYamlContent(data):
return ContentTypeYaml, nil
@ -247,7 +247,7 @@ func checkDataType(data []byte) (ContentType, error) {
}
}
func isXmlContent(data []byte) bool {
func isXMLContent(data []byte) bool {
return gregex.IsMatch(`^\s*<.+>[\S\s]+<.+>\s*$`, data)
}

View File

@ -14,7 +14,7 @@ func (j Json) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
func (j *Json) UnmarshalJSON(b []byte) error {
r, err := loadContentWithOptions(b, Options{
Type: ContentTypeJson,
Type: ContentTypeJSON,
StrNumber: true,
})
if r != nil {