github.com/lestrrat-go/jwx/v2@v2.0.21/jwk/options.go (about)

     1  package jwk
     2  
     3  import (
     4  	"github.com/lestrrat-go/option"
     5  )
     6  
     7  type identTypedField struct{}
     8  
     9  type typedFieldPair struct {
    10  	Name  string
    11  	Value interface{}
    12  }
    13  
    14  // WithTypedField allows a private field to be parsed into the object type of
    15  // your choice. It works much like the RegisterCustomField, but the effect
    16  // is only applicable to the jwt.Parse function call which receives this option.
    17  //
    18  // While this can be extremely useful, this option should be used with caution:
    19  // There are many caveats that your entire team/user-base needs to be aware of,
    20  // and therefore in general its use is discouraged. Only use it when you know
    21  // what you are doing, and you document its use clearly for others.
    22  //
    23  // First and foremost, this is a "per-object" option. Meaning that given the same
    24  // serialized format, it is possible to generate two objects whose internal
    25  // representations may differ. That is, if you parse one _WITH_ the option,
    26  // and the other _WITHOUT_, their internal representation may completely differ.
    27  // This could potentially lead to problems.
    28  //
    29  // Second, specifying this option will slightly slow down the decoding process
    30  // as it needs to consult multiple definitions sources (global and local), so
    31  // be careful if you are decoding a large number of tokens, as the effects will stack up.
    32  func WithTypedField(name string, object interface{}) ParseOption {
    33  	return &parseOption{
    34  		option.New(identTypedField{},
    35  			typedFieldPair{Name: name, Value: object},
    36  		),
    37  	}
    38  }