From dd55a3687be2e6463d950ebfce8fa598a40dd196 Mon Sep 17 00:00:00 2001 From: Kevin Joiner <10265309+KevinJoiner@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:48:14 -0400 Subject: [PATCH] Transfer repo to DIMO-Network. * Removes errors on not found data points. --- README.md | 23 +++--- cmd/codegen/codegen.go | 8 +-- go.mod | 2 +- internal/codegen/clickhouse/clickhouse.go | 2 +- internal/codegen/convert/convert.go | 2 +- internal/codegen/convert/convert.tmpl | 49 ++++++------- internal/codegen/model/model.go | 2 +- pkg/vss/convert_test.go | 4 +- pkg/vss/vehicle-convert-funcs.go | 2 +- pkg/vss/vehicle-convert-funcs_test.go | 2 +- pkg/vss/vehicle-convert.go | 87 +---------------------- 11 files changed, 49 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index 906885a..36bd299 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Model Garage ![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg) -[![GoDoc](https://godoc.org/github.com/KevinJoiner/model-garage?status.svg)](https://godoc.org/github.com/KevinJoiner/model-garage) -[![Go Report Card](https://goreportcard.com/badge/github.com/KevinJoiner/model-garage)](https://goreportcard.com/report/github.com/KevinJoiner/model-garage) +[![GoDoc](https://godoc.org/github.com/DIMO-Network/model-garage?status.svg)](https://godoc.org/github.com/DIMO-Network/model-garage) +[![Go Report Card](https://goreportcard.com/badge/github.com/DIMO-Network/model-garage)](https://goreportcard.com/report/github.com/DIMO-Network/model-garage) Welcome to the **Model Garage**, a Golang toolkit for managing and working with DIMO models generated from vspec CSV schemas. Model Garage provides the following features: @@ -17,11 +17,13 @@ Welcome to the **Model Garage**, a Golang toolkit for managing and working with ## Getting Started 1. **Installation**: + ```bash go get github.com/your-username/model-garage ``` 2. **Import in Your Code**: + ```go import "github.com/your-username/model-garage" ``` @@ -29,36 +31,41 @@ Welcome to the **Model Garage**, a Golang toolkit for managing and working with 3. **Usage**: Explore the documentation to start using Model Garage in your project. - ## Repo structure ### Codegen + The `codegen` directory contains the code generation tool for creating models from vspec CSV schemas. The tool is a standalone application that can be run from the command line. Example usage: + ```bash go run ./cmd/codegen -output=./pkg/vss -spec=./schema/vss_rel_4.2-DIMO.csv -definitions=./schema/definitions.json -package=vss package main ``` #### Generation Info + The Model generation is handled by packages in `internal/codegen`. They are responsible for creating Go structs, Clickhouse tables, and conversion functions from the vspec CSV schema and definitions file. -**Vspec Schema** The vspec schema is a CSV file that contains the signal definitions for the model. This schema is generated using vss-tools in this https://github.com/KevinJoiner/DIMO-VSS repository. +**Vspec Schema** The vspec schema is a CSV file that contains the signal definitions for the model. This schema is generated using vss-tools in this https://github.com/DIMO-Network/DIMO-VSS repository. **Definitions File** The definitions file is a JSON file that contains the signal definitions that are to be included in the model. This file is manually created. With the following structure: - **vspecName**: The name of the signal field in the vspec. Only fields specified in the vspec will be included in the model. - **conversion**: (optional) Details about the conversion from the original data to the vspec field. If not specified, the conversion is assumed to be a direct copy. - - **originalName**: The original name of the field in the data. - - **originalType**: (optional) The original data type of the field. If not specified, the original type is assumed to be the same as the vspec type. + - **originalName**: The original name of the field in the data. + + - **originalType**: (optional) The original data type of the field. If not specified, the original type is assumed to be the same as the vspec type. + ##### Generation Process + 1. First, the vspec CSV schema and definitions file are parsed. 2. Then a struct is created for each signal in the vpsec schema that is specified in the definitions file. With Clickhouse and JSON tags for each field. The CH and JSON names are the same as the vspec except `.` are replaced with `_`. 3. Next, a Clickhouse table is created for the struct. The table name is the same as the package name. The table is created with the same fields as the struct with corresponding Clickhouse types. -4. Finally, conversion functions are created for each struct. These functions convert the original data in the form of a JSON document to the struct. +4. Finally, conversion functions are created for each struct. These functions convert the original data in the form of a JSON document to the struct. **Conversion Functions** -For each field, a conversion function is created. If a conversion is specified in the definitions file, the conversion function will use the specified conversion. If no conversion is specified, the conversion info function will assume a direct copy. The conversion functions are meant to be overridden with custom logic as needed. When generation is re-run, the conversion functions are not overwritten. \ No newline at end of file +For each field, a conversion function is created. If a conversion is specified in the definitions file, the conversion function will use the specified conversion. If no conversion is specified, the conversion info function will assume a direct copy. The conversion functions are meant to be overridden with custom logic as needed. When generation is re-run, the conversion functions are not overwritten. diff --git a/cmd/codegen/codegen.go b/cmd/codegen/codegen.go index b7b8909..cd39cab 100644 --- a/cmd/codegen/codegen.go +++ b/cmd/codegen/codegen.go @@ -5,10 +5,10 @@ import ( "flag" "log" - "github.com/KevinJoiner/model-garage/internal/codegen" - "github.com/KevinJoiner/model-garage/internal/codegen/clickhouse" - "github.com/KevinJoiner/model-garage/internal/codegen/convert" - "github.com/KevinJoiner/model-garage/internal/codegen/model" + "github.com/DIMO-Network/model-garage/internal/codegen" + "github.com/DIMO-Network/model-garage/internal/codegen/clickhouse" + "github.com/DIMO-Network/model-garage/internal/codegen/convert" + "github.com/DIMO-Network/model-garage/internal/codegen/model" ) func main() { diff --git a/go.mod b/go.mod index 1379331..17e8386 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/KevinJoiner/model-garage +module github.com/DIMO-Network/model-garage go 1.22.0 diff --git a/internal/codegen/clickhouse/clickhouse.go b/internal/codegen/clickhouse/clickhouse.go index 894b573..511ba10 100644 --- a/internal/codegen/clickhouse/clickhouse.go +++ b/internal/codegen/clickhouse/clickhouse.go @@ -10,7 +10,7 @@ import ( "strings" "text/template" - "github.com/KevinJoiner/model-garage/internal/codegen" + "github.com/DIMO-Network/model-garage/internal/codegen" ) // clickhouseFileName is the name of the ClickHouse table file that will be generated. diff --git a/internal/codegen/convert/convert.go b/internal/codegen/convert/convert.go index f887a0f..ddcb5b6 100644 --- a/internal/codegen/convert/convert.go +++ b/internal/codegen/convert/convert.go @@ -13,7 +13,7 @@ import ( "strings" "text/template" - "github.com/KevinJoiner/model-garage/internal/codegen" + "github.com/DIMO-Network/model-garage/internal/codegen" ) var ( diff --git a/internal/codegen/convert/convert.tmpl b/internal/codegen/convert/convert.tmpl index 90c592b..e15ab8e 100644 --- a/internal/codegen/convert/convert.tmpl +++ b/internal/codegen/convert/convert.tmpl @@ -4,16 +4,8 @@ package {{ .PackageName }} var ( // errInvalidType is returned when a field is not of the expected type or not found. errInvalidType = errors.New("invalid type") - - // errNotFound is returned when a field is not found. - errNotFound = errors.New("not found") ) -// IsNotFound returns true if the error is of type errNotFound. -func IsNotFound(err error) bool { - return errors.Is(err, errNotFound) -} - // IsInvalidType returns true if the error is of type errInvalidType. func IsInvalidType(err error) bool { return errors.Is(err, errInvalidType) @@ -23,49 +15,48 @@ func IsInvalidType(err error) bool { // FromData creates a new {{ .ModelName }} from a map of data. Using defined conversion functions. // If skipNotFound is true, the function will not return an error if a key is not found. // instead the field will be set to the zero value of the type. -func FromData(jsonData []byte, skipNotFound bool) (*{{ .ModelName }}, error) { - {{ lower .ModelName }} := {{ .ModelName }}{} +func FromData(jsonData []byte) (*{{ .ModelName }}, error) { + {{ $varName := lower .ModelName}} + {{ $varName }} := {{ .ModelName }}{} {{ $first := true }} -{{- range .Signals }} - {{ if not .Conversion }} {{ continue }} {{ end }} +{{- range $idx, $sig := .Signals }} + {{ if not $sig.Conversion }} {{ continue }} {{ end }} {{ if $first }} var err error var result gjson.Result {{ $first = false }} {{ end }} - // convert {{ .Conversion.OriginalName }} to {{ .GOName }} - result = gjson.GetBytes(jsonData, "{{ .Conversion.OriginalName }}") + // convert {{ $sig.Conversion.OriginalName }} to {{ $sig.GOName }} + result = gjson.GetBytes(jsonData, "{{ $sig.Conversion.OriginalName }}") if result.Exists() { - {{ if .Conversion.IsArray -}} + {{ if $sig.Conversion.IsArray -}} if !result.IsArray() { - return nil, fmt.Errorf("%w, field '{{ .Conversion.OriginalName }}' is not an array", errInvalidType) + return nil, fmt.Errorf("%w, field '{{ $sig.Conversion.OriginalName }}' is not an array", errInvalidType) } - slice{{ .GOName}} := make([]{{ .Conversion.OriginalType }}, len(result.Array())) + slice{{ $sig.GOName}} := make([]{{ $sig.Conversion.OriginalType }}, len(result.Array())) for i, res := range result.Array() { - v, ok := res.Value().({{ .Conversion.OriginalType }}) + v, ok := res.Value().({{ $sig.Conversion.OriginalType }}) if !ok{ - return nil, fmt.Errorf("%w, field '{{ .Conversion.OriginalName }}' array element %d is not of type {{ .Conversion.OriginalType }}", errInvalidType, i) + return nil, fmt.Errorf("%w, field '{{ $sig.Conversion.OriginalName }}' array element %d is not of type {{ $sig.Conversion.OriginalType }}", errInvalidType, i) } - slice{{ .GOName}}[i] = v + slice{{ $sig.GOName}}[i] = v } - vehicle.{{ .GOName }}, err = {{ convertName . }}(slice{{ .GOName}} ) + {{ $varName }}.{{ $sig.GOName }}, err = {{ convertName $sig }}(slice{{ $sig.GOName}} ) if err != nil { - return nil, fmt.Errorf("failed to convert '{{ .Conversion.OriginalName }}': %w", err) + return nil, fmt.Errorf("failed to convert '{{ $sig.Conversion.OriginalName }}': %w", err) } {{ else -}} - val{{ .GOName}}, ok := result.Value().({{ .Conversion.OriginalType }}) + val{{ $sig.GOName}}, ok := result.Value().({{ $sig.Conversion.OriginalType }}) if !ok { - return nil, fmt.Errorf("%w, field '{{ .Conversion.OriginalName }}' is not of type {{ .Conversion.OriginalType }}", errInvalidType) + return nil, fmt.Errorf("%w, field '{{ $sig.Conversion.OriginalName }}' is not of type {{ $sig.Conversion.OriginalType }}", errInvalidType) } - vehicle.{{ .GOName }}, err = {{ convertName . }}(val{{ .GOName}}) + {{ $varName }}.{{ $sig.GOName }}, err = {{ convertName $sig }}(val{{ $sig.GOName}}) if err != nil { - return nil, fmt.Errorf("failed to convert '{{ .Conversion.OriginalName }}': %w", err) + return nil, fmt.Errorf("failed to convert '{{ $sig.Conversion.OriginalName }}': %w", err) } {{ end -}} - } else if !skipNotFound{ - return nil, fmt.Errorf("%w, field '{{ .Conversion.OriginalName }}'", errNotFound) } {{- end }} - return &vehicle, nil + return &{{ $varName }}, nil } diff --git a/internal/codegen/model/model.go b/internal/codegen/model/model.go index 61537e2..74ea1cb 100644 --- a/internal/codegen/model/model.go +++ b/internal/codegen/model/model.go @@ -9,7 +9,7 @@ import ( "strings" "text/template" - "github.com/KevinJoiner/model-garage/internal/codegen" + "github.com/DIMO-Network/model-garage/internal/codegen" ) // structFileName is the name of the Go file that will contain the vehicle struct. diff --git a/pkg/vss/convert_test.go b/pkg/vss/convert_test.go index 811a8eb..8409cb7 100644 --- a/pkg/vss/convert_test.go +++ b/pkg/vss/convert_test.go @@ -4,13 +4,13 @@ import ( "testing" "time" - "github.com/KevinJoiner/model-garage/pkg/vss" + "github.com/DIMO-Network/model-garage/pkg/vss" "github.com/stretchr/testify/require" ) func TestFullFromDataConversion(t *testing.T) { t.Parallel() - vehicle, err := vss.FromData([]byte(fullInputJSON), false) + vehicle, err := vss.FromData([]byte(fullInputJSON)) require.NoErrorf(t, err, "error converting full input data: %v", err) require.Equalf(t, fullVehicle, vehicle, "converted vehicle does not match expected vehicle") } diff --git a/pkg/vss/vehicle-convert-funcs.go b/pkg/vss/vehicle-convert-funcs.go index 95ede53..bfd33b7 100644 --- a/pkg/vss/vehicle-convert-funcs.go +++ b/pkg/vss/vehicle-convert-funcs.go @@ -4,7 +4,7 @@ package vss import ( "time" - "github.com/KevinJoiner/model-garage/internal/convert" + "github.com/DIMO-Network/model-garage/internal/convert" ) // This file is automatically populated with conversion functions for each field of a model struct. diff --git a/pkg/vss/vehicle-convert-funcs_test.go b/pkg/vss/vehicle-convert-funcs_test.go index 8822d49..4b78975 100644 --- a/pkg/vss/vehicle-convert-funcs_test.go +++ b/pkg/vss/vehicle-convert-funcs_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/KevinJoiner/model-garage/pkg/vss" + "github.com/DIMO-Network/model-garage/pkg/vss" "github.com/stretchr/testify/require" ) diff --git a/pkg/vss/vehicle-convert.go b/pkg/vss/vehicle-convert.go index c107008..2497ac2 100644 --- a/pkg/vss/vehicle-convert.go +++ b/pkg/vss/vehicle-convert.go @@ -11,16 +11,8 @@ import ( var ( // errInvalidType is returned when a field is not of the expected type or not found. errInvalidType = errors.New("invalid type") - - // errNotFound is returned when a field is not found. - errNotFound = errors.New("not found") ) -// IsNotFound returns true if the error is of type errNotFound. -func IsNotFound(err error) bool { - return errors.Is(err, errNotFound) -} - // IsInvalidType returns true if the error is of type errInvalidType. func IsInvalidType(err error) bool { return errors.Is(err, errInvalidType) @@ -29,7 +21,8 @@ func IsInvalidType(err error) bool { // FromData creates a new Vehicle from a map of data. Using defined conversion functions. // If skipNotFound is true, the function will not return an error if a key is not found. // instead the field will be set to the zero value of the type. -func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { +func FromData(jsonData []byte) (*Vehicle, error) { + vehicle := Vehicle{} var err error @@ -46,8 +39,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.tires.frontLeft': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.tires.frontLeft'", errNotFound) } // convert data.tires.frontRight to ChassisAxleRow1WheelRightTirePressure @@ -61,8 +52,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.tires.frontRight': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.tires.frontRight'", errNotFound) } // convert data.tires.backLeft to ChassisAxleRow2WheelLeftTirePressure @@ -76,8 +65,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.tires.backLeft': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.tires.backLeft'", errNotFound) } // convert data.tires.backRight to ChassisAxleRow2WheelRightTirePressure @@ -91,8 +78,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.tires.backRight': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.tires.backRight'", errNotFound) } // convert data.altitude to CurrentLocationAltitude @@ -106,8 +91,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.altitude': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.altitude'", errNotFound) } // convert data.latitude to CurrentLocationLatitude @@ -121,8 +104,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.latitude': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.latitude'", errNotFound) } // convert data.longitude to CurrentLocationLongitude @@ -136,8 +117,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.longitude': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.longitude'", errNotFound) } // convert data.timestamp to CurrentLocationTimestamp @@ -151,8 +130,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.timestamp': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.timestamp'", errNotFound) } // convert data.definitionID to DIMODefinitionID @@ -166,8 +143,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.definitionID': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.definitionID'", errNotFound) } // convert source to DIMOSource @@ -181,8 +156,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'source': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'source'", errNotFound) } // convert subject to DIMOSubject @@ -196,8 +169,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'subject': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'subject'", errNotFound) } // convert time to DIMOTimestamp @@ -211,8 +182,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'time': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'time'", errNotFound) } // convert type to DIMOType @@ -226,8 +195,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'type': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'type'", errNotFound) } // convert data.vehicleID to DIMOVehicleID @@ -241,8 +208,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.vehicleID': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.vehicleID'", errNotFound) } // convert data.ambientTemp to ExteriorAirTemperature @@ -256,8 +221,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.ambientTemp': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.ambientTemp'", errNotFound) } // convert data.batteryVoltage to LowVoltageBatteryCurrentVoltage @@ -271,8 +234,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.batteryVoltage': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.batteryVoltage'", errNotFound) } // convert data.barometricPressure to OBDBarometricPressure @@ -286,8 +247,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.barometricPressure': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.barometricPressure'", errNotFound) } // convert data.engineLoad to OBDEngineLoad @@ -301,8 +260,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.engineLoad': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.engineLoad'", errNotFound) } // convert data.intakeTemp to OBDIntakeTemp @@ -316,8 +273,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.intakeTemp': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.intakeTemp'", errNotFound) } // convert data.runTime to OBDRunTime @@ -331,8 +286,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.runTime': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.runTime'", errNotFound) } // convert data.coolantTemp to PowertrainCombustionEngineECT @@ -346,8 +299,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.coolantTemp': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.coolantTemp'", errNotFound) } // convert data.oil to PowertrainCombustionEngineEngineOilLevel @@ -361,8 +312,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.oil': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.oil'", errNotFound) } // convert data.engineSpeed to PowertrainCombustionEngineSpeed @@ -376,8 +325,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.engineSpeed': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.engineSpeed'", errNotFound) } // convert data.throttlePosition to PowertrainCombustionEngineTPS @@ -391,8 +338,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.throttlePosition': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.throttlePosition'", errNotFound) } // convert data.fuelPercentRemaining to PowertrainFuelSystemAbsoluteLevel @@ -406,8 +351,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.fuelPercentRemaining': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.fuelPercentRemaining'", errNotFound) } // convert data.fuelType to PowertrainFuelSystemSupportedFuelTypes @@ -421,8 +364,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.fuelType': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.fuelType'", errNotFound) } // convert data.range to PowertrainRange @@ -436,8 +377,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.range': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.range'", errNotFound) } // convert data.chargeLimit to PowertrainTractionBatteryChargingChargeLimit @@ -451,8 +390,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.chargeLimit': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.chargeLimit'", errNotFound) } // convert data.charging to PowertrainTractionBatteryChargingIsCharging @@ -466,8 +403,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.charging': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.charging'", errNotFound) } // convert data.batteryCapacity to PowertrainTractionBatteryGrossCapacity @@ -481,8 +416,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.batteryCapacity': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.batteryCapacity'", errNotFound) } // convert data.soc to PowertrainTractionBatteryStateOfChargeCurrent @@ -496,8 +429,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.soc': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.soc'", errNotFound) } // convert data.odometer to PowertrainTransmissionTravelledDistance @@ -511,8 +442,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.odometer': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.odometer'", errNotFound) } // convert data.fuelType to PowertrainType @@ -526,8 +455,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.fuelType': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.fuelType'", errNotFound) } // convert data.speed to Speed @@ -541,8 +468,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.speed': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.speed'", errNotFound) } // convert data.make to VehicleIdentificationBrand @@ -556,8 +481,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.make': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.make'", errNotFound) } // convert data.model to VehicleIdentificationModel @@ -571,8 +494,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.model': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.model'", errNotFound) } // convert data.vin to VehicleIdentificationVIN @@ -586,8 +507,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.vin': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.vin'", errNotFound) } // convert data.year to VehicleIdentificationYear @@ -601,8 +520,6 @@ func FromData(jsonData []byte, skipNotFound bool) (*Vehicle, error) { if err != nil { return nil, fmt.Errorf("failed to convert 'data.year': %w", err) } - } else if !skipNotFound { - return nil, fmt.Errorf("%w, field 'data.year'", errNotFound) } return &vehicle, nil }