Skip to content

Commit

Permalink
add a service client
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Jul 20, 2022
1 parent fda311d commit 3c78b54
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 108 deletions.
4 changes: 2 additions & 2 deletions analytics/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/micro/services/analytics/handler"
pb "github.com/micro/services/analytics/proto"
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/analytics/handler"
pb "github.com/micro/services/analytics/proto"
)

func main() {
Expand Down
12 changes: 6 additions & 6 deletions carbon/domain/domain.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package domain

type Project struct {
Name string `json:"name"`
Name string `json:"name"`
Percentage float64 `json:"splitPercentage"`
Tonnes float64 `json:"splitAmountTonnes"`
Tonnes float64 `json:"splitAmountTonnes"`
}

type OffsetRequest struct {
Expand All @@ -12,10 +12,10 @@ type OffsetRequest struct {
}

type OffsetResponse struct {
Number int32 `json:"number"`
Units string `json:"units"`
Tonnes float64 `json:"numberInTonnes"`
Number int32 `json:"number"`
Units string `json:"units"`
Tonnes float64 `json:"numberInTonnes"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Currency string `json:"currency"`
Projects []Project `json:"projectDetails"`
}
4 changes: 2 additions & 2 deletions carbon/handler/carbon.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (c *Carbon) Offset(ctx context.Context, req *pb.OffsetRequest, rsp *pb.Offs
//rsp.Currency = resp.Currency
for _, p := range resp.Projects {
rsp.Projects = append(rsp.Projects, &pb.Project{
Name: p.Name,
Name: p.Name,
Percentage: p.Percentage,
Tonnes: p.Tonnes,
Tonnes: p.Tonnes,
})
}

Expand Down
6 changes: 3 additions & 3 deletions chat/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *Chat) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.Create
Id: roomId,
Name: req.Name,
Description: req.Description,
UserIds: req.UserIds,
UserIds: req.UserIds,
Private: req.Private,
CreatedAt: time.Now().Format(time.RFC3339Nano),
}
Expand Down Expand Up @@ -295,8 +295,8 @@ func (c *Chat) Send(ctx context.Context, req *pb.SendRequest, rsp *pb.SendRespon
msg := &pb.Message{
Id: uuid.New().String(),
Client: req.Client,
RoomId: req.RoomId,
UserId: req.UserId,
RoomId: req.RoomId,
UserId: req.UserId,
Subject: req.Subject,
Text: req.Text,
SentAt: time.Now().Format(time.RFC3339Nano),
Expand Down
5 changes: 2 additions & 3 deletions crypto/handler/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,13 @@ func (c *Crypto) Price(ctx context.Context, req *pb.PriceRequest, rsp *pb.PriceR
}

// check the cache
cached, ok := c.Cache.Get("prices:"+req.Symbol)
cached, ok := c.Cache.Get("prices:" + req.Symbol)
if ok {
rsp.Symbol = req.Symbol
rsp.Price, _ = cached.(float64)
return nil
}


uri := fmt.Sprintf("%slast/crypto/%s?apikey=%s", c.Api, req.Symbol, c.Key)

resp, err := http.Get(uri)
Expand Down Expand Up @@ -254,7 +253,7 @@ func (c *Crypto) Price(ctx context.Context, req *pb.PriceRequest, rsp *pb.PriceR
rsp.Price = respBody["price"].(float64)

// set the cache
c.Cache.Set("prices:"+req.Symbol, rsp.Price, time.Minute * 5)
c.Cache.Set("prices:"+req.Symbol, rsp.Price, time.Minute*5)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion email/handler/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/mail"
"net/http"
"net/mail"
"regexp"

"github.com/micro/micro/v3/service"
Expand Down
1 change: 0 additions & 1 deletion emoji/handler/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ func (e *Emoji) Print(ctx context.Context, req *pb.PrintRequest, rsp *pb.PrintRe
rsp.Text = emoji.Parse(req.Text)
return nil
}

2 changes: 1 addition & 1 deletion event/handler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *Event) Read(ctx context.Context, req *pb.ReadRequest, rsp *pb.ReadRespo
}

if req.Offset > 0 {
opts = append(opts, events.ReadOffset( uint(req.Offset)))
opts = append(opts, events.ReadOffset(uint(req.Offset)))
}

log.Infof("Tenant %v reading %v limit: %v offset: %v\n", id, req.Topic, req.Limit, req.Offset)
Expand Down
1 change: 1 addition & 0 deletions github/generate.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package main

//go:generate make proto
110 changes: 55 additions & 55 deletions news/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@ package handler

var (
Locales = []string{
"ar",
"am",
"au",
"at",
"by",
"be",
"bo",
"br",
"bg",
"ca",
"cl",
"cn",
"co",
"hr",
"cz",
"ec",
"eg",
"fr",
"de",
"gr",
"hn",
"hk",
"in",
"id",
"ir",
"ie",
"il",
"it",
"jp",
"kr",
"mx",
"nl",
"nz",
"ni",
"pk",
"pa",
"pe",
"pl",
"pt",
"qa",
"ro",
"ru",
"sa",
"za",
"es",
"ch",
"sy",
"tw",
"th",
"tr",
"ua",
"gb",
"us",
"uy",
"ve",
"ar",
"am",
"au",
"at",
"by",
"be",
"bo",
"br",
"bg",
"ca",
"cl",
"cn",
"co",
"hr",
"cz",
"ec",
"eg",
"fr",
"de",
"gr",
"hn",
"hk",
"in",
"id",
"ir",
"ie",
"il",
"it",
"jp",
"kr",
"mx",
"nl",
"nz",
"ni",
"pk",
"pa",
"pe",
"pl",
"pt",
"qa",
"ro",
"ru",
"sa",
"za",
"es",
"ch",
"sy",
"tw",
"th",
"tr",
"ua",
"gb",
"us",
"uy",
"ve",
}
)
1 change: 1 addition & 0 deletions password/generate.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package main

//go:generate make proto
2 changes: 1 addition & 1 deletion pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (c *cache) Increment(key string, value int64) (int64, error) {

counter += value

if err := c.Set(key, fmt.Sprintf("%v",counter), time.Time{}); err != nil {
if err := c.Set(key, fmt.Sprintf("%v", counter), time.Time{}); err != nil {
return counter, err
}
return counter, nil
Expand Down
1 change: 1 addition & 0 deletions place/generate.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
package main

//go:generate make proto
62 changes: 31 additions & 31 deletions place/handler/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package handler

import (
"context"
"strings"
"strconv"
"strings"

"googlemaps.github.io/maps"
"github.com/micro/micro/v3/service/config"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"googlemaps.github.io/maps"

pb "github.com/micro/services/place/proto"
)
Expand All @@ -24,19 +24,19 @@ type Google struct {
}

func NewGoogle() *Google {
// Setup google maps
c, err := config.Get("google.apikey")
if err != nil {
logger.Fatalf("Error loading config: %v", err)
}
apiKey := c.String("")
if len(apiKey) == 0 {
logger.Fatalf("Missing required config: google.apikey")
}
m, err := maps.NewClient(maps.WithAPIKey(apiKey))
if err != nil {
logger.Fatalf("Error configuring google maps client: %v", err)
}
// Setup google maps
c, err := config.Get("google.apikey")
if err != nil {
logger.Fatalf("Error loading config: %v", err)
}
apiKey := c.String("")
if len(apiKey) == 0 {
logger.Fatalf("Missing required config: google.apikey")
}
m, err := maps.NewClient(maps.WithAPIKey(apiKey))
if err != nil {
logger.Fatalf("Error configuring google maps client: %v", err)
}

return &Google{
Maps: m,
Expand Down Expand Up @@ -99,15 +99,15 @@ func (g *Google) Nearby(ctx context.Context, req *pb.NearbyRequest, rsp *pb.Near
}

rsp.Results = append(rsp.Results, &pb.Result{
Address: res.FormattedAddress,
Location: res.Geometry.Location.String(),
Name: res.Name,
IconUrl: res.Icon,
Rating: float64(res.Rating),
OpenNow: openNow,
Address: res.FormattedAddress,
Location: res.Geometry.Location.String(),
Name: res.Name,
IconUrl: res.Icon,
Rating: float64(res.Rating),
OpenNow: openNow,
OpeningHours: hours,
Vicinity: res.Vicinity,
Types: res.Types,
Vicinity: res.Vicinity,
Types: res.Types,
})
}

Expand Down Expand Up @@ -167,15 +167,15 @@ func (g *Google) Search(ctx context.Context, req *pb.SearchRequest, rsp *pb.Sear
}
}
rsp.Results = append(rsp.Results, &pb.Result{
Address: res.FormattedAddress,
Location: res.Geometry.Location.String(),
Name: res.Name,
IconUrl: res.Icon,
Rating: float64(res.Rating),
OpenNow: openNow,
Address: res.FormattedAddress,
Location: res.Geometry.Location.String(),
Name: res.Name,
IconUrl: res.Icon,
Rating: float64(res.Rating),
OpenNow: openNow,
OpeningHours: hours,
Vicinity: res.Vicinity,
Types: res.Types,
Vicinity: res.Vicinity,
Types: res.Types,
})
}

Expand Down
2 changes: 1 addition & 1 deletion place/handler/place.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package handler

type Place struct{
type Place struct {
*Google
}

Expand Down
2 changes: 1 addition & 1 deletion price/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strings"
"time"

"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/store"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/services/pkg/api"
pb "github.com/micro/services/price/proto"
)
Expand Down

0 comments on commit 3c78b54

Please sign in to comment.