diff --git a/clients/go/m3o.go b/clients/go/m3o.go index d41131e..60f4916 100755 --- a/clients/go/m3o.go +++ b/clients/go/m3o.go @@ -37,6 +37,7 @@ import ( "github.com/micro/services/clients/go/twitter" "github.com/micro/services/clients/go/url" "github.com/micro/services/clients/go/user" + "github.com/micro/services/clients/go/vehicle" "github.com/micro/services/clients/go/weather" ) @@ -80,6 +81,7 @@ func NewClient(token string) *Client { TwitterService: twitter.NewTwitterService(token), UrlService: url.NewUrlService(token), UserService: user.NewUserService(token), + VehicleService: vehicle.NewVehicleService(token), WeatherService: weather.NewWeatherService(token), } } @@ -123,5 +125,6 @@ type Client struct { TwitterService *twitter.TwitterService UrlService *url.UrlService UserService *user.UserService + VehicleService *vehicle.VehicleService WeatherService *weather.WeatherService } diff --git a/clients/go/vehicle/vehicle.go b/clients/go/vehicle/vehicle.go new file mode 100755 index 0000000..a82da4c --- /dev/null +++ b/clients/go/vehicle/vehicle.go @@ -0,0 +1,61 @@ +package vehicle + +import ( + "github.com/m3o/m3o-go/client" +) + +func NewVehicleService(token string) *VehicleService { + return &VehicleService{ + client: client.NewClient(&client.Options{ + Token: token, + }), + } +} + +type VehicleService struct { + client *client.Client +} + +// Lookup a UK vehicle by it's registration number +func (t *VehicleService) Lookup(request *LookupRequest) (*LookupResponse, error) { + rsp := &LookupResponse{} + return rsp, t.client.Call("vehicle", "Lookup", request, rsp) +} + +type LookupRequest struct { + // the vehicle registration number + Registration string `json:"registration"` +} + +type LookupResponse struct { + // co2 emmissions + Co2emissions float64 `json:"co2emissions"` + // colour of vehicle + Colour string `json:"colour"` + // engine capacity + EngineCapacity int32 `json:"engineCapacity"` + // fuel type e.g petrol, diesel + FuelType string `json:"fuelType"` + // date of last v5 issue + LastV5issued string `json:"lastV5issued"` + // make of vehicle + Make string `json:"make"` + // month of first registration + MonthOfFirstRegistration string `json:"monthOfFirstRegistration"` + // mot expiry + MotExpiry string `json:"motExpiry"` + // mot status + MotStatus string `json:"motStatus"` + // registration number + Registration string `json:"registration"` + // tax due data + TaxDueDate string `json:"taxDueDate"` + // tax status + TaxStatus string `json:"taxStatus"` + // type approvale + TypeApproval string `json:"typeApproval"` + // wheel plan + Wheelplan string `json:"wheelplan"` + // year of manufacture + YearOfManufacture int32 `json:"yearOfManufacture"` +} diff --git a/clients/ts/index.ts b/clients/ts/index.ts index 8b0af10..7543fb4 100755 --- a/clients/ts/index.ts +++ b/clients/ts/index.ts @@ -34,6 +34,7 @@ import * as time from "./time"; import * as twitter from "./twitter"; import * as url from "./url"; import * as user from "./user"; +import * as vehicle from "./vehicle"; import * as weather from "./weather"; export class Client { @@ -74,6 +75,7 @@ export class Client { this.twitterService = new twitter.TwitterService(token); this.urlService = new url.UrlService(token); this.userService = new user.UserService(token); + this.vehicleService = new vehicle.VehicleService(token); this.weatherService = new weather.WeatherService(token); } @@ -113,5 +115,6 @@ export class Client { twitterService: twitter.TwitterService; urlService: url.UrlService; userService: user.UserService; + vehicleService: vehicle.VehicleService; weatherService: weather.WeatherService; } diff --git a/clients/ts/package.json b/clients/ts/package.json index 7cd1de7..de4c07a 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -47,6 +47,7 @@ "./twitter": "./dist/twitter/index.js", "./url": "./dist/url/index.js", "./user": "./dist/user/index.js", + "./vehicle": "./dist/vehicle/index.js", "./weather": "./dist/weather/index.js" }, "license": "ISC", @@ -63,5 +64,5 @@ }, "type": "module", "types": "dist/index.d.ts", - "version": "1.0.534" + "version": "1.0.535" } \ No newline at end of file diff --git a/clients/ts/vehicle/index.ts b/clients/ts/vehicle/index.ts new file mode 100755 index 0000000..634c894 --- /dev/null +++ b/clients/ts/vehicle/index.ts @@ -0,0 +1,55 @@ +import * as m3o from "@m3o/m3o-node"; + +export class VehicleService { + private client: m3o.Client; + + constructor(token: string) { + this.client = new m3o.Client({ token: token }); + } + // Lookup a UK vehicle by it's registration number + lookup(request: LookupRequest): Promise { + return this.client.call( + "vehicle", + "Lookup", + request + ) as Promise; + } +} + +export interface LookupRequest { + // the vehicle registration number + registration?: string; +} + +export interface LookupResponse { + // co2 emmissions + co2Emissions?: number; + // colour of vehicle + colour?: string; + // engine capacity + engineCapacity?: number; + // fuel type e.g petrol, diesel + fuelType?: string; + // date of last v5 issue + lastV5Issued?: string; + // make of vehicle + make?: string; + // month of first registration + monthOfFirstRegistration?: string; + // mot expiry + motExpiry?: string; + // mot status + motStatus?: string; + // registration number + registration?: string; + // tax due data + taxDueDate?: string; + // tax status + taxStatus?: string; + // type approvale + typeApproval?: string; + // wheel plan + wheelplan?: string; + // year of manufacture + yearOfManufacture?: number; +} diff --git a/examples/vehicle/lookup/curl/lookupVehicle.sh b/examples/vehicle/lookup/curl/lookupVehicle.sh new file mode 100755 index 0000000..00c867e --- /dev/null +++ b/examples/vehicle/lookup/curl/lookupVehicle.sh @@ -0,0 +1,6 @@ +curl "https://api.m3o.com/v1/vehicle/Lookup" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "registration": "LC60OTA" +}' \ No newline at end of file diff --git a/examples/vehicle/lookup/go/lookupVehicle.go b/examples/vehicle/lookup/go/lookupVehicle.go new file mode 100755 index 0000000..03e1c47 --- /dev/null +++ b/examples/vehicle/lookup/go/lookupVehicle.go @@ -0,0 +1,16 @@ +package example + +import ( + "fmt" + "github.com/micro/services/clients/go/vehicle" + "os" +) + +// Lookup a UK vehicle by it's registration number +func LookupVehicle() { + vehicleService := vehicle.NewVehicleService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := vehicleService.Lookup(&vehicle.LookupRequest{ + Registration: "LC60OTA", + }) + fmt.Println(rsp, err) +} diff --git a/examples/vehicle/lookup/node/lookupVehicle.js b/examples/vehicle/lookup/node/lookupVehicle.js new file mode 100755 index 0000000..563489e --- /dev/null +++ b/examples/vehicle/lookup/node/lookupVehicle.js @@ -0,0 +1,12 @@ +import * as vehicle from "m3o/vehicle"; + +// Lookup a UK vehicle by it's registration number +async function LookupVehicle() { + let vehicleService = new vehicle.VehicleService(process.env.MICRO_API_TOKEN); + let rsp = await vehicleService.lookup({ + registration: "LC60OTA", + }); + console.log(rsp); +} + +await LookupVehicle(); diff --git a/pkg/api/api.go b/pkg/api/api.go index 74b29b0..ee021f0 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -2,6 +2,7 @@ package api import ( + "bytes" "encoding/json" "fmt" "io/ioutil" @@ -45,3 +46,41 @@ func Get(url string, rsp interface{}) error { return json.Unmarshal(b, rsp) } + +// Post a url and unmarshal a json body into the given value +func Post(url string, ureq, rsp interface{}) error { + b, err := json.Marshal(ureq) + if err != nil { + return err + } + + req, err := http.NewRequest("POST", url, bytes.NewReader(b)) + if err != nil { + return err + } + + for k, v := range keys { + req.Header.Set(k, v) + } + + if v := req.Header.Get("Content-Type"); len(v) == 0 { + req.Header.Set("Content-Type", "application/json") + } + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + b, err = ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + + if resp.StatusCode != 200 { + return fmt.Errorf("Non 200 response %v: %v", resp.StatusCode, string(b)) + } + + return json.Unmarshal(b, rsp) +} diff --git a/vehicle/.gitignore b/vehicle/.gitignore new file mode 100644 index 0000000..b523e93 --- /dev/null +++ b/vehicle/.gitignore @@ -0,0 +1,2 @@ + +vehicle diff --git a/vehicle/Dockerfile b/vehicle/Dockerfile new file mode 100644 index 0000000..315bfc3 --- /dev/null +++ b/vehicle/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +ADD vehicle /vehicle +ENTRYPOINT [ "/vehicle" ] diff --git a/vehicle/Makefile b/vehicle/Makefile new file mode 100644 index 0000000..7d98428 --- /dev/null +++ b/vehicle/Makefile @@ -0,0 +1,28 @@ + +GOPATH:=$(shell go env GOPATH) +.PHONY: init +init: + go get -u github.com/golang/protobuf/proto + go get -u github.com/golang/protobuf/protoc-gen-go + go get github.com/micro/micro/v3/cmd/protoc-gen-micro + go get github.com/micro/micro/v3/cmd/protoc-gen-openapi + +.PHONY: api +api: + protoc --openapi_out=. --proto_path=. proto/vehicle.proto + +.PHONY: proto +proto: + protoc --proto_path=. --micro_out=. --go_out=:. proto/vehicle.proto + +.PHONY: build +build: + go build -o vehicle *.go + +.PHONY: test +test: + go test -v ./... -cover + +.PHONY: docker +docker: + docker build . -t vehicle:latest diff --git a/vehicle/README.md b/vehicle/README.md new file mode 100644 index 0000000..de0db20 --- /dev/null +++ b/vehicle/README.md @@ -0,0 +1,5 @@ +UK vehicle lookup + +# Vehicle Service + +Find a UK vehicle via it's registration number. diff --git a/vehicle/examples.json b/vehicle/examples.json new file mode 100644 index 0000000..73d459e --- /dev/null +++ b/vehicle/examples.json @@ -0,0 +1,28 @@ + +{ + "lookup": [{ + "title": "Lookup vehicle", + "description": "Lookup vehicle by UK registration", + "run_check": false, + "request": { + "registration": "LC60OTA" + }, + "response": { + "registration": "LC60OTA", + "make": "MAZDA", + "colour": "BLUE", + "year_of_manufacture": 2010, + "co2_emissions": 119, + "engine_capacity": 1560, + "fuel_type": "DIESEL", + "month_of_first_registration": "2010-12", + "mot_status": "Valid", + "mot_expiry": "2022-01-15", + "tax_due_date": "2022-06-01", + "tax_status": "Taxed", + "type_approval": "M1", + "wheelplan": "2 AXLE RIGID BODY", + "last_v5_issued": "2018-01-12" + } + }] +} diff --git a/vehicle/generate.go b/vehicle/generate.go new file mode 100644 index 0000000..96f431a --- /dev/null +++ b/vehicle/generate.go @@ -0,0 +1,2 @@ +package main +//go:generate make proto diff --git a/vehicle/handler/vehicle.go b/vehicle/handler/vehicle.go new file mode 100644 index 0000000..3eb6363 --- /dev/null +++ b/vehicle/handler/vehicle.go @@ -0,0 +1,64 @@ +package handler + +import ( + "context" + + "github.com/micro/services/pkg/api" + "github.com/micro/micro/v3/service/errors" + "github.com/micro/micro/v3/service/logger" + pb "github.com/micro/services/vehicle/proto" +) + +var ( + apiURL = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles" +) + +type Vehicle struct{ + Key string +} + +func New(key string) *Vehicle { + api.SetKey("x-api-key", key) + + return &Vehicle{ + Key: key, + } +} + +func (v *Vehicle) Lookup(ctx context.Context, req *pb.LookupRequest, rsp *pb.LookupResponse) error { + if len(req.Registration) == 0 { + return errors.BadRequest("vehicle.lookup", "missing registration number") + } + + var resp map[string]interface{} + + if err := api.Post(apiURL, map[string]interface{}{ + "registrationNumber": req.Registration, + }, &resp); err != nil { + logger.Errorf("Failed to lookup vehicle %v: %v", req.Registration, err) + 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) + + if v := resp["motExpiryDate"]; v != nil { + 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) + + return nil +} + diff --git a/vehicle/main.go b/vehicle/main.go new file mode 100644 index 0000000..5e526c3 --- /dev/null +++ b/vehicle/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "github.com/micro/services/vehicle/handler" + pb "github.com/micro/services/vehicle/proto" + + "github.com/micro/micro/v3/service" + "github.com/micro/micro/v3/service/config" + "github.com/micro/micro/v3/service/logger" +) + +func main() { + // Create service + srv := service.New( + service.Name("vehicle"), + service.Version("latest"), + ) + + v, err := config.Get("dvla.api_key") + if err != nil { + logger.Fatalf("sunnha.api_key config not found: %v", err) + } + key := v.String("") + if len(key) == 0 { + logger.Fatal("dvla.api_key config not found") + } + + // Register handler + pb.RegisterVehicleHandler(srv.Server(), handler.New(key)) + + // Run service + if err := srv.Run(); err != nil { + logger.Fatal(err) + } +} diff --git a/vehicle/micro.mu b/vehicle/micro.mu new file mode 100644 index 0000000..6fbc203 --- /dev/null +++ b/vehicle/micro.mu @@ -0,0 +1 @@ +service vehicle diff --git a/vehicle/proto/vehicle.pb.go b/vehicle/proto/vehicle.pb.go new file mode 100644 index 0000000..a0c0b0e --- /dev/null +++ b/vehicle/proto/vehicle.pb.go @@ -0,0 +1,373 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.6 +// source: proto/vehicle.proto + +package vehicle + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Lookup a UK vehicle by it's registration number +type LookupRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the vehicle registration number + Registration string `protobuf:"bytes,1,opt,name=registration,proto3" json:"registration,omitempty"` +} + +func (x *LookupRequest) Reset() { + *x = LookupRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_vehicle_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LookupRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupRequest) ProtoMessage() {} + +func (x *LookupRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_vehicle_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupRequest.ProtoReflect.Descriptor instead. +func (*LookupRequest) Descriptor() ([]byte, []int) { + return file_proto_vehicle_proto_rawDescGZIP(), []int{0} +} + +func (x *LookupRequest) GetRegistration() string { + if x != nil { + return x.Registration + } + return "" +} + +type LookupResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // registration number + Registration string `protobuf:"bytes,1,opt,name=registration,proto3" json:"registration,omitempty"` + // make of vehicle + Make string `protobuf:"bytes,2,opt,name=make,proto3" json:"make,omitempty"` + // colour of vehicle + Colour string `protobuf:"bytes,3,opt,name=colour,proto3" json:"colour,omitempty"` + // year of manufacture + YearOfManufacture int32 `protobuf:"varint,4,opt,name=year_of_manufacture,json=yearOfManufacture,proto3" json:"year_of_manufacture,omitempty"` + // co2 emmissions + Co2Emissions float64 `protobuf:"fixed64,5,opt,name=co2_emissions,json=co2Emissions,proto3" json:"co2_emissions,omitempty"` + // engine capacity + EngineCapacity int32 `protobuf:"varint,6,opt,name=engine_capacity,json=engineCapacity,proto3" json:"engine_capacity,omitempty"` + // fuel type e.g petrol, diesel + FuelType string `protobuf:"bytes,7,opt,name=fuel_type,json=fuelType,proto3" json:"fuel_type,omitempty"` + // month of first registration + MonthOfFirstRegistration string `protobuf:"bytes,8,opt,name=month_of_first_registration,json=monthOfFirstRegistration,proto3" json:"month_of_first_registration,omitempty"` + // mot status + MotStatus string `protobuf:"bytes,9,opt,name=mot_status,json=motStatus,proto3" json:"mot_status,omitempty"` + // mot expiry + MotExpiry string `protobuf:"bytes,10,opt,name=mot_expiry,json=motExpiry,proto3" json:"mot_expiry,omitempty"` + // tax due data + TaxDueDate string `protobuf:"bytes,11,opt,name=tax_due_date,json=taxDueDate,proto3" json:"tax_due_date,omitempty"` + // tax status + TaxStatus string `protobuf:"bytes,12,opt,name=tax_status,json=taxStatus,proto3" json:"tax_status,omitempty"` + // type approvale + TypeApproval string `protobuf:"bytes,13,opt,name=type_approval,json=typeApproval,proto3" json:"type_approval,omitempty"` + // wheel plan + Wheelplan string `protobuf:"bytes,14,opt,name=wheelplan,proto3" json:"wheelplan,omitempty"` + // date of last v5 issue + LastV5Issued string `protobuf:"bytes,15,opt,name=last_v5_issued,json=lastV5Issued,proto3" json:"last_v5_issued,omitempty"` +} + +func (x *LookupResponse) Reset() { + *x = LookupResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_vehicle_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LookupResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LookupResponse) ProtoMessage() {} + +func (x *LookupResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_vehicle_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LookupResponse.ProtoReflect.Descriptor instead. +func (*LookupResponse) Descriptor() ([]byte, []int) { + return file_proto_vehicle_proto_rawDescGZIP(), []int{1} +} + +func (x *LookupResponse) GetRegistration() string { + if x != nil { + return x.Registration + } + return "" +} + +func (x *LookupResponse) GetMake() string { + if x != nil { + return x.Make + } + return "" +} + +func (x *LookupResponse) GetColour() string { + if x != nil { + return x.Colour + } + return "" +} + +func (x *LookupResponse) GetYearOfManufacture() int32 { + if x != nil { + return x.YearOfManufacture + } + return 0 +} + +func (x *LookupResponse) GetCo2Emissions() float64 { + if x != nil { + return x.Co2Emissions + } + return 0 +} + +func (x *LookupResponse) GetEngineCapacity() int32 { + if x != nil { + return x.EngineCapacity + } + return 0 +} + +func (x *LookupResponse) GetFuelType() string { + if x != nil { + return x.FuelType + } + return "" +} + +func (x *LookupResponse) GetMonthOfFirstRegistration() string { + if x != nil { + return x.MonthOfFirstRegistration + } + return "" +} + +func (x *LookupResponse) GetMotStatus() string { + if x != nil { + return x.MotStatus + } + return "" +} + +func (x *LookupResponse) GetMotExpiry() string { + if x != nil { + return x.MotExpiry + } + return "" +} + +func (x *LookupResponse) GetTaxDueDate() string { + if x != nil { + return x.TaxDueDate + } + return "" +} + +func (x *LookupResponse) GetTaxStatus() string { + if x != nil { + return x.TaxStatus + } + return "" +} + +func (x *LookupResponse) GetTypeApproval() string { + if x != nil { + return x.TypeApproval + } + return "" +} + +func (x *LookupResponse) GetWheelplan() string { + if x != nil { + return x.Wheelplan + } + return "" +} + +func (x *LookupResponse) GetLastV5Issued() string { + if x != nil { + return x.LastV5Issued + } + return "" +} + +var File_proto_vehicle_proto protoreflect.FileDescriptor + +var file_proto_vehicle_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x65, 0x68, 0x69, 0x63, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x76, 0x65, 0x68, 0x69, 0x63, 0x6c, 0x65, 0x22, 0x33, + 0x0a, 0x0d, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x22, 0x0a, 0x0c, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x04, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x61, + 0x6b, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x61, 0x6b, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x12, 0x2e, 0x0a, 0x13, 0x79, 0x65, 0x61, 0x72, 0x5f, 0x6f, + 0x66, 0x5f, 0x6d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63, 0x74, 0x75, 0x72, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x11, 0x79, 0x65, 0x61, 0x72, 0x4f, 0x66, 0x4d, 0x61, 0x6e, 0x75, 0x66, + 0x61, 0x63, 0x74, 0x75, 0x72, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x32, 0x5f, 0x65, 0x6d, + 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0c, 0x63, + 0x6f, 0x32, 0x45, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x27, 0x0a, 0x0f, 0x65, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x63, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x43, 0x61, 0x70, 0x61, + 0x63, 0x69, 0x74, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x66, 0x75, 0x65, 0x6c, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x65, 0x6c, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x3d, 0x0a, 0x1b, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x5f, 0x6f, 0x66, 0x5f, 0x66, 0x69, + 0x72, 0x73, 0x74, 0x5f, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x4f, 0x66, 0x46, + 0x69, 0x72, 0x73, 0x74, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x6f, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x6f, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x1d, 0x0a, 0x0a, 0x6d, 0x6f, 0x74, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x79, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x6f, 0x74, 0x45, 0x78, 0x70, 0x69, 0x72, 0x79, 0x12, 0x20, + 0x0a, 0x0c, 0x74, 0x61, 0x78, 0x5f, 0x64, 0x75, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x0b, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x61, 0x78, 0x44, 0x75, 0x65, 0x44, 0x61, 0x74, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x61, 0x78, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x78, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x23, 0x0a, 0x0d, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x76, 0x61, 0x6c, + 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x74, 0x79, 0x70, 0x65, 0x41, 0x70, 0x70, 0x72, + 0x6f, 0x76, 0x61, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x77, 0x68, 0x65, 0x65, 0x6c, 0x70, 0x6c, 0x61, + 0x6e, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x77, 0x68, 0x65, 0x65, 0x6c, 0x70, 0x6c, + 0x61, 0x6e, 0x12, 0x24, 0x0a, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x76, 0x35, 0x5f, 0x69, 0x73, + 0x73, 0x75, 0x65, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, + 0x56, 0x35, 0x49, 0x73, 0x73, 0x75, 0x65, 0x64, 0x32, 0x46, 0x0a, 0x07, 0x56, 0x65, 0x68, 0x69, + 0x63, 0x6c, 0x65, 0x12, 0x3b, 0x0a, 0x06, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x12, 0x16, 0x2e, + 0x76, 0x65, 0x68, 0x69, 0x63, 0x6c, 0x65, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x76, 0x65, 0x68, 0x69, 0x63, 0x6c, 0x65, 0x2e, + 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x76, 0x65, 0x68, 0x69, + 0x63, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_vehicle_proto_rawDescOnce sync.Once + file_proto_vehicle_proto_rawDescData = file_proto_vehicle_proto_rawDesc +) + +func file_proto_vehicle_proto_rawDescGZIP() []byte { + file_proto_vehicle_proto_rawDescOnce.Do(func() { + file_proto_vehicle_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_vehicle_proto_rawDescData) + }) + return file_proto_vehicle_proto_rawDescData +} + +var file_proto_vehicle_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_vehicle_proto_goTypes = []interface{}{ + (*LookupRequest)(nil), // 0: vehicle.LookupRequest + (*LookupResponse)(nil), // 1: vehicle.LookupResponse +} +var file_proto_vehicle_proto_depIdxs = []int32{ + 0, // 0: vehicle.Vehicle.Lookup:input_type -> vehicle.LookupRequest + 1, // 1: vehicle.Vehicle.Lookup:output_type -> vehicle.LookupResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_proto_vehicle_proto_init() } +func file_proto_vehicle_proto_init() { + if File_proto_vehicle_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_vehicle_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LookupRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_vehicle_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LookupResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_vehicle_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_vehicle_proto_goTypes, + DependencyIndexes: file_proto_vehicle_proto_depIdxs, + MessageInfos: file_proto_vehicle_proto_msgTypes, + }.Build() + File_proto_vehicle_proto = out.File + file_proto_vehicle_proto_rawDesc = nil + file_proto_vehicle_proto_goTypes = nil + file_proto_vehicle_proto_depIdxs = nil +} diff --git a/vehicle/proto/vehicle.pb.micro.go b/vehicle/proto/vehicle.pb.micro.go new file mode 100644 index 0000000..5f9b613 --- /dev/null +++ b/vehicle/proto/vehicle.pb.micro.go @@ -0,0 +1,93 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/vehicle.proto + +package vehicle + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + api "github.com/micro/micro/v3/service/api" + client "github.com/micro/micro/v3/service/client" + server "github.com/micro/micro/v3/service/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for Vehicle service + +func NewVehicleEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Vehicle service + +type VehicleService interface { + Lookup(ctx context.Context, in *LookupRequest, opts ...client.CallOption) (*LookupResponse, error) +} + +type vehicleService struct { + c client.Client + name string +} + +func NewVehicleService(name string, c client.Client) VehicleService { + return &vehicleService{ + c: c, + name: name, + } +} + +func (c *vehicleService) Lookup(ctx context.Context, in *LookupRequest, opts ...client.CallOption) (*LookupResponse, error) { + req := c.c.NewRequest(c.name, "Vehicle.Lookup", in) + out := new(LookupResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Vehicle service + +type VehicleHandler interface { + Lookup(context.Context, *LookupRequest, *LookupResponse) error +} + +func RegisterVehicleHandler(s server.Server, hdlr VehicleHandler, opts ...server.HandlerOption) error { + type vehicle interface { + Lookup(ctx context.Context, in *LookupRequest, out *LookupResponse) error + } + type Vehicle struct { + vehicle + } + h := &vehicleHandler{hdlr} + return s.Handle(s.NewHandler(&Vehicle{h}, opts...)) +} + +type vehicleHandler struct { + VehicleHandler +} + +func (h *vehicleHandler) Lookup(ctx context.Context, in *LookupRequest, out *LookupResponse) error { + return h.VehicleHandler.Lookup(ctx, in, out) +} diff --git a/vehicle/proto/vehicle.proto b/vehicle/proto/vehicle.proto new file mode 100644 index 0000000..4a24795 --- /dev/null +++ b/vehicle/proto/vehicle.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; + +package vehicle; + +option go_package = "./proto;vehicle"; + +service Vehicle { + rpc Lookup(LookupRequest) returns (LookupResponse) {} +} + +// Lookup a UK vehicle by it's registration number +message LookupRequest { + // the vehicle registration number + string registration = 1; +} + +message LookupResponse { + // registration number + string registration = 1; + // make of vehicle + string make = 2; + // colour of vehicle + string colour = 3; + // year of manufacture + int32 year_of_manufacture = 4; + // co2 emmissions + double co2_emissions = 5; + // engine capacity + int32 engine_capacity = 6; + // fuel type e.g petrol, diesel + string fuel_type = 7; + // month of first registration + string month_of_first_registration = 8; + // mot status + string mot_status = 9; + // mot expiry + string mot_expiry = 10; + // tax due data + string tax_due_date = 11; + // tax status + string tax_status = 12; + // type approvale + string type_approval = 13; + // wheel plan + string wheelplan = 14; + // date of last v5 issue + string last_v5_issued = 15; +} diff --git a/vehicle/publicapi.json b/vehicle/publicapi.json new file mode 100644 index 0000000..b20f37d --- /dev/null +++ b/vehicle/publicapi.json @@ -0,0 +1,5 @@ +{ + "name": "vehicle", + "icon": "🚗", + "category": "dvla" +}