-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
59 lines (55 loc) · 1.58 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
package main
import (
"log"
"os"
"github.com/spf13/viper"
)
func initConfig() {
viper.SetDefault("http.addr", ":8080")
viper.SetDefault("http.url", "http://localhost:8080")
viper.SetDefault("http.mode", "debug")
viper.SetDefault("http.trustedProxies", []string{"127.0.0.0/24"})
viper.SetDefault("tftp.enabled", true)
viper.SetDefault("tftp.writePrefix", "bt-")
viper.SetDefault("tftp.examplesAddr", "localhost")
viper.SetDefault("upload.dataDir", "./data")
viper.SetDefault("upload.locationDatabasePath", "./IP2LOCATION-LITE-DB5.BIN")
viper.SetDefault("upload.recentsSize", 40)
viper.SetDefault("upload.forbiddenNames", []string{
"index.html",
"index.htm",
"robots.txt",
"humans.txt",
"favicon.ico",
"wp-admin.php",
"xmlrpc.php",
".env",
".git",
".config",
"recents.json",
".",
"/",
"./",
"style.css",
})
viper.SetDefault("upload.forbiddenPrefixes", []string{
".well-known", // letsencrypt site verification
".git",
".htaccess",
".htpasswd",
"google", // google website verifification
})
viper.SetEnvPrefix("biedatransfer")
viper.SetConfigName("biedatransfer-config") // name of config file (without extension)
viper.SetConfigType("yaml")
viper.AddConfigPath(".") // optionally look for config in the working directory
viper.AddConfigPath("/etc/biedatransfer")
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
log.Printf("failed to read config file: %v", err)
}
if writeConfig {
log.Print(viper.SafeWriteConfigAs("biedatransfer-config.yaml"))
os.Exit(0)
}
}