1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-05-31 21:59:42 +02:00
Asim Aslam 4ae2528cbe
add m3o services (#2301)
* add m3o services

* update readme
2021-10-11 09:18:28 +01:00

74 lines
1.7 KiB
Go
Executable File

package time
import (
"github.com/m3o/m3o-go/client"
)
func NewTimeService(token string) *TimeService {
return &TimeService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type TimeService struct {
client *client.Client
}
// Get the current time
func (t *TimeService) Now(request *NowRequest) (*NowResponse, error) {
rsp := &NowResponse{}
return rsp, t.client.Call("time", "Now", request, rsp)
}
// Get the timezone info for a specific location
func (t *TimeService) Zone(request *ZoneRequest) (*ZoneResponse, error) {
rsp := &ZoneResponse{}
return rsp, t.client.Call("time", "Zone", request, rsp)
}
type NowRequest struct {
// optional location, otherwise returns UTC
Location string `json:"location"`
}
type NowResponse struct {
// the current time as HH:MM:SS
Localtime string `json:"localtime"`
// the location as Europe/London
Location string `json:"location"`
// timestamp as 2006-01-02T15:04:05.999999999Z07:00
Timestamp string `json:"timestamp"`
// the timezone as BST
Timezone string `json:"timezone"`
// the unix timestamp
Unix int64 `json:"unix,string"`
}
type ZoneRequest struct {
// location to lookup e.g postcode, city, ip address
Location string `json:"location"`
}
type ZoneResponse struct {
// the abbreviated code e.g BST
Abbreviation string `json:"abbreviation"`
// country of the timezone
Country string `json:"country"`
// is daylight savings
Dst bool `json:"dst"`
// e.g 51.42
Latitude float64 `json:"latitude"`
// the local time
Localtime string `json:"localtime"`
// location requested
Location string `json:"location"`
// e.g -0.37
Longitude float64 `json:"longitude"`
// region of timezone
Region string `json:"region"`
// the timezone e.g Europe/London
Timezone string `json:"timezone"`
}