-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
74 lines (61 loc) · 1.68 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
package config
import (
"os"
"path/filepath"
"runtime"
"github.com/HardDie/DeckBuilder/internal/logger"
)
const (
MaxFilenameLength = 200
MinWidth = 2
MinHeight = 2
MaxWidth = 10
MaxHeight = 7
MaxCount = MaxWidth*MaxHeight - 1
)
type Config struct {
Debug bool `json:"debug"`
Version string `json:"version"`
Data string `json:"data"`
Game string `json:"game"`
Cache string `json:"cache"`
Result string `json:"result"`
CardImagePath string `json:"cardImagePath"`
DeckImagePath string `json:"deckImagePath"`
CollectionImagePath string `json:"collectionImagePath"`
GameImagePath string `json:"gameImagePath"`
}
func Get(debugFlag bool, version string) *Config {
data := "DeckBuilderData"
if runtime.GOOS == "darwin" {
// We cannot create a data folder next to an executable file on the macOS system.
// So create a data folder in home directory.
home, err := os.UserHomeDir()
if err != nil {
logger.Error.Fatal("Unable to define a user's home directory")
}
data = filepath.Join(home, data)
}
return &Config{
Debug: debugFlag,
Version: version,
Data: data,
Game: "games",
Cache: "cache",
Result: "result",
CardImagePath: "/api/games/%s/collections/%s/decks/%s/cards/%d/image",
DeckImagePath: "/api/games/%s/collections/%s/decks/%s/image",
CollectionImagePath: "/api/games/%s/collections/%s/image",
GameImagePath: "/api/games/%s/image",
}
}
func (c *Config) Games() string {
return filepath.Join(c.Data, c.Game)
}
func (c *Config) Results() string {
return filepath.Join(c.Data, c.Result)
}
// SetDataPath For tests only!!!
func (c *Config) SetDataPath(dataPath string) {
c.Data = dataPath
}