Skip to content

Releases: ggicci/owl

v0.8.2

20 Apr 20:51
Compare
Choose a tag to compare

Add ErrInvalidResolveTarget which can be returned by owl.ResolveTo() to tell that the error is caused by the given value is invalid.

v0.8.1

20 Apr 20:23
Compare
Choose a tag to compare

Now owl.ResolveTo() can take multi-level pointer values as the target for resolving to.

resolver, err := owl.New(User{})
var user = new(User)
Code v0.8.0 v0.8.1+
resolver.ResolveTo(user) ok ok
resolver.ResolveTo(&user) error ok

v0.8.0

13 Apr 22:32
Compare
Choose a tag to compare

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

30 Dec 21:04
Compare
Choose a tag to compare

Expose owl.Resolver.Copy API, which is a deep copy of a Resolver tree.

v0.6.1

17 Dec 20:06
e3644c4
Compare
Choose a tag to compare

Fixes #9: endless loop following self referential structs

v0.6.0

13 Nov 16:48
Compare
Choose a tag to compare

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

13 Nov 05:56
Compare
Choose a tag to compare

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

13 Nov 05:23
Compare
Choose a tag to compare

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 New

Ex:

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"`
}

v0.4.0

03 Oct 05:33
Compare
Choose a tag to compare

Remove type ScanErrors, the returned error now is an error that joined by errors.Join API.

Use the following code to expand it:

err.(interface{ Unwrap() []error }).Unwrap()

v0.3.0

02 Oct 04:06
Compare
Choose a tag to compare
feat: allow overriding namespace when calling Scan and Resolve

also...

1. removed the ReplaceDirectiveExecutor API
2. removed some error constants