// ValidateStructField validates a structure field, only []string and string types are supported
168572
func ValidateStructField(value reflect.Value, tag string) (bool, error) {
	re := regexp.MustCompile(`^enum=(.+,*?)+$`)
	parts := re.FindStringSubmatch(tag)

	if len(parts) != 2 {
		return false, fmt.Errorf("invalid tag '%s', must be enum=v1,v2,v3", tag)
	}

	evs := strings.Split(parts[1], ",")

	switch value.Kind() {
	case reflect.Slice:
		slice, ok := value.Interface().([]string)
		if !ok {
			return false, fmt.Errorf("only []string slices can be validated for enums")
		}

		return ValidateSlice(slice, evs)
	case reflect.String:
		str, _ := value.Interface().(string)

		return ValidateString(str, evs)

	default:
		return false, fmt.Errorf("cannot valid data of type %s for enums", value.Kind().String())
	}
}
988525
func LoadStruct(dst interface{}, f []Field) error {
	x, err := newStructFLS(dst)
	if err != nil {
		return err
	}
	return x.Load(f, nil)
}
490663
func compileStruct(file string, src *ast.Struct, requiredness fieldRequiredness) (*StructSpec, error) {
	opts := fieldOptions{requiredness: requiredness}

	if src.Type == ast.UnionType {
		opts.requiredness = noRequiredFields
		opts.disallowDefaultValue = true
	}

	fields, err := compileFields(src.Fields, opts)
	if err != nil {
		return nil, compileError{
			Target: src.Name,
			Line:   src.Line,
			Reason: err,
		}
	}

	annotations, err := compileAnnotations(src.Annotations)
	if err != nil {
		return nil, compileError{
			Target: src.Name,
			Line:   src.Line,
			Reason: err,
		}
	}

	return &StructSpec{
		Name:        src.Name,
		File:        file,
		Type:        src.Type,
		Fields:      fields,
		Doc:         src.Doc,
		Annotations: annotations,
	}, nil
}
607046
func getStructField(v interface{}, field string) (fieldVal interface{}, exists bool) {
	vv := reflect.ValueOf(v)
	if !vv.IsValid() {
		return nil, false
	}
	if vv.Kind() == reflect.Ptr {
		vv = vv.Elem()
	}
	fv := vv.FieldByName(field)
	if !fv.IsValid() {
		return nil, false
	}
	return fv.Interface(), true
}
388491
func (f FieldDefinition) Validate() error {
	if strings.TrimSpace(f.Label) == "" {
		return errs.Errorf(`field label is empty "%s" when trimmed`, f.Label)
	}
	return f.Type.Validate()
}
214350
func TableFromStructs(structs Slice) *Table {
	s := reflectSlice(structs)
	st := s.Type()
	if st.Elem().Kind() != reflect.Struct {
		panic(&generic.TypeError{st, nil, "is not a slice of struct"})
	}

	var t Builder
	rows := s.Len()
	var rec func(reflect.Type, []int)
	rec = func(typ reflect.Type, index []int) {
		for fn := 0; fn < typ.NumField(); fn++ {
			field := typ.Field(fn)
			if field.PkgPath != "" {
				continue
			}
			oldIndexLen := len(index)
			index = append(index, field.Index...)
			if field.Anonymous {
				rec(field.Type, index)
			} else {
				col := reflect.MakeSlice(reflect.SliceOf(field.Type), rows, rows)
				for i := 0; i < rows; i++ {
					col.Index(i).Set(s.Index(i).FieldByIndex(index))
				}
				t.Add(field.Name, col.Interface())
			}
			index = index[:oldIndexLen]
		}
	}
	rec(st.Elem(), []int{})
	return t.Done()
}
1123597
func CheckValidHashStructures(hashes Hashes) error {
	cnt := 0

	for k, v := range hashes {
		switch k {
		case notary.SHA256:
			if len(v) != sha256.Size {
				return ErrInvalidChecksum{alg: notary.SHA256}
			}
			cnt++
		case notary.SHA512:
			if len(v) != sha512.Size {
				return ErrInvalidChecksum{alg: notary.SHA512}
			}
			cnt++
		}
	}

	if cnt == 0 {
		return fmt.Errorf("at least one supported hash needed")
	}

	return nil
}
798171
func (v *validate) GetStructFieldOK() (reflect.Value, reflect.Kind, bool) {
	return v.getStructFieldOKInternal(v.slflParent, v.ct.param)
}
284644
func tableFromStructType(structName string, structType *ast.StructType, packagePrefix string) (*Table, error) {
	normalizedName, err := NormalizeName(structName)
	if err != nil {
		// TODO: This isn't correct, someone could override the name later
		return nil, errors.Wrapf(err, "struct name is invalid")
	}

	t := &Table{
		StructName: structName,
		EntityDefinition: EntityDefinition{
			Name:    normalizedName,
			Columns: []*ColumnDefinition{},
			Indexes: map[string]*IndexDefinition{},
		},
		ColToField: map[string]string{},
		FieldToCol: map[string]string{},
	}
	for _, field := range structType.Fields.List {
		var dosaTag string
		if field.Tag != nil {
			entityTag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
			dosaTag = strings.TrimSpace(entityTag.Get(dosaTagKey))
		}
		if dosaTag == "-" { // skip explicitly ignored fields
			continue
		}

		kind, err := parseASTType(field.Type)
		if err != nil {
			return nil, err
		}

		if kind == packagePrefix+"."+entityName || (packagePrefix == "" && kind == entityName) {
			var err error
			if t.EntityDefinition.Name, t.TTL, t.ETL, t.Key, err = parseEntityTag(structName, dosaTag); err != nil {
				return nil, err
			}
		} else {
			for _, fieldName := range field.Names {
				name := fieldName.Name
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag(name, dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				} else {
					firstRune, _ := utf8.DecodeRuneInString(name)
					if unicode.IsLower(firstRune) {
						// skip unexported fields
						continue
					}
					typ, isPointer := stringToDosaType(kind, packagePrefix)
					if typ == Invalid {
						return nil, fmt.Errorf("Column %q has invalid type %q", name, kind)
					}
					cd, err := parseField(typ, isPointer, name, dosaTag)
					if err != nil {
						return nil, errors.Wrapf(err, "column %q", name)
					}
					t.Columns = append(t.Columns, cd)
					t.ColToField[cd.Name] = name
					t.FieldToCol[name] = cd.Name
				}
			}

			if len(field.Names) == 0 {
				if kind == packagePrefix+"."+indexName || (packagePrefix == "" && kind == indexName) {
					indexName, indexKey, err := parseIndexTag("", dosaTag)
					if err != nil {
						return nil, err
					}
					if _, exist := t.Indexes[indexName]; exist {
						return nil, errors.Errorf("index name is duplicated: %s", indexName)
					}
					t.Indexes[indexName] = &IndexDefinition{Key: indexKey}
				}
			}
		}
	}

	if t.Key == nil {
		return nil, errors.Errorf("cannot find dosa.Entity in object %s", t.StructName)
	}

	translateKeyName(t)
	if err := t.EnsureValid(); err != nil {
		return nil, errors.Wrap(err, "failed to parse dosa object")
	}
	return t, nil
}
334341
func (v *defaultValidator) ValidateStruct(obj interface{}) error {
	value := reflect.ValueOf(obj)
	valueType := value.Kind()
	if valueType == reflect.Ptr {
		valueType = value.Elem().Kind()
	}
	if valueType == reflect.Struct {
		v.lazyinit()
		if err := v.validate.Struct(obj); err != nil {
			return err
		}
	}
	return nil
}
1080618
func setStructValues(structElem *reflect.Value) error {
	numFields := structElem.NumField()
	structType := structElem.Type()

	for i := 0; i < numFields; i++ {
		structField := structType.Field(i)
		fieldValue := structElem.Field(i)

		if fieldValue.Kind() == reflect.Struct {
			if err := setValue(&fieldValue, structField.Name, ""); err != nil {
				return err
			}

			continue
		}

		envValue := getEnvOrDefaultValue(&structField)

		if envValue == "" {
			continue
		}

		if err := setValue(&fieldValue, structField.Name, envValue); err != nil {
			return err
		}
	}

	return nil
}
958529
func (s *GetTemplateService) Validate() error {
	var invalid []string
	if s.id == "" {
		invalid = append(invalid, "Id")
	}
	if len(invalid) > 0 {
		return fmt.Errorf("missing required fields: %v", invalid)
	}
	return nil
}
746415
func (v *Validate) RegisterStructValidation(fn StructLevelFunc, types ...interface{}) {
	v.RegisterStructValidationCtx(wrapStructLevelFunc(fn), types...)
}
422044
func (s *StructInjector) fillStruct() {
	if !s.Has {
		return
	}
	// if field is Static then set it to the value that passed by the caller,
	// so will have the static bindings already and we can just use that value instead
	// of creating new instance.
	destElem := IndirectValue(s.initRef)
	for _, f := range s.fields {
		// if field is Static then set it to the value that passed by the caller,
		// so will have the static bindings already and we can just use that value instead
		// of creating new instance.
		if f.Object.BindType == Static {
			destElem.FieldByIndex(f.FieldIndex).Set(f.Object.Value)
		}
	}
}
264690
func RegisterStructTags(vals ...interface{}) {
	tags := mkTags(vals...)
	for k, v := range tags {
		tagsForType[k] = v
	}
}
408132
func (t *TypeInfo) StructType() (*StructTypeInfo, error) {
	structType, ok := interface{}(t.TypeSpec.Type).(*ast.StructType)
	if !ok {
		return nil, ErrNotStructType
	}

	return (*StructTypeInfo)(structType), nil
}
1158792
func (st *StructTypeInfo) FieldInfos() FieldInfos {
	var fields FieldInfos
	for _, field := range st.AstStructType().Fields.List {
		fields = append(fields, (*FieldInfo)(field))
	}

	return fields
}