Skip to content

Commit

Permalink
Added some more documentation, why types are not exported
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Mar 7, 2022
1 parent 1bbb42b commit b3d52c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions claims.go
Expand Up @@ -9,6 +9,9 @@ import (
// Claims must just have a Valid method that determines
// if the token is invalid for any supported reason
type Claims interface {
// Valid implements claim validation. The opts are function style options that can
// be used to fine-tune the validation. The type used for the options is intentionally
// un-exported, since its API and its naming is subject to change.
Valid(opts ...validationOption) error
}

Expand Down
2 changes: 1 addition & 1 deletion parser_option.go
Expand Up @@ -33,6 +33,6 @@ func WithoutClaimsValidation() ParserOption {
// WithLeeway returns the ParserOption for specifying the leeway window.
func WithLeeway(d time.Duration) ParserOption {
return func(p *Parser) {
p.validationOptions = append(p.validationOptions, withLeewayValidator(d))
p.validationOptions = append(p.validationOptions, withLeeway(d))
}
}
16 changes: 12 additions & 4 deletions validator_option.go
Expand Up @@ -4,17 +4,25 @@ import "time"

// validationOption is used to implement functional-style options that modify the behavior of the parser. To add
// new options, just create a function (ideally beginning with With or Without) that returns an anonymous function that
// takes a *ValidatorOptions type as input and manipulates its configuration accordingly.
// takes a *validator type as input and manipulates its configuration accordingly.
//
// Note that this struct is (currently) un-exported, its naming is subject to change and will only be exported once
// the API is more stable.
type validationOption func(*validator)

// validator represents options that can be used for claims validation
//
// Note that this struct is (currently) un-exported, its naming is subject to change and will only be exported once
// the API is more stable.
type validator struct {
leeway time.Duration // Leeway to provide when validating time values
}


// withLeewayValidator is an option to set the clock skew (leeway) windows
func withLeewayValidator(d time.Duration) validationOption {
// withLeeway is an option to set the clock skew (leeway) window
//
// Note that this function is (currently) un-exported, its naming is subject to change and will only be exported once
// the API is more stable.
func withLeeway(d time.Duration) validationOption {
return func(v *validator) {
v.leeway = d
}
Expand Down

0 comments on commit b3d52c5

Please sign in to comment.