refactor(sessionresolver): minor changes in files and types naming (#810)

Part of https://github.com/ooni/probe/issues/2135
This commit is contained in:
Simone Basso 2022-06-08 22:01:51 +02:00 committed by GitHub
commit a02cc6100b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 145 additions and 107 deletions

View file

@ -1,23 +1,40 @@
package sessionresolver
//
// Error wrapping
//
import (
"errors"
"fmt"
)
// errwrapper wraps an error to include the URL of the
// errWrapper wraps an error to include the URL of the
// resolver that we're currently using.
type errwrapper struct {
error
URL string
type errWrapper struct {
err error
url string
}
// newErrWrapper creates a new err wrapper.
func newErrWrapper(err error, URL string) *errWrapper {
return &errWrapper{
err: err,
url: URL,
}
}
// Error implements error.Error.
func (ew *errwrapper) Error() string {
return fmt.Sprintf("<%s> %s", ew.URL, ew.error.Error())
func (ew *errWrapper) Error() string {
return fmt.Sprintf("<%s> %s", ew.url, ew.err.Error())
}
// Is allows consumers to query for the type of the underlying error.
func (ew *errwrapper) Is(target error) bool {
return errors.Is(ew.error, target)
func (ew *errWrapper) Is(target error) bool {
return errors.Is(ew.err, target)
}
// Unwrap returns the underlying error.
func (ew *errWrapper) Unwrap() error {
return ew.err
}