-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
65 lines (51 loc) · 1022 Bytes
/
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
package swagen
import (
"errors"
"os"
)
const VERSION string = "0.0.1"
const (
PATH_DIR = "PATH_DIR"
MESSAGE_DIR = "MESSAGE_DIR"
MODEL_DIR = "MODEL_DIR"
)
var config *Config
type Config struct {
PathDir string
MessageDir string
ModelDir string
}
func (c *Config) GetPathDir() string {
return c.PathDir
}
func (c *Config) GetMessageDir() string {
return c.MessageDir
}
func (c *Config) GetModelDir() string {
return c.ModelDir
}
func NewConfig() (*Config, error) {
pathMessage := os.Getenv(PATH_DIR)
if pathMessage == "" {
return nil, errors.New("PATH_DIR is not set")
}
messageDir := os.Getenv(MESSAGE_DIR)
if messageDir == "" {
return nil, errors.New("MESSAGE_DIR is not set")
}
modelDir := os.Getenv(MODEL_DIR)
if modelDir == "" {
return nil, errors.New("MODEL_DIR is not set")
}
return &Config{
PathDir: pathMessage,
MessageDir: messageDir,
ModelDir: modelDir,
}, nil
}
func GetConfig() *Config {
return config
}
func SetConfig(c *Config) {
config = c
}