-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (52 loc) · 1.22 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
package main
import (
"context"
"log"
"os"
"github.com/adamgoose/put2aria/cmd"
"github.com/adamgoose/put2aria/put2aria"
"github.com/defval/di"
"github.com/putdotio/go-putio"
"github.com/siku2/arigo"
"github.com/spf13/viper"
"golang.org/x/oauth2"
)
func main() {
if err := put2aria.App.Apply(
di.Provide(func() *putio.Client {
oauthToken := viper.GetString("PUTIO_OAUTH_TOKEN")
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: oauthToken})
oauthClient := oauth2.NewClient(context.TODO(), tokenSource)
return putio.NewClient(oauthClient)
}),
di.Provide(func() (*arigo.Client, error) {
c, err := arigo.Dial(
viper.GetString("ARIA2_RPC_URL"),
viper.GetString("ARIA2_RPC_SECRET"),
)
return &c, err
}),
); err != nil {
log.Fatal(err)
}
cmd.Execute()
}
var secrets = []string{"PUTIO_OAUTH_TOKEN", "ARIA2_RPC_SECRET"}
func init() {
viper.SetEnvPrefix("PUT2ARIA")
viper.AutomaticEnv()
for _, secret := range secrets {
if viper.GetString(secret) != "" {
continue
}
filePath := viper.GetString(secret + "_FILE")
if filePath == "" {
continue
}
value, err := os.ReadFile(filePath)
if err != nil {
log.Fatal(err)
}
viper.Set(secret, string(value))
}
}