-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.go
43 lines (36 loc) · 971 Bytes
/
addon.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
package config
import (
"github.com/spf13/viper"
)
const (
addonEnabledKey = "gtavd.addons.enabled"
addonBlacklistKey = "gtavd.addons.blacklist"
defaultAddonPath = "\\update\\x64\\dlcpacks"
defaultAddonModPath = "\\mods\\update\\x64\\dlcpacks"
)
type Addon struct {
IsEnabled bool
Dir string
ModDir string
Blacklist map[string]struct{}
}
func init() {
viper.SetDefault(addonEnabledKey, true)
}
func NewAddon() Addon {
return Addon{
IsEnabled: viper.GetBool(addonEnabledKey),
Dir: viper.GetString(gamePathKey) + defaultAddonPath,
ModDir: viper.GetString(gamePathKey) + defaultAddonModPath,
Blacklist: newAddonBlacklist(),
}
}
func newAddonBlacklist() map[string]struct{} {
// parse the blacklist slice into a map to perform O(1) lookups, increase performance
items := viper.GetStringSlice(addonBlacklistKey)
itemMap := make(map[string]struct{})
for _, i := range items {
itemMap[i] = struct{}{}
}
return itemMap
}