mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 08:37:13 +00:00
39 lines
531 B
Go
39 lines
531 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"sync"
|
|
|
|
configTypes "grain/config/types"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
var (
|
|
cfg *configTypes.ServerConfig
|
|
once sync.Once
|
|
)
|
|
|
|
func LoadConfig(filename string) (*configTypes.ServerConfig, error) {
|
|
data, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var config configTypes.ServerConfig
|
|
err = yaml.Unmarshal(data, &config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
once.Do(func() {
|
|
cfg = &config
|
|
})
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
func GetConfig() *configTypes.ServerConfig {
|
|
return cfg
|
|
}
|