options.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package common
  2. import (
  3. "github.com/pelletier/go-toml/v2"
  4. "google.golang.org/protobuf/types/known/structpb"
  5. "log/slog"
  6. "os"
  7. )
  8. var Opts Options
  9. type StringValueEntry struct {
  10. Text string `toml:"text"`
  11. Value string `toml:"value"`
  12. }
  13. func (se *StringValueEntry) Struct() *structpb.Struct {
  14. return &structpb.Struct{
  15. Fields: map[string]*structpb.Value{
  16. "text": structpb.NewStringValue(se.Text),
  17. "value": structpb.NewStringValue(se.Value),
  18. },
  19. }
  20. }
  21. type Float64ValueEntry struct {
  22. Text string `toml:"text"`
  23. Value float64 `toml:"value"`
  24. }
  25. func (ie *Float64ValueEntry) Struct() *structpb.Struct {
  26. return &structpb.Struct{
  27. Fields: map[string]*structpb.Value{
  28. "text": structpb.NewStringValue(ie.Text),
  29. "value": structpb.NewNumberValue(ie.Value),
  30. },
  31. }
  32. }
  33. type AprCboOptions struct {
  34. AECFiled []StringValueEntry `toml:"aec_filed"`
  35. AECFilm []Float64ValueEntry `toml:"aec_film"`
  36. CompressionForce []Float64ValueEntry `toml:"compression_force"`
  37. Dose []Float64ValueEntry `toml:"dose"`
  38. ExpCorrection []Float64ValueEntry `toml:"exp_correction"`
  39. ExposureMode []StringValueEntry `toml:"exposure_mode"`
  40. Focus []Float64ValueEntry `toml:"focus"`
  41. GridType []Float64ValueEntry `toml:"grid_type"`
  42. PatientSize []StringValueEntry `toml:"patient_size"`
  43. TubeLoad []Float64ValueEntry `toml:"tube_load"`
  44. KV []Float64ValueEntry `toml:"kv"`
  45. Ma []Float64ValueEntry `toml:"ma"`
  46. Mas []Float64ValueEntry `toml:"mas"`
  47. Ms []Float64ValueEntry `toml:"ms"`
  48. }
  49. type Options struct {
  50. AprCbo AprCboOptions `toml:"apr_cbo"`
  51. }
  52. func init() {
  53. configFilePath := "config/options.toml"
  54. // 1. 读取 TOML 文件内容
  55. data, err := os.ReadFile(configFilePath)
  56. if err != nil {
  57. slog.Error("Unable to parse options file", "file", configFilePath, "err", err)
  58. panic(err)
  59. }
  60. err = toml.Unmarshal(data, &Opts)
  61. if err != nil {
  62. slog.Error("Error parsing TOML", "err", err)
  63. panic(err)
  64. }
  65. slog.Info("Parsed options success")
  66. }