You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
562 B

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. package schema
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
  4. )
  5. type Schema struct {
  6. RecordType *schema_pb.RecordType
  7. fieldMap map[string]*schema_pb.Field
  8. }
  9. func NewSchema(recordType *schema_pb.RecordType) (*Schema, error) {
  10. fieldMap := make( map[string]*schema_pb.Field)
  11. for _, field := range recordType.Fields {
  12. fieldMap[field.Name] = field
  13. }
  14. return &Schema{
  15. RecordType: recordType,
  16. fieldMap: fieldMap,
  17. }, nil
  18. }
  19. func (s *Schema) GetField(name string) (*schema_pb.Field, bool) {
  20. field, ok := s.fieldMap[name]
  21. return field, ok
  22. }