Optimize slicing operations (#4877)

This commit is contained in:
me-cs
2025-05-20 19:36:02 +08:00
committed by GitHub
parent a682bda0bb
commit 4d3681b71c
4 changed files with 138 additions and 10 deletions

View File

@@ -8,10 +8,10 @@ import (
"fmt"
"io"
"path"
"slices"
"strings"
"text/template"
"github.com/zeromicro/go-zero/core/stringx"
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util"
"github.com/zeromicro/go-zero/tools/goctl/internal/version"
@@ -96,13 +96,13 @@ func (c *componentsContext) createComponent(dir, packetName string, ty spec.Type
for _, item := range c.responseTypes {
if item.Name() == defineStruct.Name() {
superClassName = "HttpResponseData"
if !stringx.Contains(c.imports, httpResponseData) {
if !slices.Contains(c.imports, httpResponseData) {
c.imports = append(c.imports, httpResponseData)
}
break
}
}
if superClassName == "HttpData" && !stringx.Contains(c.imports, httpData) {
if superClassName == "HttpData" && !slices.Contains(c.imports, httpData) {
c.imports = append(c.imports, httpData)
}
@@ -266,7 +266,7 @@ func (c *componentsContext) genGetSet(writer io.Writer, indent int) error {
tyString := javaType
decorator := ""
javaPrimitiveType := []string{"int", "long", "boolean", "float", "double", "short"}
if !stringx.Contains(javaPrimitiveType, javaType) {
if !slices.Contains(javaPrimitiveType, javaType) {
if member.IsOptional() || member.IsOmitEmpty() {
decorator = "@Nullable "
} else {