From 40006de6eed1c76e59d624855fa662550ea7f735 Mon Sep 17 00:00:00 2001 From: Dominic Wong Date: Fri, 8 Oct 2021 11:55:02 +0100 Subject: [PATCH] Fix panic in vehicle service (#226) * fix panic * Commit from GitHub Actions (Publish APIs & Clients) Co-authored-by: domwong --- clients/ts/package.json | 2 +- examples/db/create/go/createARecord.go | 2 +- examples/stream/publish/go/publishAMessage.go | 2 +- vehicle/handler/vehicle.go | 37 ++++++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/clients/ts/package.json b/clients/ts/package.json index a9b33b5..6b3aecd 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -65,5 +65,5 @@ }, "type": "module", "types": "dist/index.d.ts", - "version": "1.0.542" + "version": "1.0.543" } \ No newline at end of file diff --git a/examples/db/create/go/createARecord.go b/examples/db/create/go/createARecord.go index c57135b..f9cc6bc 100755 --- a/examples/db/create/go/createARecord.go +++ b/examples/db/create/go/createARecord.go @@ -11,10 +11,10 @@ func CreateArecord() { dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN")) rsp, err := dbService.Create(&db.CreateRequest{ Record: map[string]interface{}{ - "age": 42, "isActive": true, "id": "1", "name": "Jane", + "age": 42, }, Table: "users", }) diff --git a/examples/stream/publish/go/publishAMessage.go b/examples/stream/publish/go/publishAMessage.go index f7db1b0..af88ee1 100755 --- a/examples/stream/publish/go/publishAMessage.go +++ b/examples/stream/publish/go/publishAMessage.go @@ -11,9 +11,9 @@ func PublishAmessage() { streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN")) rsp, err := streamService.Publish(&stream.PublishRequest{ Message: map[string]interface{}{ + "id": "1", "type": "signup", "user": "john", - "id": "1", }, Topic: "events", }) diff --git a/vehicle/handler/vehicle.go b/vehicle/handler/vehicle.go index 3eb6363..3990260 100644 --- a/vehicle/handler/vehicle.go +++ b/vehicle/handler/vehicle.go @@ -3,9 +3,9 @@ package handler import ( "context" - "github.com/micro/services/pkg/api" "github.com/micro/micro/v3/service/errors" "github.com/micro/micro/v3/service/logger" + "github.com/micro/services/pkg/api" pb "github.com/micro/services/vehicle/proto" ) @@ -13,7 +13,7 @@ var ( apiURL = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles" ) -type Vehicle struct{ +type Vehicle struct { Key string } @@ -39,26 +39,27 @@ func (v *Vehicle) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.Loo return errors.InternalServerError("vehicle.lookup", "Failed to lookup vehicle") } - rsp.Registration = resp["registrationNumber"].(string) - rsp.Make = resp["make"].(string) - rsp.Co2Emissions = resp["co2Emissions"].(float64) - rsp.Colour = resp["colour"].(string) - rsp.YearOfManufacture = int32(resp["yearOfManufacture"].(float64)) - rsp.EngineCapacity = int32(resp["engineCapacity"].(float64)) - rsp.FuelType = resp["fuelType"].(string) - rsp.MonthOfFirstRegistration = resp["monthOfFirstRegistration"].(string) - rsp.MotStatus = resp["motStatus"].(string) + rsp.Registration, _ = resp["registrationNumber"].(string) + rsp.Make, _ = resp["make"].(string) + rsp.Co2Emissions, _ = resp["co2Emissions"].(float64) + rsp.Colour, _ = resp["colour"].(string) + yom, _ := resp["yearOfManufacture"].(float64) + rsp.YearOfManufacture = int32(yom) + ec, _ := resp["engineCapacity"].(float64) + rsp.EngineCapacity = int32(ec) + rsp.FuelType, _ = resp["fuelType"].(string) + rsp.MonthOfFirstRegistration, _ = resp["monthOfFirstRegistration"].(string) + rsp.MotStatus, _ = resp["motStatus"].(string) if v := resp["motExpiryDate"]; v != nil { - rsp.MotExpiry = v.(string) + rsp.MotExpiry, _ = v.(string) } - rsp.TaxDueDate = resp["taxDueDate"].(string) - rsp.TaxStatus = resp["taxStatus"].(string) - rsp.TypeApproval = resp["typeApproval"].(string) - rsp.Wheelplan = resp["wheelplan"].(string) - rsp.LastV5Issued = resp["dateOfLastV5CIssued"].(string) + rsp.TaxDueDate, _ = resp["taxDueDate"].(string) + rsp.TaxStatus, _ = resp["taxStatus"].(string) + rsp.TypeApproval, _ = resp["typeApproval"].(string) + rsp.Wheelplan, _ = resp["wheelplan"].(string) + rsp.LastV5Issued, _ = resp["dateOfLastV5CIssued"].(string) return nil } -