Releases: ggicci/owl
v0.8.2
v0.8.1
v0.8.0
New Features
Added new API Resolver.ResoveTo(value any, opts ...Option), which allow specifying the target value where the resolver should populate values.
v0.7.0
v0.6.1
v0.6.0
New Features
Sort directives at tree build time and resolving/scanning runtime:
type Record struct {
R1 string `owl:"DOTA=2;csgo=1"`
R2 string `owl:"apple=green;pear;Grape=purple"`
}1. When passing the option to New:
owl.New(Record{}, owl.WithDirectiveRunOrder(func(d1, d2 *owl.Directive) bool {
return strings.ToLower(d1.Name) < strings.ToLower(d2.Name) // sort directives by name (alphabetical order)
}))the directives will be sorted at tree build stage. I.e. The Resolver built for field Record.R2 looks like this:
Resolver(R2).Directives ==> []*Directive {
&Directive{Name: "apple", Argv: { "green" }},
&Directive{Name: "Grape", Argv: { "purple" }},
&Directive{Name: "apple", Argv: {}},
}
Actually we can use the API Resolver.Iterate to achieve the same result.
2. When passing the option to Resolve or Scan:
resolver.Scan(form, owl.WithDirectiveRunOrder(func(d1, d2 *owl.Directive) bool {
return d1.Name == "default" // makes default directive run first
}))the original directives order won't be affected. A copy of the directives will be created an sorted.
v0.5.1
Fix the definition of nested directives.
type CreateUserRequest struct {
ApiVersion string `owl:"form=api_version"`
User // no directives defined here
}
type UpdateUserRequest struct {
ApiVersion string `owl:"form=api_version"`
User `owl:"body=xml"` // defined a "body" directive
}Since no directives are defined on field CreateUserRequest.User, the directives defined in User struct are non-nested directives.
While UpdateUserRequest.User has a directive defined, thus, the directives defined in User struct are nested directives.
v0.5.0
New Features
Added a new option WithNestedDirectivesEnabled, which can be used to disable the feature of executing the directives in nested fields.
The default value is true.
resolver := owl.New(MyStruct{}, owl.WithNestedDirectivesEnabled(false))
resolver.Resolve(owl.WithNestedDirectivesEnabled(false)) // can override the value set in New
resolver.Scan(value, owl.WithNestedDirectivesEnabled(false)) // can override the value set in NewEx:
type CreatePackageRequest struct {
Owner string `owl:"path=owner"`
Package struct {
Name string `owl:"form=name"` // won't run if disabled
Description string `owl:"form=description"`
License string `owl:"form=license"`
} `owl:"body=json"`
}