add address lookup service (#197)

This commit is contained in:
Asim Aslam
2021-08-27 12:37:59 +01:00
committed by GitHub
parent 84b9a63461
commit 5f9aa35d91
12 changed files with 709 additions and 0 deletions

2
address/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
address

3
address/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM alpine
ADD address /address
ENTRYPOINT [ "/address" ]

28
address/Makefile Normal file
View File

@@ -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/address.proto
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=. --go_out=:. proto/address.proto
.PHONY: build
build:
go build -o address *.go
.PHONY: test
test:
go test -v ./... -cover
.PHONY: docker
docker:
docker build . -t address:latest

6
address/README.md Normal file
View File

@@ -0,0 +1,6 @@
UK Address lookup by postcode
# Address Service
Lookup UK addresses by postcode or address fragments. Includes PAF and multiple residence data.

3
address/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package main
//go:generate make proto

View File

@@ -0,0 +1,85 @@
package handler
import (
"context"
"fmt"
"strings"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
pb "github.com/micro/services/address/proto"
"github.com/micro/services/pkg/api"
)
var (
AddressURL = "https://ws.postcoder.com/pcw/"
)
type Address struct {
Url string
Key string
}
func field(key string, vals map[string]interface{}) string {
if v, ok := vals[key].(string); ok {
return v
}
return ""
}
func (a *Address) lookupPostcode(q string, rsp interface{}) error {
u := fmt.Sprintf("%s/%s/address/uk/%s?format=json&lines=2", a.Url, a.Key, q)
return api.Get(u, rsp)
}
func (a *Address) LookupPostcode(ctx context.Context, req *pb.LookupPostcodeRequest, rsp *pb.LookupPostcodeResponse) error {
if len(req.Postcode) == 0 {
return errors.BadRequest("address.lookup-postcode", "missing postcode")
}
// check the store to see if we have it already
postcode := strings.ToLower(req.Postcode)
postcode = strings.ReplaceAll(postcode, " ", "")
// check the store
rec, err := store.Read(postcode)
if err == nil && len(rec) > 0 {
for _, r := range rec {
var records []*pb.Record
r.Decode(&records)
rsp.Addresses = records
}
return nil
}
var resp []interface{}
// lookup the address api for the given postcode
if err := a.lookupPostcode(req.Postcode, &resp); err != nil {
logger.Errorf("Failed to lookup postcode %v: %v", req.Postcode, err)
return errors.InternalServerError("address.lookup-postcode", "failed to lookup postcode")
}
for _, res := range resp {
addr := res.(map[string]interface{})
rsp.Addresses = append(rsp.Addresses, &pb.Record{
LineOne: field("addressline1", addr),
LineTwo: field("addressline2", addr),
Summary: field("summaryline", addr),
Organisation: field("organisation", addr),
BuildingName: field("buildingname", addr),
Premise: field("premise", addr),
Street: field("street", addr),
Locality: field("dependentlocality", addr),
Town: field("posttown", addr),
County: field("county", addr),
Postcode: field("postcode", addr),
})
}
// cache the record if we haven't done so already
store.Write(store.NewRecord(postcode, rsp.Addresses))
return nil
}

45
address/main.go Normal file
View File

@@ -0,0 +1,45 @@
package main
import (
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/config"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/address/handler"
pb "github.com/micro/services/address/proto"
)
func main() {
// Create service
srv := service.New(
service.Name("address"),
service.Version("latest"),
)
v, err := config.Get("address.api")
if err != nil {
logger.Fatalf("address.api config not found: %v", err)
}
api := v.String("")
if len(api) == 0 {
logger.Fatal("address.api config not found")
}
v, err = config.Get("address.key")
if err != nil {
logger.Fatalf("address.key config not found: %v", err)
}
key := v.String("")
if len(key) == 0 {
logger.Fatal("address.key config not found")
}
// Register handler
pb.RegisterAddressHandler(srv.Server(), &handler.Address{
Url: api,
Key: key,
})
// Run service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
}

1
address/micro.mu Normal file
View File

@@ -0,0 +1 @@
service address

390
address/proto/address.pb.go Normal file
View File

@@ -0,0 +1,390 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.6
// source: proto/address.proto
package address
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)
)
type Record struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// line one of address
LineOne string `protobuf:"bytes,1,opt,name=line_one,json=lineOne,proto3" json:"line_one,omitempty"`
// line two of address
LineTwo string `protobuf:"bytes,2,opt,name=line_two,json=lineTwo,proto3" json:"line_two,omitempty"`
// the complete address
Summary string `protobuf:"bytes,3,opt,name=summary,proto3" json:"summary,omitempty"`
// organisation if present
Organisation string `protobuf:"bytes,4,opt,name=organisation,proto3" json:"organisation,omitempty"`
// build name
BuildingName string `protobuf:"bytes,5,opt,name=building_name,json=buildingName,proto3" json:"building_name,omitempty"`
// the premise
Premise string `protobuf:"bytes,6,opt,name=premise,proto3" json:"premise,omitempty"`
// street name
Street string `protobuf:"bytes,7,opt,name=street,proto3" json:"street,omitempty"`
// dependent locality
Locality string `protobuf:"bytes,8,opt,name=locality,proto3" json:"locality,omitempty"`
// post town
Town string `protobuf:"bytes,9,opt,name=town,proto3" json:"town,omitempty"`
// the county
County string `protobuf:"bytes,10,opt,name=county,proto3" json:"county,omitempty"`
// the postcode
Postcode string `protobuf:"bytes,11,opt,name=postcode,proto3" json:"postcode,omitempty"`
}
func (x *Record) Reset() {
*x = Record{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_address_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Record) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Record) ProtoMessage() {}
func (x *Record) ProtoReflect() protoreflect.Message {
mi := &file_proto_address_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 Record.ProtoReflect.Descriptor instead.
func (*Record) Descriptor() ([]byte, []int) {
return file_proto_address_proto_rawDescGZIP(), []int{0}
}
func (x *Record) GetLineOne() string {
if x != nil {
return x.LineOne
}
return ""
}
func (x *Record) GetLineTwo() string {
if x != nil {
return x.LineTwo
}
return ""
}
func (x *Record) GetSummary() string {
if x != nil {
return x.Summary
}
return ""
}
func (x *Record) GetOrganisation() string {
if x != nil {
return x.Organisation
}
return ""
}
func (x *Record) GetBuildingName() string {
if x != nil {
return x.BuildingName
}
return ""
}
func (x *Record) GetPremise() string {
if x != nil {
return x.Premise
}
return ""
}
func (x *Record) GetStreet() string {
if x != nil {
return x.Street
}
return ""
}
func (x *Record) GetLocality() string {
if x != nil {
return x.Locality
}
return ""
}
func (x *Record) GetTown() string {
if x != nil {
return x.Town
}
return ""
}
func (x *Record) GetCounty() string {
if x != nil {
return x.County
}
return ""
}
func (x *Record) GetPostcode() string {
if x != nil {
return x.Postcode
}
return ""
}
// Lookup a list of UK addresses by postcode
type LookupPostcodeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// UK postcode e.g SW1A 2AA
Postcode string `protobuf:"bytes,1,opt,name=postcode,proto3" json:"postcode,omitempty"`
}
func (x *LookupPostcodeRequest) Reset() {
*x = LookupPostcodeRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_address_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LookupPostcodeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LookupPostcodeRequest) ProtoMessage() {}
func (x *LookupPostcodeRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_address_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 LookupPostcodeRequest.ProtoReflect.Descriptor instead.
func (*LookupPostcodeRequest) Descriptor() ([]byte, []int) {
return file_proto_address_proto_rawDescGZIP(), []int{1}
}
func (x *LookupPostcodeRequest) GetPostcode() string {
if x != nil {
return x.Postcode
}
return ""
}
type LookupPostcodeResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Addresses []*Record `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"`
}
func (x *LookupPostcodeResponse) Reset() {
*x = LookupPostcodeResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_address_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LookupPostcodeResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LookupPostcodeResponse) ProtoMessage() {}
func (x *LookupPostcodeResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_address_proto_msgTypes[2]
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 LookupPostcodeResponse.ProtoReflect.Descriptor instead.
func (*LookupPostcodeResponse) Descriptor() ([]byte, []int) {
return file_proto_address_proto_rawDescGZIP(), []int{2}
}
func (x *LookupPostcodeResponse) GetAddresses() []*Record {
if x != nil {
return x.Addresses
}
return nil
}
var File_proto_address_proto protoreflect.FileDescriptor
var file_proto_address_proto_rawDesc = []byte{
0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0xb7,
0x02, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6e,
0x65, 0x5f, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x6e,
0x65, 0x4f, 0x6e, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x77, 0x6f,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x6e, 0x65, 0x54, 0x77, 0x6f, 0x12,
0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x22, 0x0a, 0x0c, 0x6f, 0x72, 0x67,
0x61, 0x6e, 0x69, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0c, 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a,
0x0d, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x69, 0x6e, 0x67, 0x4e, 0x61,
0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x73, 0x65, 0x18, 0x06, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x72, 0x65, 0x6d, 0x69, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x73, 0x74, 0x72, 0x65, 0x65, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74,
0x72, 0x65, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x74, 0x79,
0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x74, 0x79,
0x12, 0x12, 0x0a, 0x04, 0x74, 0x6f, 0x77, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x74, 0x6f, 0x77, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x79, 0x18, 0x0a,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x79, 0x12, 0x1a, 0x0a, 0x08,
0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x33, 0x0a, 0x15, 0x4c, 0x6f, 0x6f, 0x6b,
0x75, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x47, 0x0a,
0x16, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65,
0x73, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x64, 0x64,
0x72, 0x65, 0x73, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x09, 0x61, 0x64, 0x64,
0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x32, 0x5e, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73,
0x73, 0x12, 0x53, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x63,
0x6f, 0x64, 0x65, 0x12, 0x1e, 0x2e, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x4c, 0x6f,
0x6f, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x4c, 0x6f,
0x6f, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x3b, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (
file_proto_address_proto_rawDescOnce sync.Once
file_proto_address_proto_rawDescData = file_proto_address_proto_rawDesc
)
func file_proto_address_proto_rawDescGZIP() []byte {
file_proto_address_proto_rawDescOnce.Do(func() {
file_proto_address_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_address_proto_rawDescData)
})
return file_proto_address_proto_rawDescData
}
var file_proto_address_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_proto_address_proto_goTypes = []interface{}{
(*Record)(nil), // 0: address.Record
(*LookupPostcodeRequest)(nil), // 1: address.LookupPostcodeRequest
(*LookupPostcodeResponse)(nil), // 2: address.LookupPostcodeResponse
}
var file_proto_address_proto_depIdxs = []int32{
0, // 0: address.LookupPostcodeResponse.addresses:type_name -> address.Record
1, // 1: address.Address.LookupPostcode:input_type -> address.LookupPostcodeRequest
2, // 2: address.Address.LookupPostcode:output_type -> address.LookupPostcodeResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_proto_address_proto_init() }
func file_proto_address_proto_init() {
if File_proto_address_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_address_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Record); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_address_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LookupPostcodeRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_address_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LookupPostcodeResponse); 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_address_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_address_proto_goTypes,
DependencyIndexes: file_proto_address_proto_depIdxs,
MessageInfos: file_proto_address_proto_msgTypes,
}.Build()
File_proto_address_proto = out.File
file_proto_address_proto_rawDesc = nil
file_proto_address_proto_goTypes = nil
file_proto_address_proto_depIdxs = nil
}

View File

@@ -0,0 +1,93 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/address.proto
package address
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 Address service
func NewAddressEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Address service
type AddressService interface {
LookupPostcode(ctx context.Context, in *LookupPostcodeRequest, opts ...client.CallOption) (*LookupPostcodeResponse, error)
}
type addressService struct {
c client.Client
name string
}
func NewAddressService(name string, c client.Client) AddressService {
return &addressService{
c: c,
name: name,
}
}
func (c *addressService) LookupPostcode(ctx context.Context, in *LookupPostcodeRequest, opts ...client.CallOption) (*LookupPostcodeResponse, error) {
req := c.c.NewRequest(c.name, "Address.LookupPostcode", in)
out := new(LookupPostcodeResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Address service
type AddressHandler interface {
LookupPostcode(context.Context, *LookupPostcodeRequest, *LookupPostcodeResponse) error
}
func RegisterAddressHandler(s server.Server, hdlr AddressHandler, opts ...server.HandlerOption) error {
type address interface {
LookupPostcode(ctx context.Context, in *LookupPostcodeRequest, out *LookupPostcodeResponse) error
}
type Address struct {
address
}
h := &addressHandler{hdlr}
return s.Handle(s.NewHandler(&Address{h}, opts...))
}
type addressHandler struct {
AddressHandler
}
func (h *addressHandler) LookupPostcode(ctx context.Context, in *LookupPostcodeRequest, out *LookupPostcodeResponse) error {
return h.AddressHandler.LookupPostcode(ctx, in, out)
}

View File

@@ -0,0 +1,45 @@
syntax = "proto3";
package address;
option go_package = "./proto;address";
service Address {
rpc LookupPostcode(LookupPostcodeRequest) returns (LookupPostcodeResponse) {}
}
message Record {
// line one of address
string line_one = 1;
// line two of address
string line_two = 2;
// the complete address
string summary = 3;
// organisation if present
string organisation = 4;
// build name
string building_name = 5;
// the premise
string premise = 6;
// street name
string street = 7;
// dependent locality
string locality = 8;
// post town
string town = 9;
// the county
string county = 10;
// the postcode
string postcode = 11;
}
// Lookup a list of UK addresses by postcode
message LookupPostcodeRequest {
// UK postcode e.g SW1A 2AA
string postcode = 1;
}
message LookupPostcodeResponse {
repeated Record addresses = 1;
}

8
address/publicapi.json Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "address",
"icon": "🏠",
"category": "logistics",
"pricing": {
"Address.LookupPostcode": 75000
}
}