diff --git a/attachment_detail_struct.go b/attachment_detail_struct.go index 29a8fa0..ab417eb 100644 --- a/attachment_detail_struct.go +++ b/attachment_detail_struct.go @@ -1,22 +1,24 @@ package berr -type detail struct { +const AttachmentDetailType = "detail" + +type detailAttachment struct { key string value any } -func (d detail) Key() string { +func (d detailAttachment) Key() string { return d.key } -func (d detail) Value() any { +func (d detailAttachment) Value() any { return d.value } -func (d detail) Type() string { - return "berr_detail" +func (d detailAttachment) Type() string { + return AttachmentDetailType } -func (d detail) Sensitive() bool { +func (d detailAttachment) Sensitive() bool { return false } diff --git a/attachment_error_struct.go b/attachment_error_struct.go index 06d4151..d6e0af4 100644 --- a/attachment_error_struct.go +++ b/attachment_error_struct.go @@ -1,22 +1,24 @@ package berr -type errorDetail struct { +const AttachmentErrorType = "error" + +type errorAttachment struct { key string value error } -func (d errorDetail) Key() string { +func (d errorAttachment) Key() string { return d.key } -func (d errorDetail) Value() any { +func (d errorAttachment) Value() any { return d.value } -func (d errorDetail) Type() string { - return "berr_error_detail" +func (d errorAttachment) Type() string { + return AttachmentErrorType } -func (d errorDetail) Sensitive() bool { +func (d errorAttachment) Sensitive() bool { return true } diff --git a/attachment_metadata_struct.go b/attachment_metadata_struct.go index 26fceee..1da1e43 100644 --- a/attachment_metadata_struct.go +++ b/attachment_metadata_struct.go @@ -1,22 +1,24 @@ package berr -type metadataDetail struct { +const AttachmentMetadataType = "metadata" + +type metadataAttachment struct { key string value any } -func (d metadataDetail) Key() string { +func (d metadataAttachment) Key() string { return d.key } -func (d metadataDetail) Value() any { +func (d metadataAttachment) Value() any { return d.value } -func (d metadataDetail) Type() string { +func (d metadataAttachment) Type() string { return "berr_metadata_detail" } -func (d metadataDetail) Sensitive() bool { +func (d metadataAttachment) Sensitive() bool { return true } diff --git a/error_struct.go b/error_struct.go index ce6e034..9d6743f 100644 --- a/error_struct.go +++ b/error_struct.go @@ -11,9 +11,9 @@ func newBerr(errorType ErrorType, errorMessage string, attachments ...Attachment var next error for _, d := range attachments { - if d.Type() == "berr_error_detail" && next == nil { + if d.Type() == AttachmentErrorType && next == nil { next, _ = d.Value().(error) - } else if d.Type() == "berr_error_detail" { + } else if d.Type() == AttachmentErrorType { next = fmt.Errorf("%s: %w", next, d.Value().(error)) } else if d.Type() == "berr_metadata_detail" { errorMetadata[d.Key()] = d.Value() diff --git a/functions.go b/functions.go index f00ff57..606d5e7 100644 --- a/functions.go +++ b/functions.go @@ -43,7 +43,7 @@ func Timeout(message string, attachments ...Attachment) Error { } func Detail(key string, value any) Attachment { - return detail{key: key, value: value} + return detailAttachment{key: key, value: value} } func D(key string, value any) Attachment { @@ -51,7 +51,7 @@ func D(key string, value any) Attachment { } func Metadata(key string, value any) Attachment { - return metadataDetail{key: key, value: value} + return metadataAttachment{key: key, value: value} } func M(key string, value any) Attachment { @@ -59,7 +59,7 @@ func M(key string, value any) Attachment { } func Err(value error) Attachment { - return errorDetail{key: "error", value: value} + return errorAttachment{key: "error", value: value} } func E(value error) Attachment {