34 lines
510 B
Go
34 lines
510 B
Go
|
//
|
||
|
// param.go
|
||
|
// Copyright (C) 2022 tiglog <me@tiglog.com>
|
||
|
//
|
||
|
// Distributed under terms of the MIT license.
|
||
|
//
|
||
|
|
||
|
package gconfig
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
"hexq.cn/tiglog/golib/gfile"
|
||
|
)
|
||
|
|
||
|
type ParamConfig struct {
|
||
|
Params map[string]any
|
||
|
}
|
||
|
|
||
|
func (c *ParamConfig) Load(fp string) {
|
||
|
if !gfile.Exists(fp) {
|
||
|
panic("配置文件 " + fp + " 不存在")
|
||
|
}
|
||
|
dat, err := ioutil.ReadFile(fp)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
err = yaml.Unmarshal(dat, &c.Params)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|