增加saastool功能
This commit is contained in:
38
cmd/saastool/target_cfg.go
Normal file
38
cmd/saastool/target_cfg.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
// TargetConfig 配置
|
||||
type TargetConfig 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 LoadTargetFile(filename string) (*TargetConfig, error) {
|
||||
// 打开文件
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
sc := &TargetConfig{}
|
||||
|
||||
err = json.NewDecoder(f).Decode(sc)
|
||||
return sc, err
|
||||
}
|
||||
Reference in New Issue
Block a user