Skip to content

Commit

Permalink
Improve attachment struct names and use attachment type constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Rheisen committed Mar 15, 2024
1 parent bfe89f7 commit 62ad813
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
14 changes: 8 additions & 6 deletions attachment_detail_struct.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package berr

type detail struct {
const AttachmentDetailType = "detail"

type detailAttachment struct {

Check failure on line 5 in attachment_detail_struct.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
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
}
14 changes: 8 additions & 6 deletions attachment_error_struct.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package berr

type errorDetail struct {
const AttachmentErrorType = "error"

type errorAttachment struct {

Check failure on line 5 in attachment_error_struct.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
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
}
12 changes: 7 additions & 5 deletions attachment_metadata_struct.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package berr

type metadataDetail struct {
const AttachmentMetadataType = "metadata"

type metadataAttachment struct {

Check failure on line 5 in attachment_metadata_struct.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
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
}
4 changes: 2 additions & 2 deletions error_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 14 in error_struct.go

View workflow job for this annotation

GitHub Actions / lint

ifElseChain: rewrite if-else to switch statement (gocritic)
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()
Expand Down
6 changes: 3 additions & 3 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ 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 {
return Detail(key, value)
}

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 {
return Metadata(key, value)
}

func Err(value error) Attachment {
return errorDetail{key: "error", value: value}
return errorAttachment{key: "error", value: value}
}

func E(value error) Attachment {
Expand Down

0 comments on commit 62ad813

Please sign in to comment.