mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-04 23:00:30 +08:00
refactor: use slices.Contains to simplify code (#16680)
### Summary There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains) added in the go1.21 standard library, which can make the code more concise and easy to read. Signed-off-by: weifanglab <weifanglab@outlook.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -40,12 +41,7 @@ func IsCompositeModelName(modelName string) bool {
|
||||
if len(parts) != 3 {
|
||||
return false
|
||||
}
|
||||
for _, p := range parts {
|
||||
if p == "" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return !slices.Contains(parts, "")
|
||||
}
|
||||
|
||||
func IsUUID(uuid string) bool {
|
||||
@@ -68,10 +64,8 @@ func ExtractCompositeName(modelName string) (string, string, string, error) {
|
||||
if len(parts) != 3 {
|
||||
return "", "", "", fmt.Errorf("invalid model name format")
|
||||
}
|
||||
for _, p := range parts {
|
||||
if p == "" {
|
||||
return "", "", "", fmt.Errorf("invalid model name format")
|
||||
}
|
||||
if slices.Contains(parts, "") {
|
||||
return "", "", "", fmt.Errorf("invalid model name format")
|
||||
}
|
||||
return parts[0], parts[1], parts[2], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user