Fix: Intn Panic when the len is 0 (#617)

This commit is contained in:
Fox_white 2023-03-11 15:45:40 +08:00 committed by GitHub
parent cc26eb1332
commit e1591c44b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,9 @@ func init() {
return "", err
}
arr := gjson.Get(helper.BytesToString(data), "data.data").Array()
if len(arr) == 0 {
return "", errors.New("data is empty")
}
pic := arr[rand.Intn(len(arr))]
return pic.String(), nil
}, web.GetData, time.Minute)