golib/gconfig/param.go

34 lines
514 B
Go
Raw Normal View History

2023-06-15 21:22:51 +08:00
//
// 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"
2023-06-15 21:38:12 +08:00
"git.hexq.cn/tiglog/golib/gfile"
2023-06-15 21:22:51 +08:00
)
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)
}
}