Chore: Add errutils helpers (#73577)

Add helpers for the errutil package in favor of errutil.NewBase.
This commit is contained in:
Marcus Efraimsson
2023-08-22 12:52:24 +02:00
committed by GitHub
parent 1cc226e689
commit 040b7d2571
45 changed files with 261 additions and 161 deletions
+6 -8
View File
@@ -11,7 +11,7 @@ import (
)
func TestTemplate(t *testing.T) {
tmpl := errutil.NewBase(errutil.StatusInternal, "template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
tmpl := errutil.Internal("template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
err := tmpl.Build(errutil.TemplateData{
Public: map[string]interface{}{
"user": "grot the bot",
@@ -31,7 +31,7 @@ func TestTemplate(t *testing.T) {
func ExampleTemplate() {
// Initialization, this is typically done on a package or global
// level.
var tmpl = errutil.NewBase(errutil.StatusInternal, "template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
var tmpl = errutil.Internal("template.sampleError").MustTemplate("[{{ .Public.user }}] got error: {{ .Error }}")
// Construct an error based on the template.
err := tmpl.Build(errutil.TemplateData{
@@ -50,12 +50,10 @@ func ExampleTemplate() {
func ExampleTemplate_public() {
// Initialization, this is typically done on a package or global
// level.
var tmpl = errutil.
NewBase(errutil.StatusInternal, "template.sampleError").
MustTemplate(
"[{{ .Public.user }}] got error: {{ .Error }}",
errutil.WithPublic("Oh, no, error for {{ .Public.user }}"),
)
var tmpl = errutil.Internal("template.sampleError").MustTemplate(
"[{{ .Public.user }}] got error: {{ .Error }}",
errutil.WithPublic("Oh, no, error for {{ .Public.user }}"),
)
// Construct an error based on the template.
//nolint:errorlint