-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
tpl: Add reflection functions #2427
Conversation
I'll update the docs once this is reviewed and before merged |
@anagio, I'm curious what your use case is for these. Are you just adding function to add functions or is this useful for you? |
@moorereason these are useful to me and i'm sure will be to others. I have a data file (JSON) where a property in each object is usually a string but in some cases it may store another object. While looping over this data file these functions will help determine if I have a string or map returned. |
Thanks I'll update the docs soon |
Please update your commit message subject to following the contributing guide.
|
031c45c
to
3eaf497
Compare
@moorereason updated title, and squashed commits |
@anagio, you're close. I meant for you to update your commit message subject, not the PR title. |
|
||
### typeOf | ||
|
||
Takes an interface and returns a string representation of the type. For pointers, this will return a type prefixed with an asterisk(*). So a pointer to type Foo will be *Foo. |
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.
Use backticks to keep the markdown from thinking you mean to use italics around the asterisks. For example,
with an asterisk(`*`). So a pointer to a type `Foo` will be `*Foo`.
3eaf497
to
fa744b3
Compare
@moorereason thanks just made those updates |
|
||
### typeIs | ||
|
||
Compares an interface with a string name, and returns true if they match. Note that a pointer will not match a reference. For example `*`Foo will not match Foo. |
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.
Should be:
For example `*Foo` will not match `Foo`.
@anagio, it would be helpful to add example usages for all functions. |
fa744b3
to
7c346fb
Compare
@moorereason docs are updated with an example of each function |
return defaultT(translationID, args...) | ||
if translated := defaultT(translationID, args...); translated != translationID { | ||
return translated | ||
} |
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.
Don't include this in your commit.
7c346fb
to
44e6117
Compare
@moorereason sorry about that it's removed |
LGTM |
Can this get merged in to make the release of 0.17 ? |
Hello @anagio. Thanks for this PR. This PR was referenced in this discussion. I need what you have as What was the blocker for merging this? |
@kaushalmodi I was not able to merge it on my own. moorereason said LGTM but it was just never merged. Ping him for more info |
@anagio Well you should have pinged him a reminder to merge this. If you reopen this PR, may be @moorereason can take further steps. |
I really didn't feel the need to ping anyone about merging it |
Alright. Would you like to reopen this PR and wait for it to be merged? Or should I just open a new PR? I just wanted to give credits where they were due by having your commit merged if feasible. |
We didn't merge because it would have permanently added some rather esoteric funcs to the global func map. Now that we have template func namespacing, we can revisit this. A lot has changed since this PR, so it would be better to start a new one. |
@kaushalmodi feel free to submit a new PR |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This adds template functions to check types. Originally from https://github.com/Masterminds/sprig#reflection
typeOf
: Takes an interface and returns a string representation of the type. For pointers, this will return a type prefixed with an asterisk(*). So a pointer to type Foo will be *Foo.typeIs
: Compares an interface with a string name, and returns true if they match. Note that a pointer will not match a reference. For example *Foo will not match Foo.typeIsLike
: returns true if the interface is of the given type, or is a pointer to the given type.kindOf
: Takes an interface and returns a string representation of its kind.kindIs
: Returns true if the given string matches the kind of the given interface.