Skip to content

Commit

Permalink
Update go support to 1.20+1.21
Browse files Browse the repository at this point in the history
Also upgrade thrift to 0.19.0.

Also deprecate errorsbp.Batch.
  • Loading branch information
fishy committed Sep 8, 2023
1 parent 8b80dad commit 09260ba
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
go-version:
- "1.19"
- "1.20"
- "1.21"

container:
image: golang:${{ matrix.go-version }}
Expand Down
7 changes: 4 additions & 3 deletions batchcloser/closers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package batchcloser

import (
"context"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -47,11 +48,11 @@ type BatchCloser struct {
// Close implements io.Closer and closes all of it's internal io.Closer objects,
// batching any errors into an errorsbp.Batch.
func (bc *BatchCloser) Close() error {
var errs errorsbp.Batch
errs := make([]error, 0, len(bc.closers))
for _, closer := range bc.closers {
errs.AddPrefix(fmt.Sprintf("%#v", closer), closer.Close())
errs = append(errs, errorsbp.Prefix(fmt.Sprintf("%#v", closer), closer.Close()))
}
return errs.Compile()
return errors.Join(errs...)
}

// Add adds the given io.Closer objects to the BatchCloser.
Expand Down
2 changes: 1 addition & 1 deletion errorsbp/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
// This type is not thread-safe.
// The same batch should not be operated on different goroutines concurrently.
//
// To be deprecated when we drop support for go 1.19.
// Deprecated: Please use errors.Join or fmt.Errorf with multiple %w instead.
type Batch struct {
errors []error
}
Expand Down
11 changes: 6 additions & 5 deletions filewatcher/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/fsnotify/fsnotify"

"github.com/reddit/baseplate.go/errorsbp"
"github.com/reddit/baseplate.go/internal/limitopen"
"github.com/reddit/baseplate.go/log"
)
Expand Down Expand Up @@ -369,10 +368,12 @@ func New(ctx context.Context, cfg Config) (*Result, error) {
select {
default:
case <-ctx.Done():
var batch errorsbp.Batch
batch.Add(ctx.Err())
batch.AddPrefix("last error", lastErr)
return nil, fmt.Errorf("filewatcher: context canceled while waiting for file(s) under %q to load: %w", cfg.Path, batch.Compile())
return nil, fmt.Errorf(
"filewatcher: context canceled while waiting for file(s) under %q to load: %w, last err: %w",
cfg.Path,
ctx.Err(),
lastErr,
)
}

var err error
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/reddit/baseplate.go

go 1.19
go 1.20

require (
github.com/Shopify/sarama v1.29.1
github.com/alicebob/miniredis/v2 v2.14.3
github.com/apache/thrift v0.17.0
github.com/apache/thrift v0.19.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/fsnotify/fsnotify v1.5.4
github.com/getsentry/sentry-go v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZp
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.14.3 h1:QWoo2wchYmLgOB6ctlTt2dewQ1Vu6phl+iQbwT8SYGo=
github.com/alicebob/miniredis/v2 v2.14.3/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I=
github.com/apache/thrift v0.17.0 h1:cMd2aj52n+8VoAtvSvLn4kDC3aZ6IAkBuqWQ2IDu7wo=
github.com/apache/thrift v0.17.0/go.mod h1:OLxhMRJxomX+1I/KUw03qoV3mMz16BwaKI+d4fPBx7Q=
github.com/apache/thrift v0.19.0 h1:sOqkWPzMj7w6XaYbJQG7m4sGqVolaW/0D28Ln7yPzMk=
github.com/apache/thrift v0.19.0/go.mod h1:SUALL216IiaOw2Oy+5Vs9lboJ/t9g40C+G07Dc0QC1I=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
Expand Down
13 changes: 7 additions & 6 deletions httpbp/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package httpbp

import (
"errors"

"github.com/avast/retry-go"

"github.com/reddit/baseplate.go/breakerbp"
"github.com/reddit/baseplate.go/errorsbp"
)

// ClientConfig provides the configuration for a HTTP client including its
Expand All @@ -19,15 +20,15 @@ type ClientConfig struct {

// Validate checks ClientConfig for any missing or erroneous values.
func (c ClientConfig) Validate() error {
var batch errorsbp.Batch
var errs []error
if c.Slug == "" {
batch.Add(ErrConfigMissingSlug)
errs = append(errs, ErrConfigMissingSlug)
}
if c.MaxErrorReadAhead < 0 {
batch.Add(ErrConfigInvalidMaxErrorReadAhead)
errs = append(errs, ErrConfigInvalidMaxErrorReadAhead)
}
if c.MaxConnections < 0 {
batch.Add(ErrConfigInvalidMaxConnections)
errs = append(errs, ErrConfigInvalidMaxConnections)
}
return batch.Compile()
return errors.Join(errs...)
}
8 changes: 4 additions & 4 deletions httpbp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@ func ClientErrorFromResponse(resp *http.Response) error {
// It's required for http response bodies by stdlib http clients to reuse
// keep-alive connections, so you should always defer it after checking error.
func DrainAndClose(r io.ReadCloser) error {
var batch errorsbp.Batch
_, err := io.Copy(io.Discard, r)
batch.Add(err)
batch.Add(r.Close())
return batch.Compile()
return errors.Join(
errorsbp.Prefix("read fully", err),
errorsbp.Prefix("close", r.Close()),
)
}
21 changes: 10 additions & 11 deletions httpbp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"

"github.com/reddit/baseplate.go"
"github.com/reddit/baseplate.go/errorsbp"

//lint:ignore SA1019 This library is internal only, not actually deprecated
"github.com/reddit/baseplate.go/internalv2compat"
Expand Down Expand Up @@ -92,23 +91,23 @@ type Endpoint struct {
// Validate checks for input errors on the Endpoint and returns an error
// if any exist.
func (e Endpoint) Validate() error {
var err errorsbp.Batch
var errs []error
if e.Name == "" {
err.Add(errors.New("httpbp: Endpoint.Name must be non-empty"))
errs = append(errs, errors.New("httpbp: Endpoint.Name must be non-empty"))
}
if e.Handle == nil {
err.Add(errors.New("httpbp: Endpoint.Handle must be non-nil"))
errs = append(errs, errors.New("httpbp: Endpoint.Handle must be non-nil"))
}
if len(e.Methods) == 0 {
err.Add(errors.New("httpbp: Endpoint.Methods must be non-empty"))
errs = append(errs, errors.New("httpbp: Endpoint.Methods must be non-empty"))
} else {
for _, method := range e.Methods {
if !allHTTPMethods[method] {
err.Add(fmt.Errorf("httpbp: Endpoint.Methods contains an invalid value: %q", method))
errs = append(errs, fmt.Errorf("httpbp: Endpoint.Methods contains an invalid value: %q", method))
}
}
}
return err.Compile()
return errors.Join(errs...)
}

// ServerArgs defines all of the arguments used to create a new HTTP
Expand Down Expand Up @@ -177,20 +176,20 @@ type ServerArgs struct {
// be used for testing purposes. It is called as a part of setting up a new
// Baseplate server.
func (args ServerArgs) ValidateAndSetDefaults() (ServerArgs, error) {
var inputErrors errorsbp.Batch
var errs []error
if args.Baseplate == nil {
inputErrors.Add(errors.New("argument Baseplate must be non-nil"))
errs = append(errs, errors.New("argument Baseplate must be non-nil"))
}
for _, endpoint := range args.Endpoints {
inputErrors.Add(endpoint.Validate())
errs = append(errs, endpoint.Validate())
}
if args.EndpointRegistry == nil {
args.EndpointRegistry = http.NewServeMux()
}
if args.TrustHandler == nil {
args.TrustHandler = NeverTrustHeaders{}
}
return args, inputErrors.Compile()
return args, errors.Join(errs...)
}

// SetupEndpoints calls ValidateAndSetDefaults and registeres the Endpoints
Expand Down
2 changes: 1 addition & 1 deletion internal/gen-go/reddit/baseplate/GoUnusedProtection__.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion internal/gen-go/reddit/baseplate/baseplate-consts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 32 additions & 11 deletions internal/gen-go/reddit/baseplate/baseplate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 09260ba

Please sign in to comment.