543 - update: to use updated config structure

This commit is contained in:
ameersohel45
2025-11-14 13:06:31 +05:30
parent 9f913e6aa9
commit 75880a4458
5 changed files with 106 additions and 54 deletions

View File

@@ -18,21 +18,26 @@ func (vp schemav2ValidatorProvider) New(ctx context.Context, config map[string]s
return nil, nil, errors.New("context cannot be nil")
}
url, ok := config["url"]
if !ok || url == "" {
return nil, nil, errors.New("url not configured")
}
typeVal, hasType := config["type"]
locVal, hasLoc := config["location"]
cacheTTL := 3600
if ttlStr, ok := config["cacheTTL"]; ok {
if ttl, err := strconv.Atoi(ttlStr); err == nil && ttl > 0 {
cacheTTL = ttl
}
if !hasType || typeVal == "" {
return nil, nil, errors.New("type not configured")
}
if !hasLoc || locVal == "" {
return nil, nil, errors.New("location not configured")
}
cfg := &schemav2validator.Config{
URL: url,
CacheTTL: cacheTTL,
Type: typeVal,
Location: locVal,
CacheTTL: 3600,
}
if ttlStr, ok := config["cacheTTL"]; ok {
if ttl, err := strconv.Atoi(ttlStr); err == nil && ttl > 0 {
cfg.CacheTTL = ttl
}
}
return schemav2validator.New(ctx, cfg)