mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-09 18:33:36 +02:00
* refactor: simplify io code and make utils module independent * fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler * refactor: remove unused code * refactor: remove the use of logging module in most code * refactor: streamline domain mismatch check in certState function * tweak: use ecdsa p-256 for autocert * fix(tests): update health check tests for invalid host and add case for port in host * feat(acme): custom acme directory * refactor: code refactor and improved context and error handling * tweak: optimize memory usage under load * fix(oidc): restore old user matching behavior * docs: add ChatGPT assistant to README --------- Co-authored-by: yusing <yusing@6uo.me>
gperr
gperr is an error interface that supports nested structure and subject highlighting.
Usage
gperr.Error
The error interface.
gperr.New
Like errors.New, but returns a gperr.Error.
gperr.Wrap
Like fmt.Errorf("%s: %w", message, err), but returns a gperr.Error.
gperr.Error.Subject
Returns a new error with the subject prepended to the error message. The main subject is highlighted.
err := gperr.New("error message")
err = err.Subject("bar")
err = err.Subject("foo")
Output:
foo > bar: error message
gperr.Error.Subjectf
Like gperr.Error.Subject, but formats the subject with fmt.Sprintf.
gperr.PrependSubject
Prepends the subject to the error message like gperr.Error.Subject.
err := gperr.New("error message")
err = gperr.PrependSubject(err, "foo")
err = gperr.PrependSubject(err, "bar")
Output:
bar > foo: error message
gperr.Error.With
Adds a new error to the error chain.
err := gperr.New("error message")
err = err.With(gperr.New("inner error"))
err = err.With(gperr.New("inner error 2").With(gperr.New("inner inner error")))
Output:
error message:
• inner error
• inner error 2
• inner inner error
gperr.Error.Withf
Like gperr.Error.With, but formats the error with fmt.Errorf.
gperr.Error.Is
Returns true if the error is equal to the given error.
gperr.Builder
A builder for gperr.Error.
builder := gperr.NewBuilder("foo")
builder.Add(gperr.New("error message"))
builder.Addf("error message: %s", "foo")
builder.AddRange(gperr.New("error message 1"), gperr.New("error message 2"))
Output:
foo:
• error message
• error message: foo
• error message 1
• error message 2
gperr.Builder.Build
Builds a gperr.Error from the builder.
When to return gperr.Error
- When you want to return multiple errors
- When the error has a subject