add timezone api

This commit is contained in:
Asim Aslam
2021-06-21 16:02:16 +01:00
parent ff57a74669
commit 3929d8e5d1
14 changed files with 608 additions and 0 deletions

View File

@@ -0,0 +1,302 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.6
// source: proto/timezone.proto
package timezone
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)
)
// Get the timezone info for a specific location
type InfoRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// location to lookup e.g postcode, city, ip address
Location string `protobuf:"bytes,1,opt,name=location,proto3" json:"location,omitempty"`
}
func (x *InfoRequest) Reset() {
*x = InfoRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_timezone_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InfoRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InfoRequest) ProtoMessage() {}
func (x *InfoRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_timezone_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 InfoRequest.ProtoReflect.Descriptor instead.
func (*InfoRequest) Descriptor() ([]byte, []int) {
return file_proto_timezone_proto_rawDescGZIP(), []int{0}
}
func (x *InfoRequest) GetLocation() string {
if x != nil {
return x.Location
}
return ""
}
type InfoResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// location requested
Location string `protobuf:"bytes,1,opt,name=location,proto3" json:"location,omitempty"`
// region of timezone
Region string `protobuf:"bytes,2,opt,name=region,proto3" json:"region,omitempty"`
// country of the timezone
Country string `protobuf:"bytes,3,opt,name=country,proto3" json:"country,omitempty"`
// e.g 51.42
Latitude float64 `protobuf:"fixed64,4,opt,name=latitude,proto3" json:"latitude,omitempty"`
// e.g -0.37
Longitude float64 `protobuf:"fixed64,5,opt,name=longitude,proto3" json:"longitude,omitempty"`
// the timezone e.g Europe/London
Timezone string `protobuf:"bytes,6,opt,name=timezone,proto3" json:"timezone,omitempty"`
// the abbreviated code
Abbreviation string `protobuf:"bytes,7,opt,name=abbreviation,proto3" json:"abbreviation,omitempty"`
// the local time
LocalTime string `protobuf:"bytes,8,opt,name=local_time,json=localTime,proto3" json:"local_time,omitempty"`
// is daylight savings
DaylightSavings bool `protobuf:"varint,9,opt,name=daylight_savings,json=daylightSavings,proto3" json:"daylight_savings,omitempty"`
}
func (x *InfoResponse) Reset() {
*x = InfoResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_timezone_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InfoResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InfoResponse) ProtoMessage() {}
func (x *InfoResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_timezone_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 InfoResponse.ProtoReflect.Descriptor instead.
func (*InfoResponse) Descriptor() ([]byte, []int) {
return file_proto_timezone_proto_rawDescGZIP(), []int{1}
}
func (x *InfoResponse) GetLocation() string {
if x != nil {
return x.Location
}
return ""
}
func (x *InfoResponse) GetRegion() string {
if x != nil {
return x.Region
}
return ""
}
func (x *InfoResponse) GetCountry() string {
if x != nil {
return x.Country
}
return ""
}
func (x *InfoResponse) GetLatitude() float64 {
if x != nil {
return x.Latitude
}
return 0
}
func (x *InfoResponse) GetLongitude() float64 {
if x != nil {
return x.Longitude
}
return 0
}
func (x *InfoResponse) GetTimezone() string {
if x != nil {
return x.Timezone
}
return ""
}
func (x *InfoResponse) GetAbbreviation() string {
if x != nil {
return x.Abbreviation
}
return ""
}
func (x *InfoResponse) GetLocalTime() string {
if x != nil {
return x.LocalTime
}
return ""
}
func (x *InfoResponse) GetDaylightSavings() bool {
if x != nil {
return x.DaylightSavings
}
return false
}
var File_proto_timezone_proto protoreflect.FileDescriptor
var file_proto_timezone_proto_rawDesc = []byte{
0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65,
0x22, 0x29, 0x0a, 0x0b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa0, 0x02, 0x0a, 0x0c,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08,
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x67, 0x69,
0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e,
0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61,
0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x6c, 0x61,
0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74,
0x75, 0x64, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69,
0x74, 0x75, 0x64, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65,
0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65,
0x12, 0x22, 0x0a, 0x0c, 0x61, 0x62, 0x62, 0x72, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x61, 0x62, 0x62, 0x72, 0x65, 0x76, 0x69, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x74, 0x69,
0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x54,
0x69, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x64, 0x61, 0x79, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x5f,
0x73, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x64,
0x61, 0x79, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x53, 0x61, 0x76, 0x69, 0x6e, 0x67, 0x73, 0x32, 0x43,
0x0a, 0x08, 0x54, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x49, 0x6e,
0x66, 0x6f, 0x12, 0x15, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x2e, 0x49, 0x6e,
0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x74, 0x69, 0x6d, 0x65,
0x7a, 0x6f, 0x6e, 0x65, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x42, 0x12, 0x5a, 0x10, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x74,
0x69, 0x6d, 0x65, 0x7a, 0x6f, 0x6e, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_proto_timezone_proto_rawDescOnce sync.Once
file_proto_timezone_proto_rawDescData = file_proto_timezone_proto_rawDesc
)
func file_proto_timezone_proto_rawDescGZIP() []byte {
file_proto_timezone_proto_rawDescOnce.Do(func() {
file_proto_timezone_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_timezone_proto_rawDescData)
})
return file_proto_timezone_proto_rawDescData
}
var file_proto_timezone_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_proto_timezone_proto_goTypes = []interface{}{
(*InfoRequest)(nil), // 0: timezone.InfoRequest
(*InfoResponse)(nil), // 1: timezone.InfoResponse
}
var file_proto_timezone_proto_depIdxs = []int32{
0, // 0: timezone.Timezone.Info:input_type -> timezone.InfoRequest
1, // 1: timezone.Timezone.Info:output_type -> timezone.InfoResponse
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_timezone_proto_init() }
func file_proto_timezone_proto_init() {
if File_proto_timezone_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_timezone_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InfoRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_timezone_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InfoResponse); 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_timezone_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_timezone_proto_goTypes,
DependencyIndexes: file_proto_timezone_proto_depIdxs,
MessageInfos: file_proto_timezone_proto_msgTypes,
}.Build()
File_proto_timezone_proto = out.File
file_proto_timezone_proto_rawDesc = nil
file_proto_timezone_proto_goTypes = nil
file_proto_timezone_proto_depIdxs = nil
}

View File

@@ -0,0 +1,93 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/timezone.proto
package timezone
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 Timezone service
func NewTimezoneEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Timezone service
type TimezoneService interface {
Info(ctx context.Context, in *InfoRequest, opts ...client.CallOption) (*InfoResponse, error)
}
type timezoneService struct {
c client.Client
name string
}
func NewTimezoneService(name string, c client.Client) TimezoneService {
return &timezoneService{
c: c,
name: name,
}
}
func (c *timezoneService) Info(ctx context.Context, in *InfoRequest, opts ...client.CallOption) (*InfoResponse, error) {
req := c.c.NewRequest(c.name, "Timezone.Info", in)
out := new(InfoResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Timezone service
type TimezoneHandler interface {
Info(context.Context, *InfoRequest, *InfoResponse) error
}
func RegisterTimezoneHandler(s server.Server, hdlr TimezoneHandler, opts ...server.HandlerOption) error {
type timezone interface {
Info(ctx context.Context, in *InfoRequest, out *InfoResponse) error
}
type Timezone struct {
timezone
}
h := &timezoneHandler{hdlr}
return s.Handle(s.NewHandler(&Timezone{h}, opts...))
}
type timezoneHandler struct {
TimezoneHandler
}
func (h *timezoneHandler) Info(ctx context.Context, in *InfoRequest, out *InfoResponse) error {
return h.TimezoneHandler.Info(ctx, in, out)
}

View File

@@ -0,0 +1,37 @@
syntax = "proto3";
package timezone;
option go_package = "./proto;timezone";
service Timezone {
rpc Info(InfoRequest) returns (InfoResponse) {}
}
// Get the timezone info for a specific location
message InfoRequest {
// location to lookup e.g postcode, city, ip address
string location = 1;
}
message InfoResponse {
// location requested
string location = 1;
// region of timezone
string region = 2;
// country of the timezone
string country = 3;
// e.g 51.42
double latitude = 4;
// e.g -0.37
double longitude = 5;
// the timezone e.g Europe/London
string timezone = 6;
// the abbreviated code
string abbreviation = 7;
// the local time
string local_time = 8;
// is daylight savings
bool daylight_savings = 9;
}