common

package
v1.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PowerTrainType = "powertrain_type"

	// VehicleMetadataKey is the default json key where we store vehicle metadata in device_definitions.metadata
	VehicleMetadataKey     = "vehicle_info"
	AftermarketMetadataKey = "aftermarket-device"
)
View Source
const (
	SmartCarVendor = "SmartCar"
	AutoPiVendor   = "AutoPi"
)
View Source
const (
	DefaultDeviceType     = "vehicle"
	DefautlAutoPiTemplate = "130" // dimo device client template
)

Variables

View Source
var ErrUnmintableDefinitionID = errors.New("definition id is one definitions-worker can never accept")

ErrUnmintableDefinitionID reports an id no template can ever be stored at: definitions-worker's ID_RE refuses it, so its create answers 422 and so does every retry of every VIN of that model-year, forever. It is a sentinel so a caller can tell this apart from a transient write failure with errors.Is and stop rather than retry.

Functions

func AttributeString added in v1.6.5

func AttributeString(v any) string

AttributeString renders a typed template attribute for the legacy string-valued shapes the API still serves.

Template attributes decode into map[string]any, so every number arrives as a float64. strconv rather than fmt so 15.8 renders "15.8" and not "1.58e+01", and a price of 1250000 renders "1250000" and not "1.25e+06". Both the definition path and the device-style path call this, so one definition's attributes read the same whichever endpoint served them.

func BuildDeviceDefinitionName added in v0.4.3

func BuildDeviceDefinitionName(year int16, mk string, model string) string

func BuildDeviceTypeAttributes added in v0.2.0

func BuildDeviceTypeAttributes(attributes []*coremodels.UpdateDeviceTypeAttribute, dt *repoModel.DeviceType) (null.JSON, error)

func BuildExternalIDs added in v1.0.38

func BuildExternalIDs(externalIDsJSON null.JSON) []*coremodels.ExternalID

func Contains added in v0.1.4

func Contains(s []string, str string) bool

Contains returns true if string exist in slice

func ConvertDeviceTypeAttrsToDefinitionMetadata added in v1.2.95

func ConvertDeviceTypeAttrsToDefinitionMetadata(attributes []*coremodels.UpdateDeviceTypeAttribute) *coremodels.DeviceDefinitionMetadata

func ConvertMetadataToDeviceAttributes added in v1.2.95

func ConvertMetadataToDeviceAttributes(metadata *coremodels.DeviceDefinitionMetadata) []coremodels.DeviceTypeAttributeEditor

func DeviceDefinitionSlug added in v1.1.9

func DeviceDefinitionSlug(makeSlug, modelSlug string, year int16) (string, error)

DeviceDefinitionSlug builds <make>_<model>_<year>, the template id, and refuses one definitions-worker can never hold.

The repair below drops characters, and dropping every character of a part leaves a segment ID_RE refuses just as firmly as the id it replaced. So the builder checks its own output: an id that fails ValidateDefinitionID comes back as ("", err) wrapping ErrUnmintableDefinitionID, and the id is not returned alongside it -- a caller that ignores the error must not be able to write the row or send the PUT anyway. Before this, only one of the five production call sites validated, and the contract on ValidateDefinitionID ("nothing may PUT, or build a vin_numbers row on, an id that fails it") was enforced nowhere else.

An id the worker already accepts is returned exactly as it has always been built. The catalog holds ids like volkswagen_id--buzz_2024 (model "ID. Buzz" slugs to id--buzz) and bmw_x3-_2026, and reshaping those would point every new decode of that model at an id with no template, which the decode then creates as a duplicate. Only an id the worker would refuse is repaired: each part is slugged, which also covers cmd/device-definitions-api passing the make and model raw, and stripped of every character outside the worker's class. Nothing else changes, so the raw and slugged inputs for one model still agree. An underscore can never survive inside a part: it is the separator, and templateFromDefinition reads the manufacturer slug back as everything before the first one.

func GetDefaultImageURL added in v0.7.4

func GetDefaultImageURL(images []*repoModel.Image) string

GetDefaultImageURL if the images relation is not empty, looks for the best image to use based on some logic

func GetDeviceAttributesTyped added in v0.8.8

func GetDeviceAttributesTyped(metadata null.JSON, key string) []coremodels.DeviceTypeAttributeEditor

func JSONOrDefault added in v0.1.2

func JSONOrDefault(j null.JSON) json.RawMessage

func SortedAttributeNames added in v1.6.5

func SortedAttributeNames(attributes map[string]any) []string

SortedAttributeNames returns a template's attribute names in a stable order.

Ranging over the map directly puts the attributes in a different order on every call, so two requests for the same definition answered with the same attributes in a different arrangement.

func ValidateDefinitionID added in v1.6.5

func ValidateDefinitionID(id string) error

ValidateDefinitionID reports whether definitions-worker can hold a template at this id, and wraps ErrUnmintableDefinitionID when it cannot.

DeviceDefinitionSlug repairs an id by dropping characters, and a repair that drops every character of a part leaves a segment empty -- an id ID_RE refuses just as firmly as the one the repair replaced. The repair never re-checks its own output, so this is the check: nothing may PUT, or build a vin_numbers row on, an id that fails it.

Types

type ErrorResponse

type ErrorResponse struct {
	Field string
	Tag   string
	Value string
}

type RegionEnum added in v0.1.6

type RegionEnum string
const (
	AmericasRegion RegionEnum = "Americas"
	EuropeRegion   RegionEnum = "Europe"
)

func (RegionEnum) String added in v0.1.6

func (r RegionEnum) String() string

type TxStatusResponse added in v1.2.95

type TxStatusResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
	Result  struct {
		Status string `json:"status"`
	} `json:"result"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL