From 75a5a6c3cab2724b445743fa2c9a10448a76e07e Mon Sep 17 00:00:00 2001 From: Jonathan Oliver Date: Sat, 21 Sep 2024 15:24:06 -0600 Subject: [PATCH] Introduced singleton variable to reuse. --- contracts_structs.go | 52 ++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/contracts_structs.go b/contracts_structs.go index 6fec93b..4e61076 100644 --- a/contracts_structs.go +++ b/contracts_structs.go @@ -168,22 +168,20 @@ var ( }, }, } - deserializationResultFactory = func() ResultContainer { - return &fixedResultContainer{ - ResultContainer: &SerializeResult{ - StatusCode: http.StatusBadRequest, - Content: InputErrors{ - Errors: []error{ - InputError{ - Fields: []string{"body"}, - Name: "malformed-request-payload", - Message: "The body did not contain well-formed data and could not be properly deserialized.", - }, - }, + deserializationResultFactory = func() ResultContainer { return deserializationResult } + deserializationResult = &fixedResultContainer{ResultContainer: &SerializeResult{ + StatusCode: http.StatusBadRequest, + Content: InputErrors{ + Errors: []error{ + InputError{ + Fields: []string{"body"}, + Name: "malformed-request-payload", + Message: "The body did not contain well-formed data and could not be properly deserialized.", }, }, - } - } + }, + }} + parseFormedFailedResult = &SerializeResult{ StatusCode: http.StatusBadRequest, Content: InputErrors{ @@ -196,22 +194,20 @@ var ( }, }, } - bindErrorResultFactory = func() ResultContainer { - return &bindErrorContainer{ - SerializeResult: &SerializeResult{ - StatusCode: http.StatusBadRequest, - Content: &InputErrors{}, - }, - } + bindErrorResultFactory = func() ResultContainer { return bindErrorResult } + bindErrorResult = &bindErrorContainer{ + SerializeResult: &SerializeResult{ + StatusCode: http.StatusBadRequest, + Content: &InputErrors{}, + }, } - validationResultFactory = func() ResultContainer { - return &validationErrorContainer{ - SerializeResult: &SerializeResult{ - StatusCode: http.StatusUnprocessableEntity, - Content: &InputErrors{}, - }, - } + validationResultFactory = func() ResultContainer { return validationResult } + validationResult = &validationErrorContainer{ + SerializeResult: &SerializeResult{ + StatusCode: http.StatusUnprocessableEntity, + Content: &InputErrors{}, + }, } )