-
Notifications
You must be signed in to change notification settings - Fork 29
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
Added support custom type and fixed bugs #49
Conversation
- added Unmarshaler\Marshaler interfaces
- (fix) unmarshal NoneType to nil
- (refactoring) added supported for dict if key is not string - transform to map[interface{}]interface{}
- added packages for tests - added github.com/pkg/errors
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.
So sorry for the delay on this @gebv, and thanks so much for your contributions. I have some small change requests, and would love to get this merged.
Thanks again!
case *starlarkstruct.Struct: | ||
if _var, ok := v.Constructor().(Unmarshaler); ok { | ||
err = _var.UnmarshalStarlark(x) | ||
if err != nil { | ||
err = errors.Wrapf(err, "failed marshal %q to Starlark object", v.Constructor().Type()) | ||
return | ||
} | ||
val = _var | ||
} else { | ||
err = fmt.Errorf("constructor object from *starlarkstruct.Struct not supported Marshaler to starlark object: %s", v.Constructor().Type()) | ||
} |
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.
This is a great addition!
util/util.go
Outdated
type Unmarshaler interface { | ||
UnmarshalStarlark(starlark.Value) 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.
This will cause golint
to fail. Both the Unmarshaler
interface and UnmarshalStarlark
methods should have comments that explain their use.
util/util.go
Outdated
type Marshaler interface { | ||
MarshalStarlark() (starlark.Value, 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.
Same as Unmarshaler
, this will cause golint
to fail. Both the Marshaler
interface and MarshalStarlark
methods should have comments that explain their use.
Co-authored-by: Brendan O'Brien <sparkle_pony_2000@qri.io>
Co-authored-by: Brendan O'Brien <sparkle_pony_2000@qri.io>
Any updates? |
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.
Looks great! Thanks!
starlark.Dict
if exists key as a not string