-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroservice-clients.go
More file actions
51 lines (44 loc) · 1.18 KB
/
Copy pathmicroservice-clients.go
File metadata and controls
51 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package app
// simple clients for calling the (local) microservices
// the implementation is never shown in the example
import (
"github.com/go-resty/resty/v2"
"strconv"
)
type InventoryService struct {
Hostname string // just for show, this is never used
}
func (client InventoryService) GetQuantityAvailable(productId string) (int, error) {
params := map[string]string{
"productId": productId,
}
baseUrl := "http://localhost:8009/get-quantity-available"
resty := resty.New()
resp, err := resty.R().SetQueryParams(params).Get(baseUrl)
if err != nil {
return -1, err
}
bodyAsString := resp.String()
retval, err := strconv.Atoi(bodyAsString)
if err != nil {
return -1, err
}
return retval, nil
}
type NotificationService struct {
Hostname string // just for show, this is never used
}
func (client NotificationService) SendText(message string, phoneNum string) (string, error) {
params := map[string]string{
"message": message,
"number": phoneNum,
}
baseUrl := "http://localhost:8008/send-text"
resty := resty.New()
resp, err := resty.R().SetQueryParams(params).Get(baseUrl)
if err != nil {
return "", err
}
bodyAsString := resp.String()
return bodyAsString, nil
}