Files
cloud-services/pkg/common/car_location.go

42 lines
979 B
Go

package common
import (
"encoding/json"
"github.com/pkg/errors"
)
// Location represents the location state of the car
type Location struct {
Altitude float64 `json:"altitude" redis:"altitude"`
Longitude float64 `json:"longitude" redis:"longitude"`
Latitude float64 `json:"latitude" redis:"latitude"`
Heading float64 `json:"-" redis:"heading"`
}
func (l *Location) Marshal() ([]byte, error) {
data, err := json.Marshal(*l)
return data, errors.WithStack(err)
}
func (l *Location) Unmarshal(data []byte) error {
err := json.Unmarshal(data, l)
return errors.WithStack(err)
}
func (it *Location) MarshalBinary() ([]byte, error) {
return json.Marshal(it)
}
func (it *Location) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, it)
}
type JSONCarLocation struct {
VIN string `json:"vin"`
Altitude float64 `json:"altitude"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Heading float64 `json:"heading"`
}