mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 06:25:07 +00:00
add timezone api
This commit is contained in:
1
go.mod
1
go.mod
@@ -41,6 +41,7 @@ require (
|
|||||||
github.com/stoewer/go-strcase v1.2.0
|
github.com/stoewer/go-strcase v1.2.0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
|
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
|
||||||
|
github.com/tkuchiki/go-timezone v0.2.2
|
||||||
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
|
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
|
||||||
github.com/ttacon/libphonenumber v1.2.1 // indirect
|
github.com/ttacon/libphonenumber v1.2.1 // indirect
|
||||||
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
|
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -510,6 +510,8 @@ github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4U
|
|||||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
||||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||||
github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY=
|
github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY=
|
||||||
|
github.com/tkuchiki/go-timezone v0.2.2 h1:MdHR65KwgVTwWFQrota4SKzc4L5EfuH5SdZZGtk/P2Q=
|
||||||
|
github.com/tkuchiki/go-timezone v0.2.2/go.mod h1:oFweWxYl35C/s7HMVZXiA19Jr9Y0qJHMaG/J2TES4LY=
|
||||||
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
|
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
|
||||||
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 h1:5u+EJUQiosu3JFX0XS0qTf5FznsMOzTjGqavBGuCbo0=
|
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 h1:5u+EJUQiosu3JFX0XS0qTf5FznsMOzTjGqavBGuCbo0=
|
||||||
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2/go.mod h1:4kyMkleCiLkgY6z8gK5BkI01ChBtxR0ro3I1ZDcGM3w=
|
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2/go.mod h1:4kyMkleCiLkgY6z8gK5BkI01ChBtxR0ro3I1ZDcGM3w=
|
||||||
|
|||||||
2
timezone/.gitignore
vendored
Normal file
2
timezone/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
timezone
|
||||||
3
timezone/Dockerfile
Normal file
3
timezone/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM alpine
|
||||||
|
ADD timezone /timezone
|
||||||
|
ENTRYPOINT [ "/timezone" ]
|
||||||
28
timezone/Makefile
Normal file
28
timezone/Makefile
Normal 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/timezone.proto
|
||||||
|
|
||||||
|
.PHONY: proto
|
||||||
|
proto:
|
||||||
|
protoc --proto_path=. --micro_out=. --go_out=:. proto/timezone.proto
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
go build -o timezone *.go
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
go test -v ./... -cover
|
||||||
|
|
||||||
|
.PHONY: docker
|
||||||
|
docker:
|
||||||
|
docker build . -t timezone:latest
|
||||||
7
timezone/README.md
Normal file
7
timezone/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
Time, date and timezone info
|
||||||
|
|
||||||
|
# Timezone Service
|
||||||
|
|
||||||
|
Get the time, date and timezone info for any given location in the world.
|
||||||
|
|
||||||
|
Powered by [Weather API](https://weatherapi.com)
|
||||||
3
timezone/generate.go
Normal file
3
timezone/generate.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate make proto
|
||||||
97
timezone/handler/timezone.go
Normal file
97
timezone/handler/timezone.go
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/micro/micro/v3/service/config"
|
||||||
|
"github.com/micro/micro/v3/service/errors"
|
||||||
|
"github.com/micro/micro/v3/service/logger"
|
||||||
|
pb "github.com/micro/services/timezone/proto"
|
||||||
|
"github.com/tkuchiki/go-timezone"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Timezone struct {
|
||||||
|
Api string
|
||||||
|
Key string
|
||||||
|
TZ *timezone.Timezone
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *Timezone {
|
||||||
|
// TODO: look for "weather.provider" to determine the handler
|
||||||
|
v, err := config.Get("weatherapi.api")
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalf("weatherapi.api config not found: %v", err)
|
||||||
|
}
|
||||||
|
api := v.String("")
|
||||||
|
if len(api) == 0 {
|
||||||
|
logger.Fatal("weatherapi.api config not found")
|
||||||
|
}
|
||||||
|
v, err = config.Get("weatherapi.key")
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalf("weatherapi.key config not found: %v", err)
|
||||||
|
}
|
||||||
|
key := v.String("")
|
||||||
|
if len(key) == 0 {
|
||||||
|
logger.Fatal("weatherapi.key config not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Timezone{
|
||||||
|
Api: api,
|
||||||
|
Key: key,
|
||||||
|
TZ: timezone.New(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Timezone) Info(ctx context.Context, req *pb.InfoRequest, rsp *pb.InfoResponse) error {
|
||||||
|
if len(req.Location) == 0 {
|
||||||
|
return errors.BadRequest("timezone.info", "invalid location")
|
||||||
|
}
|
||||||
|
|
||||||
|
vals := url.Values{}
|
||||||
|
vals.Set("key", t.Key)
|
||||||
|
vals.Set("q", req.Location)
|
||||||
|
|
||||||
|
resp, err := http.Get(t.Api + "timezone.json?" + vals.Encode())
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Failed to get timezone info: %v\n", err)
|
||||||
|
return errors.InternalServerError("weather.current", "failed to get timezone info")
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
logger.Errorf("Failed to get timezone info (non 200): %d %v\n", resp.StatusCode, string(b))
|
||||||
|
return errors.InternalServerError("weather.current", "failed to get timezone info")
|
||||||
|
}
|
||||||
|
|
||||||
|
var respBody map[string]interface{}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(b, &respBody); err != nil {
|
||||||
|
logger.Errorf("Failed to unmarshal current: %v\n", err)
|
||||||
|
return errors.InternalServerError("weather.current", "failed to get current")
|
||||||
|
}
|
||||||
|
|
||||||
|
location := respBody["location"].(map[string]interface{})
|
||||||
|
|
||||||
|
rsp.Location = location["name"].(string)
|
||||||
|
rsp.Region = location["region"].(string)
|
||||||
|
rsp.Country = location["country"].(string)
|
||||||
|
rsp.Latitude = location["lat"].(float64)
|
||||||
|
rsp.Longitude = location["lon"].(float64)
|
||||||
|
rsp.Timezone = location["tz_id"].(string)
|
||||||
|
rsp.LocalTime = location["localtime"].(string)
|
||||||
|
|
||||||
|
loc, _ := time.LoadLocation(rsp.Timezone)
|
||||||
|
ti := time.Now().In(loc)
|
||||||
|
isDST := t.TZ.IsDST(ti)
|
||||||
|
rsp.Abbreviation, _ = t.TZ.GetTimezoneAbbreviation(rsp.Timezone, isDST)
|
||||||
|
rsp.DaylightSavings = isDST
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
24
timezone/main.go
Normal file
24
timezone/main.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/micro/micro/v3/service"
|
||||||
|
"github.com/micro/micro/v3/service/logger"
|
||||||
|
"github.com/micro/services/timezone/handler"
|
||||||
|
pb "github.com/micro/services/timezone/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Create service
|
||||||
|
srv := service.New(
|
||||||
|
service.Name("timezone"),
|
||||||
|
service.Version("latest"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register handler
|
||||||
|
pb.RegisterTimezoneHandler(srv.Server(), handler.New())
|
||||||
|
|
||||||
|
// Run service
|
||||||
|
if err := srv.Run(); err != nil {
|
||||||
|
logger.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
timezone/micro.mu
Normal file
1
timezone/micro.mu
Normal file
@@ -0,0 +1 @@
|
|||||||
|
service timezone
|
||||||
302
timezone/proto/timezone.pb.go
Normal file
302
timezone/proto/timezone.pb.go
Normal 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
|
||||||
|
}
|
||||||
93
timezone/proto/timezone.pb.micro.go
Normal file
93
timezone/proto/timezone.pb.micro.go
Normal 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)
|
||||||
|
}
|
||||||
37
timezone/proto/timezone.proto
Normal file
37
timezone/proto/timezone.proto
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
8
timezone/publicapi.json
Normal file
8
timezone/publicapi.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "timezone",
|
||||||
|
"icon": "🌐",
|
||||||
|
"category": "time",
|
||||||
|
"pricing": {
|
||||||
|
"Timezone.Info": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user