-
Notifications
You must be signed in to change notification settings - Fork 17
/
init.go
94 lines (89 loc) · 2.13 KB
/
init.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
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2020-present Cloud <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 3 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"log"
"os"
"path/filepath"
"strconv"
"github.com/joho/godotenv"
)
var maxbody int64 = 0
var timeout int64 = 0
var port int64 = 443
var rate int64 = 30
var niconame string = "github.com/txthinking/nico"
var certpath string = ""
var nicoip string = ""
var nicohttp3 string = ""
func init() {
home, err := os.UserHomeDir()
if err != nil {
log.Println(err)
os.Exit(1)
return
}
if err := godotenv.Load(filepath.Join(home, ".nico.env")); err != nil {
if !os.IsNotExist(err) {
log.Println(err)
os.Exit(1)
return
}
}
if os.Getenv("NICO_MAX_BODY") != "" {
maxbody, err = strconv.ParseInt(os.Getenv("NICO_MAX_BODY"), 10, 64)
if err != nil {
log.Println(err)
os.Exit(1)
return
}
}
if os.Getenv("NICO_TIMEOUT") != "" {
timeout, err = strconv.ParseInt(os.Getenv("NICO_TIMEOUT"), 10, 64)
if err != nil {
log.Println(err)
os.Exit(1)
return
}
}
if os.Getenv("NICO_PORT") != "" {
port, err = strconv.ParseInt(os.Getenv("NICO_PORT"), 10, 64)
if err != nil {
log.Println(err)
os.Exit(1)
return
}
}
if os.Getenv("NICO_RATE") != "" {
rate, err = strconv.ParseInt(os.Getenv("NICO_RATE"), 10, 64)
if err != nil {
log.Println(err)
os.Exit(1)
return
}
}
if s := os.Getenv("NICO_NAME"); s != "" {
niconame = s
}
if s := os.Getenv("NICO_IP"); s != "" {
nicoip = s
}
certpath = filepath.Join(home, ".nico")
if s := os.Getenv("NICO_CERT"); s != "" {
certpath = s
}
if s := os.Getenv("NICO_HTTP3"); s != "" {
nicohttp3 = s
}
}