-
Notifications
You must be signed in to change notification settings - Fork 316
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
Add MarshalText and UnmarshalText for Duration #270
Add MarshalText and UnmarshalText for Duration #270
Conversation
model.Duration is an internal format, generally kong should use time.Duration. What would be the usecase? |
time.Duration doesn't support anything above hours. Therefore it would need a custom wrapper to support |
I am not sure that I'd like to advise large projects like kong to rely on prometheus common given all the direct and indirect dependencies we have. We have complains like #255 already, and I do not want to amplify these. I agree that the code change is small, but it is also using exported interfaces only, such as this could as well be done downstream in kong with the same amount of code:
Would that be an option? (note that it would still have the issue pointed by #255) |
There is no direct dependency with both projects anywhere. Kong won't depend on Prometheus common either. It depends on the package main
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/prometheus/common/model"
)
var CLI struct {
Retention model.Duration `name:"retention" default:"15d" help:"Retention for our app."`
}
func main() {
kong.Parse(&CLI)
fmt.Printf("retention: %d\n", CLI.Retention)
} Only in this downstream application both will be used. Before that there's no dependency with neither as kong depends on |
Okay, can you add a comment about which interface you are implementing? |
Signed-off-by: Matthias Loibl <mail@matthiasloibl.com> This is mostly needed for https://github.com/alecthomas/kong. Furthermore it should be useful for others too, as it implements stdlib interfaces.
cf4d06a
to
ee8cd20
Compare
if c.expectedString == "" { | ||
expectedString = c.in | ||
} | ||
text, _ := d.MarshalText() // MarshalText returns hardcoded nil |
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.
For the future it would have been great to check for error, even if we only return nil.
Thanks!! |
This is mostly needed for https://github.com/alecthomas/kong.
Furthermore it should be useful for others too, as it implements stdlib interfaces.