-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
52 lines (41 loc) · 1021 Bytes
/
types.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
package profile
import (
"os"
"path"
"github.com/spf13/viper"
)
type Type int
const (
// Unknown indicates that the profile has not been installed yet.
Unknown Type = iota
Vanilla
Fabric
)
type Profile struct {
Name string `json:"name"`
Directory string `json:"directory"`
config *Config // Config is loaded on demand
Type Type `json:"type"`
// Version represents the Minecraft version of the profile.
// Present no matter the type (except Unknown)
Version string `json:"version"`
}
func (p *Profile) Config() *Config {
if p.config != nil {
return p.config
}
v := viper.New()
v.SetConfigFile(path.Join(p.Directory, "config.json"))
// Read the config file if it exists
if _, err := os.Stat(v.ConfigFileUsed()); err == nil {
if err := v.ReadInConfig(); err != nil {
panic(err) //todo this should proceed with default config and log an error
}
}
var config Config
if err := v.Unmarshal(&config); err != nil {
panic(err) //todo
}
p.config = &config
return p.config
}