Skip to content

Commit

Permalink
feat(metadata): update UoM configuration struct
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hung <chris@iotechsys.com>
  • Loading branch information
Chris Hung committed Aug 17, 2022
1 parent 2391845 commit cbc81fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
15 changes: 7 additions & 8 deletions cmd/core-metadata/res/uom.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[Uom]
Source="reference to source for all UoM if not specified below"
[Uom.Units]
[Uom.Units.temperature]
Source="www.weather.com"
Values=["C","F","K"]
[Uom.Units.weights]
Source="www.usa.gov/federal-agencies/weights-and-measures-division"
Values=["lbs","ounces","kilos","grams"]
[Units]
[Units.temperature]
Source="www.weather.com"
Values=["C","F","K"]
[Units.weights]
Source="www.usa.gov/federal-agencies/weights-and-measures-division"
Values=["lbs","ounces","kilos","grams"]
8 changes: 2 additions & 6 deletions internal/core/metadata/uom/uom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
package uom

type UnitsOfMeasureImpl struct {
Uom ConfigurationStruct
}

type ConfigurationStruct struct {
Source string
Units map[string]Unit
}
Expand All @@ -20,11 +16,11 @@ type Unit struct {
}

func (u *UnitsOfMeasureImpl) Validate(unit string) bool {
if unit == "" || len(u.Uom.Units) == 0 {
if unit == "" || len(u.Units) == 0 {
return true
}

for _, units := range u.Uom.Units {
for _, units := range u.Units {
for _, v := range units.Values {
if unit == v {
return true
Expand Down

0 comments on commit cbc81fb

Please sign in to comment.