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

Method ParseIntoWithValidation

pkg/structured/typed.go:64–76  ·  view source on GitHub ↗

ParseIntoWithValidation 解析并进行自定义验证

(ctx context.Context, text string, target any, validator func(any) error)

Source from the content-addressed store, hash-verified

62
63// ParseIntoWithValidation 解析并进行自定义验证
64func (tp *TypedParser) ParseIntoWithValidation(ctx context.Context, text string, target any, validator func(any) error) error {
65 if err := tp.ParseInto(ctx, text, target); err != nil {
66 return err
67 }
68
69 if validator != nil {
70 if err := validator(target); err != nil {
71 return fmt.Errorf("custom validation failed: %w", err)
72 }
73 }
74
75 return nil
76}
77
78// ExtractAndParse 提取 JSON 并解析为通用 map
79func (tp *TypedParser) ExtractAndParse(ctx context.Context, text string) (map[string]any, error) {

Callers

nothing calls this directly

Calls 1

ParseIntoMethod · 0.95

Tested by

no test coverage detected