feat: add knowledge management functionality with CRUD operations and database schema
- Implemented KnowledgeHandler for managing knowledge groups and items, including listing, creating, updating, and deleting operations. - Added database migration scripts to create necessary tables for knowledge management, including knowledge_groups, knowledge_items, knowledge_parse_tasks, and knowledge_chunks_meta. - Introduced prompt_rule_knowledge_groups table to associate prompt rules with knowledge groups.
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const ginAppErrorKey = "app_error"
|
||||
|
||||
type AppError struct {
|
||||
HTTPStatus int `json:"-"`
|
||||
Code int `json:"code"`
|
||||
@@ -41,6 +43,8 @@ func SuccessWithStatus(c *gin.Context, status int, data interface{}) {
|
||||
|
||||
func Error(c *gin.Context, err error) {
|
||||
appErr := Normalize(err)
|
||||
c.Set(ginAppErrorKey, appErr)
|
||||
_ = c.Error(appErr)
|
||||
c.JSON(appErr.HTTPStatus, gin.H{
|
||||
"code": appErr.Code,
|
||||
"message": appErr.Message,
|
||||
@@ -62,6 +66,18 @@ func Normalize(err error) *AppError {
|
||||
}
|
||||
}
|
||||
|
||||
func AppErrorFromGin(c *gin.Context) (*AppError, bool) {
|
||||
if c == nil {
|
||||
return nil, false
|
||||
}
|
||||
value, ok := c.Get(ginAppErrorKey)
|
||||
if !ok || value == nil {
|
||||
return nil, false
|
||||
}
|
||||
appErr, ok := value.(*AppError)
|
||||
return appErr, ok && appErr != nil
|
||||
}
|
||||
|
||||
func getRequestID(c *gin.Context) string {
|
||||
if rid, ok := c.Get("request_id"); ok {
|
||||
return rid.(string)
|
||||
|
||||
Reference in New Issue
Block a user