-
Notifications
You must be signed in to change notification settings - Fork 3
/
dependencies.go
67 lines (53 loc) · 2.37 KB
/
dependencies.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
package dependencies
import (
"github.com/RomaBilka/parcel-tracking/logic"
determine_delivery "github.com/RomaBilka/parcel-tracking/pkg/determine-delivery"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/dhl"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/fedex"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/me"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/np"
np_shopping "github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/np-shopping"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/ukrposhta"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/ups"
"github.com/RomaBilka/parcel-tracking/pkg/determine-delivery/carriers/usps"
"go.uber.org/zap"
)
type Deps struct {
Config *Config
ParcelTracker *logic.ParcelsTracker
Logger *zap.Logger
}
func InitDeps() (*Deps, error) {
config, err := initConfig()
if err != nil {
return nil, err
}
detector := determine_delivery.NewDetector()
detector.Registry(np.NewCarrier(np.NewApi(config.NovaPoshta.ApiURL, config.NovaPoshta.ApiKey)))
meApi := me.NewApi(config.MeestExpress.ApiURL, config.MeestExpress.ID, config.MeestExpress.Login, config.MeestExpress.Password)
detector.Registry(me.NewCarrier(meApi))
uspsApi := usps.NewApi(config.USPS.ApiURL, config.USPS.UserID, config.USPS.SourceId)
detector.Registry(usps.NewCarrier(uspsApi))
upsApi := ups.NewApi(config.UPS.ApiURL, config.UPS.UserID, config.UPS.AccessLicenseNumber, config.UPS.Password)
detector.Registry(ups.NewCarrier(upsApi))
fedexApi := fedex.NewApi(config.Fedex.ApiURL, config.Fedex.ApiKey, config.Fedex.GrantType, config.Fedex.ShippingAccount)
detector.Registry(fedex.NewCarrier(fedexApi))
dhlApi := dhl.NewApi(config.DHL.ApiURL, config.DHL.ApiKey)
detector.Registry(dhl.NewCarrier(dhlApi))
npShoppingApi := np_shopping.NewApi(config.NovaPoshtaShopping.ApiURL)
detector.Registry(np_shopping.NewCarrier(npShoppingApi))
ukrPoshtaApi := ukrposhta.NewApi(config.UkrPoshta.ApiURL, config.UkrPoshta.ApiToken)
detector.Registry(ukrposhta.NewCarrier(ukrPoshtaApi))
logger, err := zap.NewProduction()
if err != nil {
return nil, err
}
return &Deps{
Config: config,
ParcelTracker: logic.NewParcelsTracker(detector),
Logger: logger,
}, nil
}
func (d Deps) TearDown() {
_ = d.Logger.Sync()
}