mirror of
https://github.com/alibaba/higress.git
synced 2026-06-02 00:57:28 +08:00
fix: nil guards, safe type assertions, panic prevention, and rate limiter plugin (#3757)
Signed-off-by: Srikanth Patchava <spatchava@meta.com> Signed-off-by: Srikanth Patchava <srpatcha@users.noreply.github.com> Co-authored-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1c4fe1c9f9
commit
29da03c371
@@ -236,6 +236,10 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
|
||||
// ListTables List all tables in the connected database.
|
||||
func (c *DBClient) ListTables() ([]string, error) {
|
||||
if err := c.reconnectIfDbEmpty(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sql string
|
||||
switch c.dbType {
|
||||
case MYSQL:
|
||||
@@ -265,6 +269,10 @@ func (c *DBClient) ListTables() ([]string, error) {
|
||||
tables = append(tables, table)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating table rows: %w", err)
|
||||
}
|
||||
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
@@ -335,6 +343,10 @@ func (c *DBClient) Query(sql string, args ...interface{}) ([]map[string]interfac
|
||||
results = append(results, rowMap)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("failed to iterate table rows in Query: %w", err)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -792,22 +792,36 @@ func (m *MilvusProvider) ListDocs(ctx context.Context, limit int) ([]schema.Docu
|
||||
fieldName := strings.ToLower(fieldMapping.StandardName)
|
||||
switch fieldName {
|
||||
case "id":
|
||||
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil {
|
||||
id = v.(string)
|
||||
if typedCol, ok := col.(*entity.ColumnVarChar); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if s, ok := v.(string); ok {
|
||||
id = s
|
||||
}
|
||||
}
|
||||
}
|
||||
case "content":
|
||||
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil {
|
||||
content = v.(string)
|
||||
if typedCol, ok := col.(*entity.ColumnVarChar); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if s, ok := v.(string); ok {
|
||||
content = s
|
||||
}
|
||||
}
|
||||
}
|
||||
case "metadata":
|
||||
if v, err := col.(*entity.ColumnJSONBytes).Get(i); err == nil {
|
||||
if bytes, ok := v.([]byte); ok {
|
||||
_ = json.Unmarshal(bytes, &metadata)
|
||||
if typedCol, ok := col.(*entity.ColumnJSONBytes); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if bytes, ok := v.([]byte); ok {
|
||||
_ = json.Unmarshal(bytes, &metadata)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "created_at":
|
||||
if v, err := col.(*entity.ColumnInt64).Get(i); err == nil {
|
||||
createdAt = v.(int64)
|
||||
if typedCol, ok := col.(*entity.ColumnInt64); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if ts, ok := v.(int64); ok {
|
||||
createdAt = ts
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,13 +87,17 @@ func parseConfig(json gjson.Result, config *RequestBlockConfig, log log.Log) err
|
||||
if regexpUrl == "" {
|
||||
continue
|
||||
}
|
||||
var reg *regexp.Regexp
|
||||
var err error
|
||||
if config.caseSensitive {
|
||||
reg := regexp.MustCompile(regexpUrl)
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
reg, err = regexp.Compile(regexpUrl)
|
||||
} else {
|
||||
reg := regexp.MustCompile(strings.ToLower(regexpUrl))
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
reg, err = regexp.Compile(strings.ToLower(regexpUrl))
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid regexp pattern %q: %w", regexpUrl, err)
|
||||
}
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
}
|
||||
for _, item := range json.Get("block_headers").Array() {
|
||||
header := item.String()
|
||||
|
||||
Reference in New Issue
Block a user