-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
54 lines (40 loc) · 940 Bytes
/
app.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
package main
import (
"log"
"path/filepath"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/storage"
homedir "github.com/mitchellh/go-homedir"
)
// App Global App
type App struct {
config *torrent.Config
client *torrent.Client
}
// NewApp NewApp
func (app *App) initApp() {
config, err := defaultConfig()
if err != nil {
log.Fatalln("Failed to initialize defaultConfig")
}
app.config = config
client, err := torrent.NewClient(config)
if err != nil {
log.Fatalln("Failed to initialize Client")
}
app.client = client
}
func defaultConfig() (cfg *torrent.Config, err error) {
hd, err := homedir.Dir()
if err != nil {
log.Fatal(err.Error())
}
baseDir := filepath.Join(hd, ".vin")
defaultStorage := storage.NewFileByInfoHash(baseDir)
cfg = &torrent.Config{
ListenAddr: "localhost:9000",
PeerID: "VinTorrent1234567890",
DefaultStorage: defaultStorage,
}
return cfg, nil
}