From 069e0ec1a4dd0a37ed307cd3e5296b60a6c9cbba Mon Sep 17 00:00:00 2001 From: Carlos Lapao Date: Tue, 20 Dec 2022 08:36:06 +0000 Subject: [PATCH] - allowed mapper to map body several times (#31) * - allowed mapper to map body several times - removed println from logs - made the version not print the rev if it is 0 * fixed the failing unit tests --- helper/http_helper/http.go | 2 ++ log/main.go | 1 - version/main.go | 7 ++++++- version/main_test.go | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/helper/http_helper/http.go b/helper/http_helper/http.go index a6080c1..3621845 100644 --- a/helper/http_helper/http.go +++ b/helper/http_helper/http.go @@ -1,6 +1,7 @@ package http_helper import ( + "bytes" "encoding/json" "errors" "fmt" @@ -160,6 +161,7 @@ func MapRequestBody(request *http.Request, dest interface{}) error { } bodyArr, err := ioutil.ReadAll(request.Body) + request.Body = io.NopCloser(bytes.NewBuffer(bodyArr)) if err != nil { return err } diff --git a/log/main.go b/log/main.go index 258439c..773e6e0 100644 --- a/log/main.go +++ b/log/main.go @@ -142,7 +142,6 @@ func (l *Logger) WithWarning() *Logger { } func (l *Logger) WithTimestamp() *Logger { - println("setting the withtimesramp") for _, logger := range l.Loggers { logger.UseTimestamp(true) } diff --git a/version/main.go b/version/main.go index 9d7f0ec..37b6db4 100644 --- a/version/main.go +++ b/version/main.go @@ -71,7 +71,12 @@ func Get(v ...int) *Version { } func (v *Version) String() string { - return fmt.Sprint(v.Major) + "." + fmt.Sprint(v.Minor) + "." + fmt.Sprint(v.Build) + "." + fmt.Sprint(v.Rev) + if v.Rev > 0 { + return fmt.Sprint(v.Major) + "." + fmt.Sprint(v.Minor) + "." + fmt.Sprint(v.Build) + "." + fmt.Sprint(v.Rev) + + } else { + return fmt.Sprint(v.Major) + "." + fmt.Sprint(v.Minor) + "." + fmt.Sprint(v.Build) + } } func FromString(ver string) (*Version, error) { diff --git a/version/main_test.go b/version/main_test.go index d364d6f..5f4d424 100644 --- a/version/main_test.go +++ b/version/main_test.go @@ -131,7 +131,7 @@ func TestToString(t *testing.T) { //Assert assert.NotNilf(t, v, "Version should not be null") assert.Nilf(t, err, "Error should be nil") - assert.Equalf(t, "1.1.1.0", v.String(), "ToString should be equal to 1.1.1.0") + assert.Equalf(t, "1.1.1", v.String(), "ToString should be equal to 1.1.1") } func TestEmptyGet(t *testing.T) {