-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (41 loc) · 1.38 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
package s3packs
import (
"errors"
"fmt"
"github.com/orme292/s3packer/conf"
"github.com/orme292/s3packer/s3packs/provider"
s3aws "github.com/orme292/s3packer/s3packs/providers/aws"
s3linode "github.com/orme292/s3packer/s3packs/providers/linode"
s3oracle "github.com/orme292/s3packer/s3packs/providers/oracle"
"github.com/orme292/s3packer/tuipack"
)
func Init(app *conf.AppConfig) (*provider.Stats, error) {
operFn, objFn, err := getProviderFunctions(app.Provider.Is)
if err != nil {
return nil, errors.New("unable to find the correct provider")
}
handler, err := provider.NewHandler(app, operFn, objFn)
if err != nil {
return &provider.Stats{}, err
}
err = handler.Init()
if err != nil {
return &provider.Stats{}, err
}
app.Tui.SendOutput(tuipack.NewLogMsg("Finished.", tuipack.ScrnLfCheck,
tuipack.INFO, "Finished"))
app.Tui.ToScreenHeader("s3packer is finished!")
return handler.Stats, nil
}
func getProviderFunctions(name conf.ProviderName) (provider.OperGenFunc, provider.ObjectGenFunc, error) {
switch name {
case conf.ProviderNameAWS:
return s3aws.NewAwsOperator, s3aws.NewAwsObject, nil
case conf.ProviderNameLinode:
return s3linode.NewLinodeOperator, s3linode.NewLinodeObject, nil
case conf.ProviderNameOCI:
return s3oracle.NewOracleOperator, s3oracle.NewOracleObject, nil
default:
return nil, nil, fmt.Errorf("unable to determine the provider")
}
}