-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose field object publicly #52
base: master
Are you sure you want to change the base?
Conversation
@@ -114,6 +114,9 @@ type field struct { | |||
Filterable bool | |||
// All supported operators for this field. | |||
FilterOps map[string]bool | |||
} | |||
type Field struct { | |||
*FieldMeta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not inline its fields inside the Field
type?
func (p *Parser) GetFields() []*Field { | ||
fields := make([]*Field, 0, len(p.fields)) | ||
for _, v := range p.fields { | ||
fields = append(fields, v) | ||
} | ||
return fields | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (p *Parser) GetFields() []*Field { | |
fields := make([]*Field, 0, len(p.fields)) | |
for _, v := range p.fields { | |
fields = append(fields, v) | |
} | |
return fields | |
} | |
func (p *Parser) Fields() []*Field { | |
fields := make([]*Field, 0, len(p.fields)) | |
for _, v := range p.fields { | |
fields = append(fields, v) | |
} | |
return fields | |
} |
Why this method is needed? If it's for testing, let's use the existing public API instead.
} | ||
if err := p.init(); err != nil { | ||
return nil, err | ||
} | ||
return p, nil | ||
} | ||
|
||
// Does not use config.Model, gets config from Fields) | ||
func NewParserF(c Config, fields []*Field) (*Parser, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to: NewFieldsParser or add a new option as Config.Fields
.
Also, an error should return if c.Model
was set as the two are mutually exclusive.
Thanks for the contribution, @ashtonian. It's appreciated. |
This adds functions to expose the internal fields object and to create a new parser from a slice of field objects. This lets the user dynamically configure a parser, my use case is to change rql config based on permissions. I would also like to expose the parsed data and related field information to be able to document related metadata for the user like what are available operations. I think it pairs well with #51.
I think it would be nice to refactor to the following, but this is breaking:
Added: