replace
len(name) != 0
with name != ""
59// WithName returns the option to set the name for server.
60func WithName(name string) Option {
61 return func(s *server) {
62 if len(name) != 0 { 63 s.name = name
64 }
65 }
replace
len(ip) != 0
with ip != ""
50// WithIP returns the option to set the IP for server.
51func WithIP(ip string) Option {
52 return func(s *server) {
53 if len(ip) != 0 { 54 s.ip = ip
55 }
56 }
replace
len(s) == 0
with s == ""
2833 } else {
2834 if pos < len(locs.GetLocations()) {
2835 locs.GetLocations()[pos].Ips = append(locs.GetLocations()[pos].Ips, loc.GetIps()...)
2836 if s := locs.GetLocations()[pos].Name; len(s) == 0 {2837 locs.GetLocations()[pos].Name = loc.GetName()
2838 } else {
2839 // strings.Join is used because '+=' causes performance degradation when the number of characters is large.
replace
len(id.GetId()) == 0
with id.GetId() == ""
2263 return nil, err
2264 }
2265 }
2266 shouldInsert = err != nil || id == nil || len(id.GetId()) == 02267 }
2268
2269 var operation string
replace
len(uuid) == 0
with uuid == ""
2141 ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.UpsertRPCName,
2142 ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
2143 }
2144 if len(uuid) == 0 {2145 err = status.WrapWithInvalidArgument(vald.UpsertRPCName+" API invalid uuid", errors.ErrInvalidMetaDataConfig, reqInfo, resInfo,
2146 &errdetails.BadRequest{
2147 FieldViolations: []*errdetails.BadRequestFieldViolation{
replace
len(uuid) == 0
with uuid == ""
1602 ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.UpdateRPCName + "." + vald.GetObjectRPCName,
1603 ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
1604 }
1605 if len(uuid) == 0 {1606 err = errors.ErrInvalidMetaDataConfig
1607 err = status.WrapWithInvalidArgument(vald.UpdateRPCName+" API invalid uuid", err, reqInfo, resInfo,
1608 &errdetails.BadRequest{
replace
len(id.GetId()) != 0
with id.GetId() != ""
1275 default:
1276 err = nil
1277 }
1278 } else if id != nil && len(id.GetId()) != 0 {1279 err = status.WrapWithAlreadyExists(vald.InsertRPCName+" API uuid "+uuid+"'s data already exists", errors.ErrMetaDataAlreadyExists(uuid), reqInfo, resInfo, info.Get())
1280 attrs = trace.StatusCodeAlreadyExists(err.Error())
1281 }
replace
len(uuid) == 0
with uuid == ""
1220 ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.InsertRPCName,
1221 ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
1222 }
1223 if len(uuid) == 0 {1224 err = errors.ErrInvalidMetaDataConfig
1225 err = status.WrapWithInvalidArgument(vald.InsertRPCName+" API invalid uuid", err, reqInfo, resInfo,
1226 &errdetails.BadRequest{
replace
len(req.GetId()) == 0
with req.GetId() == ""
835 ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.LinearSearchByIDRPCName,
836 ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
837 }
838 if len(req.GetId()) == 0 { 839 err = errors.ErrInvalidMetaDataConfig
840 err = status.WrapWithInvalidArgument(vald.LinearSearchByIDRPCName+" API invalid uuid", err, reqInfo, resInfo,
841 &errdetails.BadRequest{
replace
len(uuid) == 0
with uuid == ""
352 ResourceType: errdetails.ValdGRPCResourceTypePrefix + "/vald.v1." + vald.SearchByIDRPCName,
353 ResourceName: fmt.Sprintf("%s: %s(%s) to %v", apiName, s.name, s.ip, s.gateway.Addrs(ctx)),
354 }
355 if len(uuid) == 0 { 356 err = errors.ErrInvalidMetaDataConfig
357 err = status.WrapWithInvalidArgument(vald.SearchByIDRPCName+" API invalid uuid", err, reqInfo, resInfo,
358 &errdetails.BadRequest{
replace
len(uuid) == 0
with uuid == ""
77 }
78 }()
79
80 if len(uuid) == 0 { 81 err = errors.ErrInvalidUUID(uuid)
82 log.Warn(err)
83 if span != nil {
replace
len(addr) == 0
with addr == ""
104
105func WithVectorizerTargets(addr string) Option {
106 return func(s *server) {
107 if len(addr) == 0 {108 return
109 }
110 s.Vectorizer = addr
replace
len(name) != 0
with name != ""
56// WithName returns the option to set the name for server.
57func WithName(name string) Option {
58 return func(s *server) {
59 if len(name) != 0 { 60 s.name = name
61 }
62 }
replace
len(ip) != 0
with ip != ""
47// WithIP returns the option to set the IP for server.
48func WithIP(ip string) Option {
49 return func(s *server) {
50 if len(ip) != 0 { 51 s.ip = ip
52 }
53 }
replace
len(s.Vectorizer) == 0
with s.Vectorizer == ""
1126 }
1127 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
1128 if len(target) == 0 {
1129 if len(s.Vectorizer) == 0 {1130 err := errors.ErrFilterNotFound
1131 err = status.WrapWithInvalidArgument(vald.UpsertObjectRPCName+" API vectorizer configuration is invalid", err,
1132 &errdetails.RequestInfo{
replace
len(target) == 0
with target == ""
1125 vr.Host = "localhost"
1126 }
1127 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
1128 if len(target) == 0 {1129 if len(s.Vectorizer) == 0 {
1130 err := errors.ErrFilterNotFound
1131 err = status.WrapWithInvalidArgument(vald.UpsertObjectRPCName+" API vectorizer configuration is invalid", err,
replace
len(s.Vectorizer) == 0
with s.Vectorizer == ""
874
875 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
876 if len(target) == 0 {
877 if len(s.Vectorizer) == 0 { 878 err := errors.ErrFilterNotFound
879 err = status.WrapWithInvalidArgument(vald.UpdateObjectRPCName+" API vectorizer configuration is invalid", err,
880 &errdetails.RequestInfo{
replace
len(target) == 0
with target == ""
873 }
874
875 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
876 if len(target) == 0 { 877 if len(s.Vectorizer) == 0 {
878 err := errors.ErrFilterNotFound
879 err = status.WrapWithInvalidArgument(vald.UpdateObjectRPCName+" API vectorizer configuration is invalid", err,
replace
len(s.Vectorizer) == 0
with s.Vectorizer == ""
620 }
621 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
622 if len(target) == 0 {
623 if len(s.Vectorizer) == 0 { 624 err := errors.ErrFilterNotFound
625 err = status.WrapWithInvalidArgument(vald.InsertObjectRPCName+" API vectorizer configuration is invalid", err,
626 &errdetails.RequestInfo{
replace
len(target) == 0
with target == ""
619 vr.Host = "localhost"
620 }
621 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
622 if len(target) == 0 { 623 if len(s.Vectorizer) == 0 {
624 err := errors.ErrFilterNotFound
625 err = status.WrapWithInvalidArgument(vald.InsertObjectRPCName+" API vectorizer configuration is invalid", err,
replace
len(s.Vectorizer) == 0
with s.Vectorizer == ""
364 }
365 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
366 if len(target) == 0 {
367 if len(s.Vectorizer) == 0 { 368 err := errors.ErrFilterNotFound
369 err = status.WrapWithInvalidArgument(vald.LinearSearchObjectRPCName+" API vectorizer configuration is invalid", err,
370 &errdetails.RequestInfo{
replace
len(target) == 0
with target == ""
363 vr.Host = "localhost"
364 }
365 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
366 if len(target) == 0 { 367 if len(s.Vectorizer) == 0 {
368 err := errors.ErrFilterNotFound
369 err = status.WrapWithInvalidArgument(vald.LinearSearchObjectRPCName+" API vectorizer configuration is invalid", err,
replace
len(s.Vectorizer) == 0
with s.Vectorizer == ""
113 }
114 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
115 if len(target) == 0 {
116 if len(s.Vectorizer) == 0 { 117 err := errors.ErrFilterNotFound
118 err = status.WrapWithInvalidArgument(vald.SearchObjectRPCName+" API vectorizer configuration is invalid", err,
119 &errdetails.RequestInfo{
replace
len(target) == 0
with target == ""
112 vr.Host = "localhost"
113 }
114 target := fmt.Sprintf("%s:%d", vr.GetHost(), vr.GetPort())
115 if len(target) == 0 { 116 if len(s.Vectorizer) == 0 {
117 err := errors.ErrFilterNotFound
118 err = status.WrapWithInvalidArgument(vald.SearchObjectRPCName+" API vectorizer configuration is invalid", err,
replace
len(ns) != 0
with ns != ""
52
53func WithNamespace(ns string) Option {
54 return func(d *discoverer) error {
55 if len(ns) != 0 {56 d.namespace = ns
57 }
58 return nil
Description
It is not recommended to use len
for empty string test.
A string can be tested for its emptiness either by treating it as a slice and calculating the length of the slice, or by treating it as a string and directly comparing the value. While both produce identical code when compiled, it makes more sense to treat a string as itself, than a slice, for the sake of comparison of values.
Bad practice
len(s) == 0
Recommended
s == ""
The recommended practice is considered more idiomatic in Go.