mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 08:29:58 +08:00
Optimize slicing operations (#4877)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -3,9 +3,9 @@ package spec
|
||||
import (
|
||||
"errors"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ func (m Member) IsOptional() bool {
|
||||
tag := m.Tags()
|
||||
for _, item := range tag {
|
||||
if item.Key == bodyTagKey || item.Key == formTagKey {
|
||||
if stringx.Contains(item.Options, "optional") {
|
||||
if slices.Contains(item.Options, "optional") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (m Member) IsOmitEmpty() bool {
|
||||
tag := m.Tags()
|
||||
for _, item := range tag {
|
||||
if item.Key == bodyTagKey {
|
||||
if stringx.Contains(item.Options, "omitempty") {
|
||||
if slices.Contains(item.Options, "omitempty") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (m Member) IsOmitEmpty() bool {
|
||||
func (m Member) GetPropertyName() (string, error) {
|
||||
tags := m.Tags()
|
||||
for _, tag := range tags {
|
||||
if stringx.Contains(definedKeys, tag.Key) {
|
||||
if slices.Contains(definedKeys, tag.Key) {
|
||||
if tag.Name == "-" {
|
||||
return util.Untitle(m.Name), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user