-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
83 lines (67 loc) · 1.59 KB
/
config.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
package main
import (
"io/ioutil"
"log"
"os"
apis "astuart.co/goapis"
"astuart.co/nntp"
"gopkg.in/yaml.v2"
)
var geek *apis.Client
var use *nntp.Client
var config = struct {
Geek struct {
APIKey, URL string
}
Usenet struct {
Server, Username, Password string
Port, Connections int
TLS bool
}
Downloads struct {
Dir string
}
Filter []string
}{}
//Usenet well-known ports
const (
InsecureUsenetPort = 119
SecureUsenetPort = 563
)
func connectApis() {
confName := os.ExpandEnv("$HOME/.config/sab/config.yml")
confFile, err := os.Open(confName)
if err != nil {
log.Fatalf("Error opening config confFile:\n\t%v\n", err)
}
confData, err := ioutil.ReadAll(confFile)
if err != nil {
log.Fatalf("Error reading confFile:\n\t%v\n", err)
}
yaml.Unmarshal(confData, &config)
if config.Usenet.Port == 0 {
if config.Usenet.TLS {
config.Usenet.Port = SecureUsenetPort
} else {
config.Usenet.Port = InsecureUsenetPort
}
}
geek = apis.NewClient(config.Geek.URL)
geek.DefaultParams(apis.Query{
"apikey": config.Geek.APIKey,
"limit": "200",
})
if config.Usenet.Server == "" {
log.Fatal("No server configured. Please provide a valid usenet server name.")
}
if config.Usenet.Port == 0 {
log.Fatal("No port configured. Please provide a valid usenet port.")
}
use = nntp.NewClient(config.Usenet.Server, config.Usenet.Port)
use.Tls = config.Usenet.TLS
use.SetMaxConns(config.Usenet.Connections)
err = use.Auth(config.Usenet.Username, config.Usenet.Password)
if err != nil {
log.Fatalf("Error authenticating:\n\t%v\n", err)
}
}