Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
41
pkg/common/car_location.go
Normal file
41
pkg/common/car_location.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user