-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
65 lines (54 loc) · 1.38 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
package config
import (
"os"
"time"
"github.com/quanxiang-cloud/cabin/logger"
mysql2 "github.com/quanxiang-cloud/cabin/tailormade/db/mysql"
redis2 "github.com/quanxiang-cloud/cabin/tailormade/db/redis"
"gopkg.in/yaml.v2"
)
// Conf configuration file.
var Conf *Config
// DefaultPath default configuration path.
var DefaultPath = "./configs/config.yml"
// Config configuration file.
type Config struct {
Port string `yaml:"port"`
Model string `yaml:"model"`
MaxSize int64 `yaml:"maxSize"`
Log logger.Config `yaml:"log"`
Mysql mysql2.Config `yaml:"mysql"`
Redis redis2.Config `yaml:"redis"`
Storage Storage `yaml:"storage"`
Blob Blob `yaml:"blob"`
Buckets map[string]string `yaml:"buckets"`
}
// Storage Storage.
type Storage struct {
AccessKeyID string
SecretAccessKey string
Endpoint string
Region string
URLExpire time.Duration
PartExpire time.Duration
}
// Blob decompression configuration.
type Blob struct {
Template string `yaml:"template"`
TempPath string `yaml:"tempPath"`
}
// NewConfig get configuration.
func NewConfig(path string) (*Config, error) {
if path == "" {
path = DefaultPath
}
file, err := os.ReadFile(path)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(file, &Conf)
if err != nil {
return nil, err
}
return Conf, nil
}