schema.go 565 B

1234567891011121314151617181920212223242526
  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. }