-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
96 lines (71 loc) · 2.3 KB
/
main.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"context"
"os"
"github.com/americanas-go/config"
ilog "github.com/americanas-go/ignite/americanas-go/log.v1"
"github.com/americanas-go/ignite/go-resty/resty.v2"
logplugin "github.com/americanas-go/ignite/go-resty/resty.v2/plugins/contrib/americanas-go/log.v1"
"github.com/americanas-go/log"
r "github.com/go-resty/resty/v2"
)
const (
// config google client
googleConfigPath = "app.resty.googleConfigPath"
googlePluginsConfigPath = googleConfigPath + ".plugins"
googleLogPluginConfigPath = googlePluginsConfigPath + ".log"
// config americanas client
acomConfigPath = "app.resty.acomConfigPath"
acomPluginsConfigPath = acomConfigPath + ".plugins"
acomLogPluginConfigPath = acomPluginsConfigPath + ".log"
)
func init() {
os.Setenv("IGNITE_LOGRUS_CONSOLE_LEVEL", "INFO")
os.Setenv("APP_RESTY_GOOGLE_HOST", "http://www.googleConfigPath.com")
os.Setenv("APP_RESTY_ACOM_HOST", "https://www.americanas.com.br")
os.Setenv("APP_RESTY_ACOM_PLUGINS_LOG_LEVEL", "INFO")
resty.ConfigAdd(acomConfigPath)
logplugin.ConfigAdd(acomLogPluginConfigPath)
resty.ConfigAdd(googleConfigPath)
logplugin.ConfigAdd(googleLogPluginConfigPath)
}
func main() {
config.Load()
ilog.New()
ctx := context.Background()
logger := log.FromContext(ctx)
var err error
// ACOM CALL
var acomLogPlugin *logplugin.Log
acomLogPlugin, err = logplugin.NewLogWithConfigPath(acomLogPluginConfigPath)
if err != nil {
log.Fatal(err)
}
var clientAcom *r.Client
if clientAcom, err = resty.NewClientWithConfigPath(ctx, acomConfigPath, acomLogPlugin.Register); err != nil {
log.Fatal(err)
}
var responseAcom *r.Response
if responseAcom, err = clientAcom.R().Get("/"); err != nil {
log.Fatal(err)
}
if responseAcom != nil {
logger.Infof(responseAcom.String())
}
// GOOGLE CALL
var googleLogPlugin *logplugin.Log
if googleLogPlugin, err = logplugin.NewLogWithConfigPath(googleLogPluginConfigPath); err != nil {
log.Fatal(err)
}
var clientGoogle *r.Client
if clientGoogle, err = resty.NewClientWithConfigPath(ctx, googleConfigPath, googleLogPlugin.Register); err != nil {
log.Fatal(err)
}
var responseGoogle *r.Response
if responseGoogle, err = clientGoogle.R().Get("/"); err != nil {
log.Fatal(err)
}
if responseGoogle != nil {
logger.Infof(responseGoogle.String())
}
}