diff --git a/go.mod b/go.mod index 33927eb4f..9ab0d9781 100644 --- a/go.mod +++ b/go.mod @@ -162,9 +162,8 @@ require ( github.com/lestrrat-go/dsig v1.0.0 // indirect github.com/lestrrat-go/dsig-secp256k1 v1.0.0 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect - github.com/lestrrat-go/httprc/v3 v3.0.1 // indirect + github.com/lestrrat-go/httprc/v3 v3.0.2 // indirect github.com/lestrrat-go/jwx/v3 v3.0.11 // indirect - github.com/lestrrat-go/option v1.0.1 // indirect github.com/lestrrat-go/option/v2 v2.0.0 // indirect github.com/mattn/go-runewidth v0.0.23 // indirect github.com/mattn/go-shellwords v1.0.12 // indirect diff --git a/go.sum b/go.sum index de58f8635..48b03d37e 100644 --- a/go.sum +++ b/go.sum @@ -379,12 +379,10 @@ github.com/lestrrat-go/dsig-secp256k1 v1.0.0 h1:JpDe4Aybfl0soBvoVwjqDbp+9S1Y2OM7 github.com/lestrrat-go/dsig-secp256k1 v1.0.0/go.mod h1:CxUgAhssb8FToqbL8NjSPoGQlnO4w3LG1P0qPWQm/NU= github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= -github.com/lestrrat-go/httprc/v3 v3.0.1 h1:3n7Es68YYGZb2Jf+k//llA4FTZMl3yCwIjFIk4ubevI= -github.com/lestrrat-go/httprc/v3 v3.0.1/go.mod h1:2uAvmbXE4Xq8kAUjVrZOq1tZVYYYs5iP62Cmtru00xk= +github.com/lestrrat-go/httprc/v3 v3.0.2 h1:7u4HUaD0NQbf2/n5+fyp+T10hNCsAnwKfqn4A4Baif0= +github.com/lestrrat-go/httprc/v3 v3.0.2/go.mod h1:mSMtkZW92Z98M5YoNNztbRGxbXHql7tSitCvaxvo9l0= github.com/lestrrat-go/jwx/v3 v3.0.11 h1:yEeUGNUuNjcez/Voxvr7XPTYNraSQTENJgtVTfwvG/w= github.com/lestrrat-go/jwx/v3 v3.0.11/go.mod h1:XSOAh2SiXm0QgRe3DulLZLyt+wUuEdFo81zuKTLcvgQ= -github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= -github.com/lestrrat-go/option v1.0.1/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmtT7T5nBBp3I= github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLOcID3Ss= github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg= github.com/letsencrypt/boulder v0.20260309.0 h1:kZynrxK3QfqLGx6hhoz+Rfs3hgltJs1p9Mp+4+VwnY0= @@ -540,7 +538,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= diff --git a/vendor/github.com/lestrrat-go/httprc/v3/Changes b/vendor/github.com/lestrrat-go/httprc/v3/Changes index 4dc6f9f4b..6a5eb8064 100644 --- a/vendor/github.com/lestrrat-go/httprc/v3/Changes +++ b/vendor/github.com/lestrrat-go/httprc/v3/Changes @@ -1,6 +1,10 @@ Changes ======= +v3.0.2 05 Dev 2025 +* Code changes mainly due to upgraded linter. +* github.com/lestrrat-go/option upgraded to v2 + v3.0.1 18 Aug 2025 * Refresh() no longer requires the resource to be ready. diff --git a/vendor/github.com/lestrrat-go/httprc/v3/client.go b/vendor/github.com/lestrrat-go/httprc/v3/client.go index 75ac3fc18..05dfbb43f 100644 --- a/vendor/github.com/lestrrat-go/httprc/v3/client.go +++ b/vendor/github.com/lestrrat-go/httprc/v3/client.go @@ -51,6 +51,9 @@ type Client struct { // By default ALL urls are allowed. This may not be suitable for you if // are using this in a production environment. You are encouraged to specify // a whitelist using the `WithWhitelist` option. +// +// NOTE: In future versions, this function signature should be changed to +// return an error to properly handle option parsing failures. func NewClient(options ...NewClientOption) *Client { //nolint:staticcheck var errSink ErrorSink = errsink.NewNop() @@ -63,19 +66,18 @@ func NewClient(options ...NewClientOption) *Client { defaultMaxInterval := DefaultMaxInterval numWorkers := DefaultWorkers - //nolint:forcetypeassert for _, option := range options { switch option.Ident() { case identHTTPClient{}: - httpcl = option.Value().(HTTPClient) + _ = option.Value(&httpcl) case identWorkers{}: - numWorkers = option.Value().(int) + _ = option.Value(&numWorkers) case identErrorSink{}: - errSink = option.Value().(ErrorSink) + _ = option.Value(&errSink) case identTraceSink{}: - traceSink = option.Value().(TraceSink) + _ = option.Value(&traceSink) case identWhitelist{}: - wl = option.Value().(Whitelist) + _ = option.Value(&wl) } } diff --git a/vendor/github.com/lestrrat-go/httprc/v3/controller.go b/vendor/github.com/lestrrat-go/httprc/v3/controller.go index ae2eb218e..1ad9d7b6c 100644 --- a/vendor/github.com/lestrrat-go/httprc/v3/controller.go +++ b/vendor/github.com/lestrrat-go/httprc/v3/controller.go @@ -123,11 +123,12 @@ func (c *controller) Add(ctx context.Context, r Resource, options ...AddOption) c.traceSink.Put(ctx, fmt.Sprintf("httprc controller: START Add(%q)", r.URL())) defer c.traceSink.Put(ctx, fmt.Sprintf("httprc controller: END Add(%q)", r.URL())) waitReady := true - //nolint:forcetypeassert for _, option := range options { switch option.Ident() { case identWaitReady{}: - waitReady = option.(addOption).Value().(bool) + if err := option.Value(&waitReady); err != nil { + return fmt.Errorf(`httprc.Controller.Add: failed to parse WaitReady option: %w`, err) + } } } diff --git a/vendor/github.com/lestrrat-go/httprc/v3/options.go b/vendor/github.com/lestrrat-go/httprc/v3/options.go index 3f07b5671..40cf891b1 100644 --- a/vendor/github.com/lestrrat-go/httprc/v3/options.go +++ b/vendor/github.com/lestrrat-go/httprc/v3/options.go @@ -3,7 +3,7 @@ package httprc import ( "time" - "github.com/lestrrat-go/option" + "github.com/lestrrat-go/option/v2" ) type NewClientOption interface { diff --git a/vendor/github.com/lestrrat-go/httprc/v3/resource.go b/vendor/github.com/lestrrat-go/httprc/v3/resource.go index e637f791f..0f0d140d2 100644 --- a/vendor/github.com/lestrrat-go/httprc/v3/resource.go +++ b/vendor/github.com/lestrrat-go/httprc/v3/resource.go @@ -41,17 +41,24 @@ func NewResource[T any](s string, transformer Transformer[T], options ...NewReso var interval time.Duration minInterval := DefaultMinInterval maxInterval := DefaultMaxInterval - //nolint:forcetypeassert for _, option := range options { switch option.Ident() { case identHTTPClient{}: - httpcl = option.Value().(HTTPClient) + if err := option.Value(&httpcl); err != nil { + return nil, fmt.Errorf(`httprc.NewResource: failed to parse HTTPClient option: %w`, err) + } case identMinimumInterval{}: - minInterval = option.Value().(time.Duration) + if err := option.Value(&minInterval); err != nil { + return nil, fmt.Errorf(`httprc.NewResource: failed to parse MinimumInterval option: %w`, err) + } case identMaximumInterval{}: - maxInterval = option.Value().(time.Duration) + if err := option.Value(&maxInterval); err != nil { + return nil, fmt.Errorf(`httprc.NewResource: failed to parse MaximumInterval option: %w`, err) + } case identConstantInterval{}: - interval = option.Value().(time.Duration) + if err := option.Value(&interval); err != nil { + return nil, fmt.Errorf(`httprc.NewResource: failed to parse ConstantInterval option: %w`, err) + } } } if transformer == nil { @@ -109,7 +116,7 @@ func (r *ResourceBase[T]) Ready(ctx context.Context) error { // returns `A` or `B` depending on the type of the resource. When accessing the // resource through the `httprc.Resource` interface, use this method to obtain the // stored value. -func (r *ResourceBase[T]) Get(dst interface{}) error { +func (r *ResourceBase[T]) Get(dst any) error { return blackmagic.AssignIfCompatible(dst, r.Resource()) } diff --git a/vendor/github.com/lestrrat-go/option/.gitignore b/vendor/github.com/lestrrat-go/option/.gitignore deleted file mode 100644 index 66fd13c90..000000000 --- a/vendor/github.com/lestrrat-go/option/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ diff --git a/vendor/github.com/lestrrat-go/option/LICENSE b/vendor/github.com/lestrrat-go/option/LICENSE deleted file mode 100644 index 188ea7685..000000000 --- a/vendor/github.com/lestrrat-go/option/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 lestrrat-go - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/lestrrat-go/option/README.md b/vendor/github.com/lestrrat-go/option/README.md deleted file mode 100644 index cab0044ed..000000000 --- a/vendor/github.com/lestrrat-go/option/README.md +++ /dev/null @@ -1,245 +0,0 @@ -# option - -Base object for the "Optional Parameters Pattern". - -# DESCRIPTION - -The beauty of this pattern is that you can achieve a method that can -take the following simple calling style - -```go -obj.Method(mandatory1, mandatory2) -``` - -or the following, if you want to modify its behavior with optional parameters - -```go -obj.Method(mandatory1, mandatory2, optional1, optional2, optional3) -``` - -Instead of the more clunky zero value for optionals style - -```go -obj.Method(mandatory1, mandatory2, nil, "", 0) -``` - -or the equally clunky config object style, which requires you to create a -struct with `NamesThatLookReallyLongBecauseItNeedsToIncludeMethodNamesConfig - -```go -cfg := &ConfigForMethod{ - Optional1: ..., - Optional2: ..., - Optional3: ..., -} -obj.Method(mandatory1, mandatory2, &cfg) -``` - -# SYNOPSIS - -Create an "identifier" for the option. We recommend using an unexported empty struct, -because - -1. It is uniquely identifiable globally -1. Takes minimal space -1. Since it's unexported, you do not have to worry about it leaking elsewhere or having it changed by consumers - -```go -// an unexported empty struct -type identFeatureX struct{} -``` - -Then define a method to create an option using this identifier. Here we assume -that the option will be a boolean option. - -```go -// this is optional, but for readability we usually use a wrapper -// around option.Interface, or a type alias. -type Option -func WithFeatureX(v bool) Option { - // use the constructor to create a new option - return option.New(identFeatureX{}, v) -} -``` - -Now you can create an option, which essentially a two element tuple consisting -of an identifier and its associated value. - -To consume this, you will need to create a function with variadic parameters, -and iterate over the list looking for a particular identifier: - -```go -func MyAwesomeFunc( /* mandatory parameters omitted */, options ...[]Option) { - var enableFeatureX bool - // The nolint directive is recommended if you are using linters such - // as golangci-lint - //nolint:forcetypeassert - for _, option := range options { - switch option.Ident() { - case identFeatureX{}: - enableFeatureX = option.Value().(bool) - // other cases omitted - } - } - if enableFeatureX { - .... - } -} -``` - -# Option objects - -Option objects take two arguments, its identifier and the value it contains. - -The identifier can be anything, but it's usually better to use a an unexported -empty struct so that only you have the ability to generate said option: - -```go -type identOptionalParamOne struct{} -type identOptionalParamTwo struct{} -type identOptionalParamThree struct{} - -func WithOptionOne(v ...) Option { - return option.New(identOptionalParamOne{}, v) -} -``` - -Then you can call the method we described above as - -```go -obj.Method(m1, m2, WithOptionOne(...), WithOptionTwo(...), WithOptionThree(...)) -``` - -Options should be parsed in a code that looks somewhat like this - -```go -func (obj *Object) Method(m1 Type1, m2 Type2, options ...Option) { - paramOne := defaultValueParamOne - for _, option := range options { - switch option.Ident() { - case identOptionalParamOne{}: - paramOne = option.Value().(...) - } - } - ... -} -``` - -The loop requires a bit of boilerplate, and admittedly, this is the main downside -of this module. However, if you think you want use the Option as a Function pattern, -please check the FAQ below for rationale. - -# Simple usage - -Most of the times all you need to do is to declare the Option type as an alias -in your code: - -```go -package myawesomepkg - -import "github.com/lestrrat-go/option" - -type Option = option.Interface -``` - -Then you can start defining options like they are described in the SYNOPSIS section. - -# Differentiating Options - -When you have multiple methods and options, and those options can only be passed to -each one the methods, it's hard to see which options should be passed to which method. - -```go -func WithX() Option { ... } -func WithY() Option { ... } - -// Now, which of WithX/WithY go to which method? -func (*Obj) Method1(options ...Option) {} -func (*Obj) Method2(options ...Option) {} -``` - -In this case the easiest way to make it obvious is to put an extra layer around -the options so that they have different types - -```go -type Method1Option interface { - Option - method1Option() -} - -type method1Option struct { Option } -func (*method1Option) method1Option() {} - -func WithX() Method1Option { - return &methodOption{option.New(...)} -} - -func (*Obj) Method1(options ...Method1Option) {} -``` - -This way the compiler knows if an option can be passed to a given method. - -# FAQ - -## Why aren't these function-based? - -Using a base option type like `type Option func(ctx interface{})` is certainly one way to achieve the same goal. In this case, you are giving the option itself the ability to "configure" the main object. For example: - -```go -type Foo struct { - optionaValue bool -} - -type Option func(*Foo) error - -func WithOptionalValue(v bool) Option { - return Option(func(f *Foo) error { - f.optionalValue = v - return nil - }) -} - -func NewFoo(options ...Option) (*Foo, error) { - var f Foo - for _, o := range options { - if err := o(&f); err != nil { - return nil, err - } - } - return &f -} -``` - -This in itself is fine, but we think there are a few problems: - -### 1. It's hard to create a reusable "Option" type - -We create many libraries using this optional pattern. We would like to provide a default base object. However, this function based approach is not reusuable because each "Option" type requires that it has a context-specific input type. For example, if the "Option" type in the previous example was `func(interface{}) error`, then its usability will significantly decrease because of the type conversion. - -This is not to say that this library's approach is better as it also requires type conversion to convert the _value_ of the option. However, part of the beauty of the original function based approach was the ease of its use, and we claim that this significantly decreases the merits of the function based approach. - -### 2. The receiver requires exported fields - -Part of the appeal for a function-based option pattern is by giving the option itself the ability to do what it wants, you open up the possibility of allowing third-parties to create options that do things that the library authors did not think about. - -```go -package thirdparty -, but when I read drum sheet music, I kind of get thrown off b/c many times it says to hit the bass drum where I feel like it's a snare hit. -func WithMyAwesomeOption( ... ) mypkg.Option { - return mypkg.Option(func(f *mypkg) error { - f.X = ... - f.Y = ... - f.Z = ... - return nil - }) -} -``` - -However, for any third party code to access and set field values, these fields (`X`, `Y`, `Z`) must be exported. Basically you will need an "open" struct. - -Exported fields are absolutely no problem when you have a struct that represents data alone (i.e., API calls that refer or change state information) happen, but we think that casually expose fields for a library struct is a sure way to maintenance hell in the future. What happens when you want to change the API? What happens when you realize that you want to use the field as state (i.e. use it for more than configuration)? What if they kept referring to that field, and then you have concurrent code accessing it? - -Giving third parties complete access to exported fields is like handing out a loaded weapon to the users, and you are at their mercy. - -Of course, providing public APIs for everything so you can validate and control concurrency is an option, but then ... it's a lot of work, and you may have to provide APIs _only_ so that users can refer it in the option-configuration phase. That sounds like a lot of extra work. - diff --git a/vendor/github.com/lestrrat-go/option/option.go b/vendor/github.com/lestrrat-go/option/option.go deleted file mode 100644 index bfdbb118c..000000000 --- a/vendor/github.com/lestrrat-go/option/option.go +++ /dev/null @@ -1,38 +0,0 @@ -package option - -import "fmt" - -// Interface defines the minimum interface that an option must fulfill -type Interface interface { - // Ident returns the "identity" of this option, a unique identifier that - // can be used to differentiate between options - Ident() interface{} - - // Value returns the corresponding value. - Value() interface{} -} - -type pair struct { - ident interface{} - value interface{} -} - -// New creates a new Option -func New(ident, value interface{}) Interface { - return &pair{ - ident: ident, - value: value, - } -} - -func (p *pair) Ident() interface{} { - return p.ident -} - -func (p *pair) Value() interface{} { - return p.value -} - -func (p *pair) String() string { - return fmt.Sprintf(`%v(%v)`, p.ident, p.value) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index c6269b7d2..71db3bc49 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -599,7 +599,7 @@ github.com/lestrrat-go/dsig-secp256k1 # github.com/lestrrat-go/httpcc v1.0.1 ## explicit; go 1.16 github.com/lestrrat-go/httpcc -# github.com/lestrrat-go/httprc/v3 v3.0.1 +# github.com/lestrrat-go/httprc/v3 v3.0.2 ## explicit; go 1.23.0 github.com/lestrrat-go/httprc/v3 github.com/lestrrat-go/httprc/v3/errsink @@ -635,9 +635,6 @@ github.com/lestrrat-go/jwx/v3/jwt github.com/lestrrat-go/jwx/v3/jwt/internal/errors github.com/lestrrat-go/jwx/v3/jwt/internal/types github.com/lestrrat-go/jwx/v3/transform -# github.com/lestrrat-go/option v1.0.1 -## explicit; go 1.16 -github.com/lestrrat-go/option # github.com/lestrrat-go/option/v2 v2.0.0 ## explicit; go 1.23 github.com/lestrrat-go/option/v2