Skip to content

Commit

Permalink
fix(go): use decimal instead f32 for price
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaranski committed Nov 14, 2022
1 parent e6f6e59 commit 16b0c58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down
11 changes: 6 additions & 5 deletions go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
wheretopark "wheretopark/go"

geojson "github.com/paulmach/go.geojson"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -95,23 +96,23 @@ func TestParkingLot(t *testing.T) {
Pricing: []wheretopark.PricingRule{
{
Duration: "PT1H",
Price: 0.0,
Price: decimal.Zero,
},
{
Duration: "PT2H",
Price: 2.0,
Price: decimal.NewFromInt(2),
},
{
Duration: "PT3H",
Price: 3.0,
Price: decimal.NewFromInt(3),
},
{
Duration: "PT24H",
Price: 25.0,
Price: decimal.NewFromInt(25),
},
{
Duration: "PT1H",
Price: 4.0,
Price: decimal.NewFromInt(4),
Repeating: true,
},
},
Expand Down
7 changes: 4 additions & 3 deletions go/parking_lot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wheretopark
import (
"github.com/mmcloughlin/geohash"
geojson "github.com/paulmach/go.geojson"
"github.com/shopspring/decimal"
)

type ID = string
Expand All @@ -12,9 +13,9 @@ type PaymentMethod = string
type LanguageCode = string

type PricingRule struct {
Duration string `json:"duration"`
Price float32 `json:"price"`
Repeating bool `json:"repeating,omitempty"`
Duration string `json:"duration"`
Price decimal.Decimal `json:"price"`
Repeating bool `json:"repeating,omitempty"`
}

type Rule struct {
Expand Down

0 comments on commit 16b0c58

Please sign in to comment.