package common import ( "github.com/pelletier/go-toml/v2" "google.golang.org/protobuf/types/known/structpb" "log/slog" "os" ) var Opts Options type StringValueEntry struct { Text string `toml:"text"` Value string `toml:"value"` } func (se *StringValueEntry) Struct() *structpb.Struct { return &structpb.Struct{ Fields: map[string]*structpb.Value{ "text": structpb.NewStringValue(se.Text), "value": structpb.NewStringValue(se.Value), }, } } type Float64ValueEntry struct { Text string `toml:"text"` Value float64 `toml:"value"` } func (ie *Float64ValueEntry) Struct() *structpb.Struct { return &structpb.Struct{ Fields: map[string]*structpb.Value{ "text": structpb.NewStringValue(ie.Text), "value": structpb.NewNumberValue(ie.Value), }, } } type AprCboOptions struct { AECFiled []StringValueEntry `toml:"aec_filed"` AECFilm []Float64ValueEntry `toml:"aec_film"` CompressionForce []Float64ValueEntry `toml:"compression_force"` Dose []Float64ValueEntry `toml:"dose"` ExpCorrection []Float64ValueEntry `toml:"exp_correction"` ExposureMode []StringValueEntry `toml:"exposure_mode"` Focus []Float64ValueEntry `toml:"focus"` GridType []Float64ValueEntry `toml:"grid_type"` PatientSize []StringValueEntry `toml:"patient_size"` TubeLoad []Float64ValueEntry `toml:"tube_load"` KV []Float64ValueEntry `toml:"kv"` Ma []Float64ValueEntry `toml:"ma"` Mas []Float64ValueEntry `toml:"mas"` Ms []Float64ValueEntry `toml:"ms"` } type Options struct { AprCbo AprCboOptions `toml:"apr_cbo"` } func init() { configFilePath := "config/options.toml" // 1. 读取 TOML 文件内容 data, err := os.ReadFile(configFilePath) if err != nil { slog.Error("Unable to parse options file", "file", configFilePath, "err", err) panic(err) } err = toml.Unmarshal(data, &Opts) if err != nil { slog.Error("Error parsing TOML", "err", err) panic(err) } slog.Info("Parsed options success") }