feat: optimise get server ip (#20)

* feat: optimise get server ip

* feat: test ServerIP
This commit is contained in:
Yaxian
2021-10-21 11:30:48 +08:00
committed by GitHub
parent 7caf5a0df9
commit c8155553b8
3 changed files with 32 additions and 20 deletions

View File

@@ -1,8 +1,17 @@
package config
import (
"gopkg.in/yaml.v3"
"io/ioutil"
"path/filepath"
"runtime"
"gopkg.in/yaml.v3"
)
var (
_, b, _, _ = runtime.Caller(0)
// Root folder of this project
Root = filepath.Join(filepath.Dir(b), "../../..")
)
var Config config
@@ -147,14 +156,14 @@ type config struct {
}
func init() {
bytes, err := ioutil.ReadFile("../config/config.yaml")
// if we cd Open-IM-Server/src/utils and run go test
// it will panic cannot find config/config.yaml
bytes, err := ioutil.ReadFile(Root + "/config/config.yaml")
if err != nil {
panic(err)
return
}
if err = yaml.Unmarshal(bytes, &Config); err != nil {
panic(err)
return
}
}