mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 15:38:06 +00:00
Update Go version and package dependencies
This commit is contained in:
16
vendor/go.uber.org/multierr/CHANGELOG.md
generated
vendored
16
vendor/go.uber.org/multierr/CHANGELOG.md
generated
vendored
@@ -1,6 +1,22 @@
|
||||
Releases
|
||||
========
|
||||
|
||||
v1.10.0 (2023-03-08)
|
||||
====================
|
||||
|
||||
- Comply with Go 1.20's multiple-error interface.
|
||||
- Drop Go 1.18 support.
|
||||
Per the support policy, only Go 1.19 and 1.20 are supported now.
|
||||
- Drop all non-test external dependencies.
|
||||
|
||||
v1.9.0 (2022-12-12)
|
||||
===================
|
||||
|
||||
- Add `AppendFunc` that allow passsing functions to similar to
|
||||
`AppendInvoke`.
|
||||
|
||||
- Bump up yaml.v3 dependency to 3.0.1.
|
||||
|
||||
v1.8.0 (2022-02-28)
|
||||
===================
|
||||
|
||||
|
22
vendor/go.uber.org/multierr/README.md
generated
vendored
22
vendor/go.uber.org/multierr/README.md
generated
vendored
@@ -2,9 +2,29 @@
|
||||
|
||||
`multierr` allows combining one or more Go `error`s together.
|
||||
|
||||
## Features
|
||||
|
||||
- **Idiomatic**:
|
||||
multierr follows best practices in Go, and keeps your code idiomatic.
|
||||
- It keeps the underlying error type hidden,
|
||||
allowing you to deal in `error` values exclusively.
|
||||
- It provides APIs to safely append into an error from a `defer` statement.
|
||||
- **Performant**:
|
||||
multierr is optimized for performance:
|
||||
- It avoids allocations where possible.
|
||||
- It utilizes slice resizing semantics to optimize common cases
|
||||
like appending into the same error object from a loop.
|
||||
- **Interoperable**:
|
||||
multierr interoperates with the Go standard library's error APIs seamlessly:
|
||||
- The `errors.Is` and `errors.As` functions *just work*.
|
||||
- **Lightweight**:
|
||||
multierr comes with virtually no dependencies.
|
||||
|
||||
## Installation
|
||||
|
||||
go get -u go.uber.org/multierr
|
||||
```bash
|
||||
go get -u go.uber.org/multierr@latest
|
||||
```
|
||||
|
||||
## Status
|
||||
|
||||
|
378
vendor/go.uber.org/multierr/error.go
generated
vendored
378
vendor/go.uber.org/multierr/error.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2017-2021 Uber Technologies, Inc.
|
||||
// Copyright (c) 2017-2023 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -20,106 +20,109 @@
|
||||
|
||||
// Package multierr allows combining one or more errors together.
|
||||
//
|
||||
// Overview
|
||||
// # Overview
|
||||
//
|
||||
// Errors can be combined with the use of the Combine function.
|
||||
//
|
||||
// multierr.Combine(
|
||||
// reader.Close(),
|
||||
// writer.Close(),
|
||||
// conn.Close(),
|
||||
// )
|
||||
// multierr.Combine(
|
||||
// reader.Close(),
|
||||
// writer.Close(),
|
||||
// conn.Close(),
|
||||
// )
|
||||
//
|
||||
// If only two errors are being combined, the Append function may be used
|
||||
// instead.
|
||||
//
|
||||
// err = multierr.Append(reader.Close(), writer.Close())
|
||||
// err = multierr.Append(reader.Close(), writer.Close())
|
||||
//
|
||||
// The underlying list of errors for a returned error object may be retrieved
|
||||
// with the Errors function.
|
||||
//
|
||||
// errors := multierr.Errors(err)
|
||||
// if len(errors) > 0 {
|
||||
// fmt.Println("The following errors occurred:", errors)
|
||||
// }
|
||||
// errors := multierr.Errors(err)
|
||||
// if len(errors) > 0 {
|
||||
// fmt.Println("The following errors occurred:", errors)
|
||||
// }
|
||||
//
|
||||
// Appending from a loop
|
||||
// # Appending from a loop
|
||||
//
|
||||
// You sometimes need to append into an error from a loop.
|
||||
//
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// err = multierr.Append(err, process(item))
|
||||
// }
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// err = multierr.Append(err, process(item))
|
||||
// }
|
||||
//
|
||||
// Cases like this may require knowledge of whether an individual instance
|
||||
// failed. This usually requires introduction of a new variable.
|
||||
//
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// if perr := process(item); perr != nil {
|
||||
// log.Warn("skipping item", item)
|
||||
// err = multierr.Append(err, perr)
|
||||
// }
|
||||
// }
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// if perr := process(item); perr != nil {
|
||||
// log.Warn("skipping item", item)
|
||||
// err = multierr.Append(err, perr)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// multierr includes AppendInto to simplify cases like this.
|
||||
//
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// if multierr.AppendInto(&err, process(item)) {
|
||||
// log.Warn("skipping item", item)
|
||||
// }
|
||||
// }
|
||||
// var err error
|
||||
// for _, item := range items {
|
||||
// if multierr.AppendInto(&err, process(item)) {
|
||||
// log.Warn("skipping item", item)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// This will append the error into the err variable, and return true if that
|
||||
// individual error was non-nil.
|
||||
//
|
||||
// See AppendInto for more information.
|
||||
// See [AppendInto] for more information.
|
||||
//
|
||||
// Deferred Functions
|
||||
// # Deferred Functions
|
||||
//
|
||||
// Go makes it possible to modify the return value of a function in a defer
|
||||
// block if the function was using named returns. This makes it possible to
|
||||
// record resource cleanup failures from deferred blocks.
|
||||
//
|
||||
// func sendRequest(req Request) (err error) {
|
||||
// conn, err := openConnection()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer func() {
|
||||
// err = multierr.Append(err, conn.Close())
|
||||
// }()
|
||||
// // ...
|
||||
// }
|
||||
// func sendRequest(req Request) (err error) {
|
||||
// conn, err := openConnection()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer func() {
|
||||
// err = multierr.Append(err, conn.Close())
|
||||
// }()
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// multierr provides the Invoker type and AppendInvoke function to make cases
|
||||
// like the above simpler and obviate the need for a closure. The following is
|
||||
// roughly equivalent to the example above.
|
||||
//
|
||||
// func sendRequest(req Request) (err error) {
|
||||
// conn, err := openConnection()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(conn))
|
||||
// // ...
|
||||
// }
|
||||
// func sendRequest(req Request) (err error) {
|
||||
// conn, err := openConnection()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(conn))
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// See AppendInvoke and Invoker for more information.
|
||||
// See [AppendInvoke] and [Invoker] for more information.
|
||||
//
|
||||
// Advanced Usage
|
||||
// NOTE: If you're modifying an error from inside a defer, you MUST use a named
|
||||
// return value for that function.
|
||||
//
|
||||
// # Advanced Usage
|
||||
//
|
||||
// Errors returned by Combine and Append MAY implement the following
|
||||
// interface.
|
||||
//
|
||||
// type errorGroup interface {
|
||||
// // Returns a slice containing the underlying list of errors.
|
||||
// //
|
||||
// // This slice MUST NOT be modified by the caller.
|
||||
// Errors() []error
|
||||
// }
|
||||
// type errorGroup interface {
|
||||
// // Returns a slice containing the underlying list of errors.
|
||||
// //
|
||||
// // This slice MUST NOT be modified by the caller.
|
||||
// Errors() []error
|
||||
// }
|
||||
//
|
||||
// Note that if you need access to list of errors behind a multierr error, you
|
||||
// should prefer using the Errors function. That said, if you need cheap
|
||||
@@ -128,24 +131,22 @@
|
||||
// because errors returned by Combine and Append are not guaranteed to
|
||||
// implement this interface.
|
||||
//
|
||||
// var errors []error
|
||||
// group, ok := err.(errorGroup)
|
||||
// if ok {
|
||||
// errors = group.Errors()
|
||||
// } else {
|
||||
// errors = []error{err}
|
||||
// }
|
||||
// var errors []error
|
||||
// group, ok := err.(errorGroup)
|
||||
// if ok {
|
||||
// errors = group.Errors()
|
||||
// } else {
|
||||
// errors = []error{err}
|
||||
// }
|
||||
package multierr // import "go.uber.org/multierr"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/atomic"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -185,8 +186,8 @@ type errorGroup interface {
|
||||
// Errors returns a slice containing zero or more errors that the supplied
|
||||
// error is composed of. If the error is nil, a nil slice is returned.
|
||||
//
|
||||
// err := multierr.Append(r.Close(), w.Close())
|
||||
// errors := multierr.Errors(err)
|
||||
// err := multierr.Append(r.Close(), w.Close())
|
||||
// errors := multierr.Errors(err)
|
||||
//
|
||||
// If the error is not composed of other errors, the returned slice contains
|
||||
// just the error that was passed in.
|
||||
@@ -209,10 +210,7 @@ func Errors(err error) []error {
|
||||
return []error{err}
|
||||
}
|
||||
|
||||
errors := eg.Errors()
|
||||
result := make([]error, len(errors))
|
||||
copy(result, errors)
|
||||
return result
|
||||
return append(([]error)(nil), eg.Errors()...)
|
||||
}
|
||||
|
||||
// multiError is an error that holds one or more errors.
|
||||
@@ -239,33 +237,6 @@ func (merr *multiError) Errors() []error {
|
||||
return merr.errors
|
||||
}
|
||||
|
||||
// As attempts to find the first error in the error list that matches the type
|
||||
// of the value that target points to.
|
||||
//
|
||||
// This function allows errors.As to traverse the values stored on the
|
||||
// multierr error.
|
||||
func (merr *multiError) As(target interface{}) bool {
|
||||
for _, err := range merr.Errors() {
|
||||
if errors.As(err, target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Is attempts to match the provided error against errors in the error list.
|
||||
//
|
||||
// This function allows errors.Is to traverse the values stored on the
|
||||
// multierr error.
|
||||
func (merr *multiError) Is(target error) bool {
|
||||
for _, err := range merr.Errors() {
|
||||
if errors.Is(err, target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (merr *multiError) Error() string {
|
||||
if merr == nil {
|
||||
return ""
|
||||
@@ -393,8 +364,7 @@ func fromSlice(errors []error) error {
|
||||
// Otherwise "errors" escapes to the heap
|
||||
// unconditionally for all other cases.
|
||||
// This lets us optimize for the "no errors" case.
|
||||
out := make([]error, len(errors))
|
||||
copy(out, errors)
|
||||
out := append(([]error)(nil), errors...)
|
||||
return &multiError{errors: out}
|
||||
}
|
||||
}
|
||||
@@ -420,32 +390,32 @@ func fromSlice(errors []error) error {
|
||||
// If zero arguments were passed or if all items are nil, a nil error is
|
||||
// returned.
|
||||
//
|
||||
// Combine(nil, nil) // == nil
|
||||
// Combine(nil, nil) // == nil
|
||||
//
|
||||
// If only a single error was passed, it is returned as-is.
|
||||
//
|
||||
// Combine(err) // == err
|
||||
// Combine(err) // == err
|
||||
//
|
||||
// Combine skips over nil arguments so this function may be used to combine
|
||||
// together errors from operations that fail independently of each other.
|
||||
//
|
||||
// multierr.Combine(
|
||||
// reader.Close(),
|
||||
// writer.Close(),
|
||||
// pipe.Close(),
|
||||
// )
|
||||
// multierr.Combine(
|
||||
// reader.Close(),
|
||||
// writer.Close(),
|
||||
// pipe.Close(),
|
||||
// )
|
||||
//
|
||||
// If any of the passed errors is a multierr error, it will be flattened along
|
||||
// with the other errors.
|
||||
//
|
||||
// multierr.Combine(multierr.Combine(err1, err2), err3)
|
||||
// // is the same as
|
||||
// multierr.Combine(err1, err2, err3)
|
||||
// multierr.Combine(multierr.Combine(err1, err2), err3)
|
||||
// // is the same as
|
||||
// multierr.Combine(err1, err2, err3)
|
||||
//
|
||||
// The returned error formats into a readable multi-line error message if
|
||||
// formatted with %+v.
|
||||
//
|
||||
// fmt.Sprintf("%+v", multierr.Combine(err1, err2))
|
||||
// fmt.Sprintf("%+v", multierr.Combine(err1, err2))
|
||||
func Combine(errors ...error) error {
|
||||
return fromSlice(errors)
|
||||
}
|
||||
@@ -455,16 +425,19 @@ func Combine(errors ...error) error {
|
||||
// This function is a specialization of Combine for the common case where
|
||||
// there are only two errors.
|
||||
//
|
||||
// err = multierr.Append(reader.Close(), writer.Close())
|
||||
// err = multierr.Append(reader.Close(), writer.Close())
|
||||
//
|
||||
// The following pattern may also be used to record failure of deferred
|
||||
// operations without losing information about the original error.
|
||||
//
|
||||
// func doSomething(..) (err error) {
|
||||
// f := acquireResource()
|
||||
// defer func() {
|
||||
// err = multierr.Append(err, f.Close())
|
||||
// }()
|
||||
// func doSomething(..) (err error) {
|
||||
// f := acquireResource()
|
||||
// defer func() {
|
||||
// err = multierr.Append(err, f.Close())
|
||||
// }()
|
||||
//
|
||||
// Note that the variable MUST be a named return to append an error to it from
|
||||
// the defer statement. See also [AppendInvoke].
|
||||
func Append(left error, right error) error {
|
||||
switch {
|
||||
case left == nil:
|
||||
@@ -494,37 +467,37 @@ func Append(left error, right error) error {
|
||||
// AppendInto appends an error into the destination of an error pointer and
|
||||
// returns whether the error being appended was non-nil.
|
||||
//
|
||||
// var err error
|
||||
// multierr.AppendInto(&err, r.Close())
|
||||
// multierr.AppendInto(&err, w.Close())
|
||||
// var err error
|
||||
// multierr.AppendInto(&err, r.Close())
|
||||
// multierr.AppendInto(&err, w.Close())
|
||||
//
|
||||
// The above is equivalent to,
|
||||
//
|
||||
// err := multierr.Append(r.Close(), w.Close())
|
||||
// err := multierr.Append(r.Close(), w.Close())
|
||||
//
|
||||
// As AppendInto reports whether the provided error was non-nil, it may be
|
||||
// used to build a multierr error in a loop more ergonomically. For example:
|
||||
//
|
||||
// var err error
|
||||
// for line := range lines {
|
||||
// var item Item
|
||||
// if multierr.AppendInto(&err, parse(line, &item)) {
|
||||
// continue
|
||||
// }
|
||||
// items = append(items, item)
|
||||
// }
|
||||
// var err error
|
||||
// for line := range lines {
|
||||
// var item Item
|
||||
// if multierr.AppendInto(&err, parse(line, &item)) {
|
||||
// continue
|
||||
// }
|
||||
// items = append(items, item)
|
||||
// }
|
||||
//
|
||||
// Compare this with a version that relies solely on Append:
|
||||
//
|
||||
// var err error
|
||||
// for line := range lines {
|
||||
// var item Item
|
||||
// if parseErr := parse(line, &item); parseErr != nil {
|
||||
// err = multierr.Append(err, parseErr)
|
||||
// continue
|
||||
// }
|
||||
// items = append(items, item)
|
||||
// }
|
||||
// var err error
|
||||
// for line := range lines {
|
||||
// var item Item
|
||||
// if parseErr := parse(line, &item); parseErr != nil {
|
||||
// err = multierr.Append(err, parseErr)
|
||||
// continue
|
||||
// }
|
||||
// items = append(items, item)
|
||||
// }
|
||||
func AppendInto(into *error, err error) (errored bool) {
|
||||
if into == nil {
|
||||
// We panic if 'into' is nil. This is not documented above
|
||||
@@ -545,7 +518,7 @@ func AppendInto(into *error, err error) (errored bool) {
|
||||
// AppendInvoke to append the result of calling the function into an error.
|
||||
// This allows you to conveniently defer capture of failing operations.
|
||||
//
|
||||
// See also, Close and Invoke.
|
||||
// See also, [Close] and [Invoke].
|
||||
type Invoker interface {
|
||||
Invoke() error
|
||||
}
|
||||
@@ -556,19 +529,22 @@ type Invoker interface {
|
||||
//
|
||||
// For example,
|
||||
//
|
||||
// func processReader(r io.Reader) (err error) {
|
||||
// scanner := bufio.NewScanner(r)
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
// for scanner.Scan() {
|
||||
// // ...
|
||||
// }
|
||||
// // ...
|
||||
// }
|
||||
// func processReader(r io.Reader) (err error) {
|
||||
// scanner := bufio.NewScanner(r)
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
// for scanner.Scan() {
|
||||
// // ...
|
||||
// }
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// In this example, the following line will construct the Invoker right away,
|
||||
// but defer the invocation of scanner.Err() until the function returns.
|
||||
//
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
//
|
||||
// Note that the error you're appending to from the defer statement MUST be a
|
||||
// named return.
|
||||
type Invoke func() error
|
||||
|
||||
// Invoke calls the supplied function and returns its result.
|
||||
@@ -579,19 +555,22 @@ func (i Invoke) Invoke() error { return i() }
|
||||
//
|
||||
// For example,
|
||||
//
|
||||
// func processFile(path string) (err error) {
|
||||
// f, err := os.Open(path)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
// return processReader(f)
|
||||
// }
|
||||
// func processFile(path string) (err error) {
|
||||
// f, err := os.Open(path)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
// return processReader(f)
|
||||
// }
|
||||
//
|
||||
// In this example, multierr.Close will construct the Invoker right away, but
|
||||
// defer the invocation of f.Close until the function returns.
|
||||
//
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
//
|
||||
// Note that the error you're appending to from the defer statement MUST be a
|
||||
// named return.
|
||||
func Close(closer io.Closer) Invoker {
|
||||
return Invoke(closer.Close)
|
||||
}
|
||||
@@ -601,52 +580,73 @@ func Close(closer io.Closer) Invoker {
|
||||
// invocation of fallible operations until a function returns, and capture the
|
||||
// resulting errors.
|
||||
//
|
||||
// func doSomething(...) (err error) {
|
||||
// // ...
|
||||
// f, err := openFile(..)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// func doSomething(...) (err error) {
|
||||
// // ...
|
||||
// f, err := openFile(..)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// // multierr will call f.Close() when this function returns and
|
||||
// // if the operation fails, its append its error into the
|
||||
// // returned error.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
// // multierr will call f.Close() when this function returns and
|
||||
// // if the operation fails, its append its error into the
|
||||
// // returned error.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Close(f))
|
||||
//
|
||||
// scanner := bufio.NewScanner(f)
|
||||
// // Similarly, this scheduled scanner.Err to be called and
|
||||
// // inspected when the function returns and append its error
|
||||
// // into the returned error.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
// scanner := bufio.NewScanner(f)
|
||||
// // Similarly, this scheduled scanner.Err to be called and
|
||||
// // inspected when the function returns and append its error
|
||||
// // into the returned error.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(scanner.Err))
|
||||
//
|
||||
// // ...
|
||||
// }
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// NOTE: If used with a defer, the error variable MUST be a named return.
|
||||
//
|
||||
// Without defer, AppendInvoke behaves exactly like AppendInto.
|
||||
//
|
||||
// err := // ...
|
||||
// multierr.AppendInvoke(&err, mutltierr.Invoke(foo))
|
||||
// err := // ...
|
||||
// multierr.AppendInvoke(&err, mutltierr.Invoke(foo))
|
||||
//
|
||||
// // ...is roughly equivalent to...
|
||||
// // ...is roughly equivalent to...
|
||||
//
|
||||
// err := // ...
|
||||
// multierr.AppendInto(&err, foo())
|
||||
// err := // ...
|
||||
// multierr.AppendInto(&err, foo())
|
||||
//
|
||||
// The advantage of the indirection introduced by Invoker is to make it easy
|
||||
// to defer the invocation of a function. Without this indirection, the
|
||||
// invoked function will be evaluated at the time of the defer block rather
|
||||
// than when the function returns.
|
||||
//
|
||||
// // BAD: This is likely not what the caller intended. This will evaluate
|
||||
// // foo() right away and append its result into the error when the
|
||||
// // function returns.
|
||||
// defer multierr.AppendInto(&err, foo())
|
||||
// // BAD: This is likely not what the caller intended. This will evaluate
|
||||
// // foo() right away and append its result into the error when the
|
||||
// // function returns.
|
||||
// defer multierr.AppendInto(&err, foo())
|
||||
//
|
||||
// // GOOD: This will defer invocation of foo unutil the function returns.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(foo))
|
||||
// // GOOD: This will defer invocation of foo unutil the function returns.
|
||||
// defer multierr.AppendInvoke(&err, multierr.Invoke(foo))
|
||||
//
|
||||
// multierr provides a few Invoker implementations out of the box for
|
||||
// convenience. See Invoker for more information.
|
||||
// convenience. See [Invoker] for more information.
|
||||
func AppendInvoke(into *error, invoker Invoker) {
|
||||
AppendInto(into, invoker.Invoke())
|
||||
}
|
||||
|
||||
// AppendFunc is a shorthand for [AppendInvoke].
|
||||
// It allows using function or method value directly
|
||||
// without having to wrap it into an [Invoker] interface.
|
||||
//
|
||||
// func doSomething(...) (err error) {
|
||||
// w, err := startWorker(...)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// // multierr will call w.Stop() when this function returns and
|
||||
// // if the operation fails, it appends its error into the
|
||||
// // returned error.
|
||||
// defer multierr.AppendFunc(&err, w.Stop)
|
||||
// }
|
||||
func AppendFunc(into *error, fn func() error) {
|
||||
AppendInvoke(into, Invoke(fn))
|
||||
}
|
||||
|
29
vendor/go.uber.org/multierr/error_post_go120.go
generated
vendored
Normal file
29
vendor/go.uber.org/multierr/error_post_go120.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2017-2023 Uber Technologies, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
//go:build go1.20
|
||||
// +build go1.20
|
||||
|
||||
package multierr
|
||||
|
||||
// Unwrap returns a list of errors wrapped by this multierr.
|
||||
func (merr *multiError) Unwrap() []error {
|
||||
return merr.Errors()
|
||||
}
|
59
vendor/go.uber.org/multierr/error_pre_go120.go
generated
vendored
Normal file
59
vendor/go.uber.org/multierr/error_pre_go120.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2017-2023 Uber Technologies, Inc.
|
||||
//
|
||||
// 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.
|
||||
|
||||
//go:build !go1.20
|
||||
// +build !go1.20
|
||||
|
||||
package multierr
|
||||
|
||||
import "errors"
|
||||
|
||||
// Versions of Go before 1.20 did not support the Unwrap() []error method.
|
||||
// This provides a similar behavior by implementing the Is(..) and As(..)
|
||||
// methods.
|
||||
// See the errors.Join proposal for details:
|
||||
// https://github.com/golang/go/issues/53435
|
||||
|
||||
// As attempts to find the first error in the error list that matches the type
|
||||
// of the value that target points to.
|
||||
//
|
||||
// This function allows errors.As to traverse the values stored on the
|
||||
// multierr error.
|
||||
func (merr *multiError) As(target interface{}) bool {
|
||||
for _, err := range merr.Errors() {
|
||||
if errors.As(err, target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Is attempts to match the provided error against errors in the error list.
|
||||
//
|
||||
// This function allows errors.Is to traverse the values stored on the
|
||||
// multierr error.
|
||||
func (merr *multiError) Is(target error) bool {
|
||||
for _, err := range merr.Errors() {
|
||||
if errors.Is(err, target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
8
vendor/go.uber.org/multierr/glide.yaml
generated
vendored
8
vendor/go.uber.org/multierr/glide.yaml
generated
vendored
@@ -1,8 +0,0 @@
|
||||
package: go.uber.org/multierr
|
||||
import:
|
||||
- package: go.uber.org/atomic
|
||||
version: ^1
|
||||
testImport:
|
||||
- package: github.com/stretchr/testify
|
||||
subpackages:
|
||||
- assert
|
13
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
13
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
@@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.24.0 (30 Nov 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1148][]: Add `Level` to both `Logger` and `SugaredLogger` that reports the
|
||||
current minimum enabled log level.
|
||||
* [#1185][]: `SugaredLogger` turns errors to zap.Error automatically.
|
||||
|
||||
Thanks to @Abirdcfly, @craigpastro, @nnnkkk7, and @sashamelentyev for their
|
||||
contributions to this release.
|
||||
|
||||
[#1148]: https://github.coml/uber-go/zap/pull/1148
|
||||
[#1185]: https://github.coml/uber-go/zap/pull/1185
|
||||
|
||||
## 1.23.0 (24 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
|
8
vendor/go.uber.org/zap/array_go118.go
generated
vendored
8
vendor/go.uber.org/zap/array_go118.go
generated
vendored
@@ -76,9 +76,9 @@ func (os objects[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// objectMarshalerPtr is a constraint that specifies that the given type
|
||||
// ObjectMarshalerPtr is a constraint that specifies that the given type
|
||||
// implements zapcore.ObjectMarshaler on a pointer receiver.
|
||||
type objectMarshalerPtr[T any] interface {
|
||||
type ObjectMarshalerPtr[T any] interface {
|
||||
*T
|
||||
zapcore.ObjectMarshaler
|
||||
}
|
||||
@@ -105,11 +105,11 @@ type objectMarshalerPtr[T any] interface {
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
func ObjectValues[T any, P objectMarshalerPtr[T]](key string, values []T) Field {
|
||||
func ObjectValues[T any, P ObjectMarshalerPtr[T]](key string, values []T) Field {
|
||||
return Array(key, objectValues[T, P](values))
|
||||
}
|
||||
|
||||
type objectValues[T any, P objectMarshalerPtr[T]] []T
|
||||
type objectValues[T any, P ObjectMarshalerPtr[T]] []T
|
||||
|
||||
func (os objectValues[T, P]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for i := range os {
|
||||
|
7
vendor/go.uber.org/zap/logger.go
generated
vendored
7
vendor/go.uber.org/zap/logger.go
generated
vendored
@@ -183,6 +183,13 @@ func (log *Logger) With(fields ...Field) *Logger {
|
||||
return l
|
||||
}
|
||||
|
||||
// Level reports the minimum enabled level for this logger.
|
||||
//
|
||||
// For NopLoggers, this is [zapcore.InvalidLevel].
|
||||
func (log *Logger) Level() zapcore.Level {
|
||||
return zapcore.LevelOf(log.core)
|
||||
}
|
||||
|
||||
// Check returns a CheckedEntry if logging a message at the specified level
|
||||
// is enabled. It's a completely optional optimization; in high-performance
|
||||
// applications, Check can help avoid allocating a slice to hold fields.
|
||||
|
3
vendor/go.uber.org/zap/options.go
generated
vendored
3
vendor/go.uber.org/zap/options.go
generated
vendored
@@ -133,7 +133,8 @@ func IncreaseLevel(lvl zapcore.LevelEnabler) Option {
|
||||
}
|
||||
|
||||
// OnFatal sets the action to take on fatal logs.
|
||||
// Deprecated: Use WithFatalHook instead.
|
||||
//
|
||||
// Deprecated: Use [WithFatalHook] instead.
|
||||
func OnFatal(action zapcore.CheckWriteAction) Option {
|
||||
return WithFatalHook(action)
|
||||
}
|
||||
|
100
vendor/go.uber.org/zap/sink.go
generated
vendored
100
vendor/go.uber.org/zap/sink.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016-2022 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -34,23 +35,7 @@ import (
|
||||
|
||||
const schemeFile = "file"
|
||||
|
||||
var (
|
||||
_sinkMutex sync.RWMutex
|
||||
_sinkFactories map[string]func(*url.URL) (Sink, error) // keyed by scheme
|
||||
)
|
||||
|
||||
func init() {
|
||||
resetSinkRegistry()
|
||||
}
|
||||
|
||||
func resetSinkRegistry() {
|
||||
_sinkMutex.Lock()
|
||||
defer _sinkMutex.Unlock()
|
||||
|
||||
_sinkFactories = map[string]func(*url.URL) (Sink, error){
|
||||
schemeFile: newFileSink,
|
||||
}
|
||||
}
|
||||
var _sinkRegistry = newSinkRegistry()
|
||||
|
||||
// Sink defines the interface to write to and close logger destinations.
|
||||
type Sink interface {
|
||||
@@ -58,10 +43,6 @@ type Sink interface {
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type nopCloserSink struct{ zapcore.WriteSyncer }
|
||||
|
||||
func (nopCloserSink) Close() error { return nil }
|
||||
|
||||
type errSinkNotFound struct {
|
||||
scheme string
|
||||
}
|
||||
@@ -70,16 +51,29 @@ func (e *errSinkNotFound) Error() string {
|
||||
return fmt.Sprintf("no sink found for scheme %q", e.scheme)
|
||||
}
|
||||
|
||||
// RegisterSink registers a user-supplied factory for all sinks with a
|
||||
// particular scheme.
|
||||
//
|
||||
// All schemes must be ASCII, valid under section 3.1 of RFC 3986
|
||||
// (https://tools.ietf.org/html/rfc3986#section-3.1), and must not already
|
||||
// have a factory registered. Zap automatically registers a factory for the
|
||||
// "file" scheme.
|
||||
func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
_sinkMutex.Lock()
|
||||
defer _sinkMutex.Unlock()
|
||||
type nopCloserSink struct{ zapcore.WriteSyncer }
|
||||
|
||||
func (nopCloserSink) Close() error { return nil }
|
||||
|
||||
type sinkRegistry struct {
|
||||
mu sync.Mutex
|
||||
factories map[string]func(*url.URL) (Sink, error) // keyed by scheme
|
||||
openFile func(string, int, os.FileMode) (*os.File, error) // type matches os.OpenFile
|
||||
}
|
||||
|
||||
func newSinkRegistry() *sinkRegistry {
|
||||
sr := &sinkRegistry{
|
||||
factories: make(map[string]func(*url.URL) (Sink, error)),
|
||||
openFile: os.OpenFile,
|
||||
}
|
||||
sr.RegisterSink(schemeFile, sr.newFileSinkFromURL)
|
||||
return sr
|
||||
}
|
||||
|
||||
// RegisterScheme registers the given factory for the specific scheme.
|
||||
func (sr *sinkRegistry) RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
sr.mu.Lock()
|
||||
defer sr.mu.Unlock()
|
||||
|
||||
if scheme == "" {
|
||||
return errors.New("can't register a sink factory for empty string")
|
||||
@@ -88,14 +82,22 @@ func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q is not a valid scheme: %v", scheme, err)
|
||||
}
|
||||
if _, ok := _sinkFactories[normalized]; ok {
|
||||
if _, ok := sr.factories[normalized]; ok {
|
||||
return fmt.Errorf("sink factory already registered for scheme %q", normalized)
|
||||
}
|
||||
_sinkFactories[normalized] = factory
|
||||
sr.factories[normalized] = factory
|
||||
return nil
|
||||
}
|
||||
|
||||
func newSink(rawURL string) (Sink, error) {
|
||||
func (sr *sinkRegistry) newSink(rawURL string) (Sink, error) {
|
||||
// URL parsing doesn't work well for Windows paths such as `c:\log.txt`, as scheme is set to
|
||||
// the drive, and path is unset unless `c:/log.txt` is used.
|
||||
// To avoid Windows-specific URL handling, we instead check IsAbs to open as a file.
|
||||
// filepath.IsAbs is OS-specific, so IsAbs('c:/log.txt') is false outside of Windows.
|
||||
if filepath.IsAbs(rawURL) {
|
||||
return sr.newFileSinkFromPath(rawURL)
|
||||
}
|
||||
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't parse %q as a URL: %v", rawURL, err)
|
||||
@@ -104,16 +106,27 @@ func newSink(rawURL string) (Sink, error) {
|
||||
u.Scheme = schemeFile
|
||||
}
|
||||
|
||||
_sinkMutex.RLock()
|
||||
factory, ok := _sinkFactories[u.Scheme]
|
||||
_sinkMutex.RUnlock()
|
||||
sr.mu.Lock()
|
||||
factory, ok := sr.factories[u.Scheme]
|
||||
sr.mu.Unlock()
|
||||
if !ok {
|
||||
return nil, &errSinkNotFound{u.Scheme}
|
||||
}
|
||||
return factory(u)
|
||||
}
|
||||
|
||||
func newFileSink(u *url.URL) (Sink, error) {
|
||||
// RegisterSink registers a user-supplied factory for all sinks with a
|
||||
// particular scheme.
|
||||
//
|
||||
// All schemes must be ASCII, valid under section 0.1 of RFC 3986
|
||||
// (https://tools.ietf.org/html/rfc3983#section-3.1), and must not already
|
||||
// have a factory registered. Zap automatically registers a factory for the
|
||||
// "file" scheme.
|
||||
func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
return _sinkRegistry.RegisterSink(scheme, factory)
|
||||
}
|
||||
|
||||
func (sr *sinkRegistry) newFileSinkFromURL(u *url.URL) (Sink, error) {
|
||||
if u.User != nil {
|
||||
return nil, fmt.Errorf("user and password not allowed with file URLs: got %v", u)
|
||||
}
|
||||
@@ -130,13 +143,18 @@ func newFileSink(u *url.URL) (Sink, error) {
|
||||
if hn := u.Hostname(); hn != "" && hn != "localhost" {
|
||||
return nil, fmt.Errorf("file URLs must leave host empty or use localhost: got %v", u)
|
||||
}
|
||||
switch u.Path {
|
||||
|
||||
return sr.newFileSinkFromPath(u.Path)
|
||||
}
|
||||
|
||||
func (sr *sinkRegistry) newFileSinkFromPath(path string) (Sink, error) {
|
||||
switch path {
|
||||
case "stdout":
|
||||
return nopCloserSink{os.Stdout}, nil
|
||||
case "stderr":
|
||||
return nopCloserSink{os.Stderr}, nil
|
||||
}
|
||||
return os.OpenFile(u.Path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
return sr.openFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
}
|
||||
|
||||
func normalizeScheme(s string) (string, error) {
|
||||
|
2
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
2
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
@@ -154,7 +154,7 @@ func newStackFormatter(b *buffer.Buffer) stackFormatter {
|
||||
// the final runtime.main/runtime.goexit frame.
|
||||
func (sf *stackFormatter) FormatStack(stack *stacktrace) {
|
||||
// Note: On the last iteration, frames.Next() returns false, with a valid
|
||||
// frame, but we ignore this frame. The last frame is a a runtime frame which
|
||||
// frame, but we ignore this frame. The last frame is a runtime frame which
|
||||
// adds noise, since it's only either runtime.main or runtime.goexit.
|
||||
for frame, more := stack.Next(); more; frame, more = stack.Next() {
|
||||
sf.FormatFrame(frame)
|
||||
|
31
vendor/go.uber.org/zap/sugar.go
generated
vendored
31
vendor/go.uber.org/zap/sugar.go
generated
vendored
@@ -31,6 +31,7 @@ import (
|
||||
const (
|
||||
_oddNumberErrMsg = "Ignored key without a value."
|
||||
_nonStringKeyErrMsg = "Ignored key-value pairs with non-string keys."
|
||||
_multipleErrMsg = "Multiple errors without a key."
|
||||
)
|
||||
|
||||
// A SugaredLogger wraps the base Logger functionality in a slower, but less
|
||||
@@ -114,6 +115,13 @@ func (s *SugaredLogger) With(args ...interface{}) *SugaredLogger {
|
||||
return &SugaredLogger{base: s.base.With(s.sweetenFields(args)...)}
|
||||
}
|
||||
|
||||
// Level reports the minimum enabled level for this logger.
|
||||
//
|
||||
// For NopLoggers, this is [zapcore.InvalidLevel].
|
||||
func (s *SugaredLogger) Level() zapcore.Level {
|
||||
return zapcore.LevelOf(s.base.core)
|
||||
}
|
||||
|
||||
// Debug uses fmt.Sprint to construct and log a message.
|
||||
func (s *SugaredLogger) Debug(args ...interface{}) {
|
||||
s.log(DebugLevel, "", args, nil)
|
||||
@@ -329,10 +337,13 @@ func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Allocate enough space for the worst case; if users pass only structured
|
||||
// fields, we shouldn't penalize them with extra allocations.
|
||||
fields := make([]Field, 0, len(args))
|
||||
var invalid invalidPairs
|
||||
var (
|
||||
// Allocate enough space for the worst case; if users pass only structured
|
||||
// fields, we shouldn't penalize them with extra allocations.
|
||||
fields = make([]Field, 0, len(args))
|
||||
invalid invalidPairs
|
||||
seenError bool
|
||||
)
|
||||
|
||||
for i := 0; i < len(args); {
|
||||
// This is a strongly-typed field. Consume it and move on.
|
||||
@@ -342,6 +353,18 @@ func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
continue
|
||||
}
|
||||
|
||||
// If it is an error, consume it and move on.
|
||||
if err, ok := args[i].(error); ok {
|
||||
if !seenError {
|
||||
seenError = true
|
||||
fields = append(fields, Error(err))
|
||||
} else {
|
||||
s.base.Error(_multipleErrMsg, Error(err))
|
||||
}
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
// Make sure this element isn't a dangling key.
|
||||
if i == len(args)-1 {
|
||||
s.base.Error(_oddNumberErrMsg, Any("ignored", args[i]))
|
||||
|
2
vendor/go.uber.org/zap/writer.go
generated
vendored
2
vendor/go.uber.org/zap/writer.go
generated
vendored
@@ -68,7 +68,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
|
||||
var openErr error
|
||||
for _, path := range paths {
|
||||
sink, err := newSink(path)
|
||||
sink, err := _sinkRegistry.newSink(path)
|
||||
if err != nil {
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("open sink %q: %w", path, err))
|
||||
continue
|
||||
|
3
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
3
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
@@ -281,7 +281,8 @@ func (ce *CheckedEntry) AddCore(ent Entry, core Core) *CheckedEntry {
|
||||
// Should sets this CheckedEntry's CheckWriteAction, which controls whether a
|
||||
// Core will panic or fatal after writing this log entry. Like AddCore, it's
|
||||
// safe to call on nil CheckedEntry references.
|
||||
// Deprecated: Use After(ent Entry, after CheckWriteHook) instead.
|
||||
//
|
||||
// Deprecated: Use [CheckedEntry.After] instead.
|
||||
func (ce *CheckedEntry) Should(ent Entry, should CheckWriteAction) *CheckedEntry {
|
||||
return ce.After(ent, should)
|
||||
}
|
||||
|
Reference in New Issue
Block a user