From 9cf1d38a123c303c3f00d7319f09a1cae53c1665 Mon Sep 17 00:00:00 2001 From: noobj Date: Mon, 25 Sep 2023 11:10:04 -0700 Subject: [PATCH] fix: entry float32 truncate error --- cmd/ahorro/fetchentries/main.go | 12 ++++++------ go.mod | 2 +- go.sum | 8 -------- .../repositories/ahorro/entry/entry_repository.go | 2 +- package.json | 2 +- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/cmd/ahorro/fetchentries/main.go b/cmd/ahorro/fetchentries/main.go index b192b32..8e034e6 100644 --- a/cmd/ahorro/fetchentries/main.go +++ b/cmd/ahorro/fetchentries/main.go @@ -20,20 +20,20 @@ type Response events.APIGatewayProxyResponse type Entry struct { Id primitive.ObjectID `json:"_id" bson:"_id"` - Amount float32 `json:"amount" bson:"amount"` + Amount float64 `json:"amount" bson:"amount"` Date string `json:"date"` Descr string `json:"descr"` } type AggregateResult struct { Entries []Entry - Sum float32 + Sum float64 Category []EntryRepository.Category } type CategoryEntriesBundle struct { Id primitive.ObjectID `json:"_id" bson:"_id"` - Sum float32 `json:"sum"` + Sum float64 `json:"sum"` Percentage string `json:"percentage"` Name string `json:"name"` Entries []Entry `json:"entries"` @@ -132,7 +132,7 @@ func (this Invoker) Invoke(ctx context.Context, request events.APIGatewayV2HTTPR repoResults := this.entryRepository.Aggregate([]bson.D{matchStage, sortStage, groupStage, sortSumStage, lookupStage}) var categories []CategoryEntriesBundle - total := float32(0.0) + total := float64(0.0) for _, repoResult := range repoResults { fmt.Printf("%+v", repoResult) doc, _ := bson.Marshal(repoResult) @@ -156,13 +156,13 @@ func (this Invoker) Invoke(ctx context.Context, request events.APIGatewayV2HTTPR } for key, category := range categories { - percentage := float32(category.Sum) / float32(total) + percentage := float64(category.Sum) / float64(total) categories[key].Percentage = fmt.Sprintf("%.2f", percentage) } resultForReturn := struct { Categories []CategoryEntriesBundle `json:"categories"` - Total float32 `json:"total"` + Total float64 `json:"total"` }{ Categories: categories, Total: total, diff --git a/go.mod b/go.mod index c8addce..cf44b06 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang/mock v1.6.0 github.com/golobby/container/v3 v3.3.1 + github.com/google/uuid v1.3.0 github.com/joho/godotenv v1.4.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/mitchellh/mapstructure v1.5.0 @@ -21,7 +22,6 @@ require ( require ( cloud.google.com/go/compute v1.7.0 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect github.com/googleapis/gax-go/v2 v2.4.0 // indirect github.com/kr/pretty v0.2.1 // indirect diff --git a/go.sum b/go.sum index da59c1d..f61a147 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,6 @@ github.com/antchfx/xmlquery v1.3.11/go.mod h1:ywPcYkN0GvURUxXpUujaMVvuLSOYQBzoSf github.com/antchfx/xpath v1.2.1 h1:qhp4EW6aCOVr5XIkT+l6LJ9ck/JsUH/yyauNgTQkBF8= github.com/antchfx/xpath v1.2.1/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/aws/aws-lambda-go v1.34.1 h1:M3a/uFYBjii+tDcOJ0wL/WyFi2550FHoECdPf27zvOs= -github.com/aws/aws-lambda-go v1.34.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= github.com/aws/aws-lambda-go v1.37.0 h1:WXkQ/xhIcXZZ2P5ZBEw+bbAKeCEcb5NtiYpSwVVzIXg= github.com/aws/aws-lambda-go v1.37.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= github.com/aws/aws-sdk-go v1.44.79 h1:IZCtfBq9VlJ1Eu34I+2Y76q+XkvTtZYbEwaoVM1gzoA= @@ -154,8 +152,6 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golobby/container/v3 v3.2.1 h1:waIB8d4nSDwMaO7PvM6H+OCqAFEWyMuSPNN4Fwpv0Ok= -github.com/golobby/container/v3 v3.2.1/go.mod h1:RDdKpnKpV1Of11PFBe7Dxc2C1k2KaLE4FD47FflAmj0= github.com/golobby/container/v3 v3.3.1 h1:Y+QpwChmkz86tAKimvqc0qls8A4eYm/PhMqSEt/HTj4= github.com/golobby/container/v3 v3.3.1/go.mod h1:RDdKpnKpV1Of11PFBe7Dxc2C1k2KaLE4FD47FflAmj0= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -239,10 +235,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/noobj/jwtmiddleware v1.0.2 h1:h30phLAskmcpxBz/sd01qonIfF1Pu5pd1EhAm8JXsVs= -github.com/noobj/jwtmiddleware v1.0.2/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg= -github.com/noobj/jwtmiddleware v1.0.3 h1:kfJNDI22T6CCVoALFvMJi2iHBngSKOSAclrMs0mBvrc= -github.com/noobj/jwtmiddleware v1.0.3/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg= github.com/noobj/jwtmiddleware v1.0.4 h1:QWfjMw7d+CaBc14vthC7duzdEeLvq7cwZH133YCLw7I= github.com/noobj/jwtmiddleware v1.0.4/go.mod h1:KBR615o5jFZPvzWFs7bQ9ZS/69bo+uJCkI+k0yuQLTg= github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI= diff --git a/internal/repositories/ahorro/entry/entry_repository.go b/internal/repositories/ahorro/entry/entry_repository.go index 43cd69f..55a74fb 100644 --- a/internal/repositories/ahorro/entry/entry_repository.go +++ b/internal/repositories/ahorro/entry/entry_repository.go @@ -9,7 +9,7 @@ import ( type Entry struct { Id primitive.ObjectID `json:"_id" bson:"_id"` - Amount float32 `json:"amount" bson:"amount"` + Amount float64 `json:"amount" bson:"amount"` Date string `json:"date"` Descr string `json:"descr"` Category primitive.ObjectID `json:"category,omitempty" bson:"category,omitempty"` diff --git a/package.json b/package.json index 5b5ebdc..42eb729 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "To run the golang lambda service locally", "version": "1.0.0", "scripts": { - "start": "SLS_DEBUG=* node ./node_modules/.bin/serverless offline --host 0.0.0.0 start --useDocker", + "start": "SLS_DEBUG=* node ./node_modules/.bin/serverless offline --host 0.0.0.0 --httpsProtocol ./ssl start --useDocker", "watch": "nodemon --watch ./ -e go --exec make build -j", "watch_swim": "nodemon --watch ./ -e go --exec make swimbuild", "test": "ginkgo ./..."