39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
// MapConfig 配置
|
|
type MapConfig struct {
|
|
Targets map[string]*Target `json:"targets"`
|
|
}
|
|
|
|
// Target 配置
|
|
type Target struct {
|
|
WriteByte *byte `json:"write_byte"` // byte值
|
|
WriteBytePos int `json:"write_byte_pos"` // byte写入位置
|
|
WriteUint32 *uint32 `json:"write_uint32"` // uint32值
|
|
WriteUint32Pos int `json:"write_uint32_pos"` // uint32写入位置
|
|
WriteFlag *bool `json:"write_flag"` // 标志位
|
|
WriteExpire *uint32 `json:"write_expire"` // 过期时间
|
|
WriteFlagWithExpirePos int `json:"write_flag_with_expire_pos"` // 标志与过期写入位置
|
|
|
|
}
|
|
|
|
// LoadConfigFile 加载配置文件
|
|
func LoadMapFile(filename string) (*MapConfig, error) {
|
|
// 打开文件
|
|
f, err := os.Open(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
sc := &MapConfig{}
|
|
|
|
err = json.NewDecoder(f).Decode(sc)
|
|
return sc, err
|
|
}
|