MCPcopy Create free account
hub / github.com/astercloud/aster / ValidateContent

Method ValidateContent

pkg/memory/schema.go:61–78  ·  view source on GitHub ↗

ValidateContent 验证内容是否符合 Schema content: JSON 字符串或 Markdown 字符串 如果 Schema.Type 为空或 "string",直接验证字符串 如果 Schema.Type 为 "object" 等,先解析 JSON 再验证

(content string)

Source from the content-addressed store, hash-verified

59// 如果 Schema.Type 为空或 "string",直接验证字符串
60// 如果 Schema.Type 为 "object" 等,先解析 JSON 再验证
61func (s *JSONSchema) ValidateContent(content string) error {
62 if s == nil {
63 return nil // 无 Schema 时不验证
64 }
65
66 // 如果 Schema 类型为空或 string,直接验证字符串长度等
67 if s.Type == "" || s.Type == "string" {
68 return s.validateString(content)
69 }
70
71 // 否则,尝试解析为 JSON 并验证
72 var data any
73 if err := json.Unmarshal([]byte(content), &data); err != nil {
74 return fmt.Errorf("content is not valid JSON: %w", err)
75 }
76
77 return s.validateValue(data)
78}
79
80// validateString 验证字符串
81func (s *JSONSchema) validateString(value string) error {

Callers 1

UpdateMethod · 0.80

Calls 2

validateStringMethod · 0.95
validateValueMethod · 0.95

Tested by

no test coverage detected