github.com/weaviate/weaviate@v1.24.6/modules/ref2vec-centroid/config/validation.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package config 13 14 import ( 15 "errors" 16 "fmt" 17 ) 18 19 var errInvalidConfig = errors.New("invalid config") 20 21 func Validate(cfg *Config) error { 22 // referencePropertiesField is a required field 23 class := cfg.class.Class() 24 refProps, ok := class[referencePropertiesField] 25 if !ok { 26 return fmt.Errorf("%w: must have at least one value in the %q field", 27 errInvalidConfig, referencePropertiesField) 28 } 29 30 propSlice, ok := refProps.([]interface{}) 31 if !ok { 32 return fmt.Errorf("%w: expected array for field %q, got %T", 33 errInvalidConfig, referencePropertiesField, refProps) 34 } 35 36 if len(propSlice) == 0 { 37 return fmt.Errorf("%w: must have at least one value in the %q field", 38 errInvalidConfig, referencePropertiesField) 39 } 40 41 // all provided property names must be strings 42 for _, prop := range propSlice { 43 if _, ok := prop.(string); !ok { 44 return fmt.Errorf("%w: expected %q to contain strings, found %T: %+v", 45 errInvalidConfig, referencePropertiesField, prop, refProps) 46 } 47 } 48 49 return nil 50 }