Skip to content
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 regexp.Regexp support #7

Merged
merged 1 commit into from
Aug 4, 2021
Merged

Add regexp.Regexp support #7

merged 1 commit into from
Aug 4, 2021

Conversation

jparise
Copy link
Contributor

@jparise jparise commented May 17, 2021

It's useful to support validated regular expressions in configuration.
Previously, we could represent these fields as raw pattern strings and
compile them in application code. By supporting Regexp as a first-class
field type, we get a smaller application code and more immediate error
reporting without complicating the API.

@jparise
Copy link
Contributor Author

jparise commented Jul 20, 2021

@kkyr just wanted to check in and ask if you'd consider including this.

@kkyr
Copy link
Owner

kkyr commented Jul 26, 2021

Hi @jparise, big thanks for the CR and apologies for the delay. I wasn't monitoring this account.

Can you share the use case for having regex in an application's configuration?

@jparise
Copy link
Contributor Author

jparise commented Jul 26, 2021

@kkyr
Copy link
Owner

kkyr commented Jul 30, 2021

I'm OK adding this, however there are some things that need to be addressed in the CR first:

  • util_test.go: test isZero() with nil and non-nil regexp
  • examples/config/config_test.go: add example reading it from file
  • doc.go#193: add field with regexp
  • doc.go#L227: add regexp

@jparise
Copy link
Contributor Author

jparise commented Aug 3, 2021

I'm OK adding this, however there are some things that need to be addressed in the CR first

Thanks for the feedback! I believe I've addressed all of these items.

It's useful to support validated regular expressions in configuration
files. Previously, we could represent these fields as raw pattern
strings and compile them in application code. By supporting Regexp as a
first-class field type, we get a smaller application code and more
immediate error reporting without complicating the API.
@@ -206,7 +207,7 @@ See example below to help understand:

err := fig.Load(&cfg)
fmt.Print(err)
// A: required, B: required, C: required, D: required, E: required, G: required, H.J: required, K: required, M: required
// A: required validation failed, B: required validation failed, C: required validation failed, D: required validation failed, E: required validation failed, G: required validation failed, H.J: required validation failed, K: required validation failed, M: required validation failed, N: required validation failed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating to the latest error message

@kkyr kkyr merged commit 9422805 into kkyr:master Aug 4, 2021
@kkyr
Copy link
Owner

kkyr commented Aug 4, 2021

Merged. I'll include it in a new release that also bumps Go to 1.16.

Thanks again for the PR!

@jparise jparise deleted the regexp branch August 5, 2021 03:30
@jparise
Copy link
Contributor Author

jparise commented Aug 6, 2021

Merged. I'll include it in a new release that also bumps Go to 1.16.

It looks like you've made those updates. Are you still planning on tagging a new release, too?

Thanks again for the PR!

Sure thing!

@kkyr
Copy link
Owner

kkyr commented Aug 6, 2021

Yes, I’ll tag it this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants