-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
49 lines (41 loc) · 869 Bytes
/
init.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
package config
import (
"fmt"
"gopkg.in/yaml.v3"
"os"
)
var (
RsConfig = &AppConfig{
EnvCfgFilePath: "",
Env: "",
WrapperConfig: WrapperConfig{},
}
// AppInit IInit
)
type IInit interface {
InitDBClient(wrapperConfig WrapperConfig)
// InitRedisClient(wrapperConfig WrapperConfig)
}
func Init(path string) {
initConfig(path)
// AppInit.InitDBClient(RsConfig.WrapperConfig)
// AppInit.InitRedisClient(RsConfig.WrapperConfig)
}
func initConfig(configFile string) {
path := getEnvCfgFilePath(configFile)
configContent, err := os.ReadFile(path)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(configContent, &RsConfig.WrapperConfig)
if err != nil {
panic(err)
}
}
func ServerPort() string {
port := RsConfig.Config.Server.Port
if port < 0 || port > 65535 {
panic("端口不正确")
}
return fmt.Sprintf(":%d", port)
}