package extract import ( "encoding/xml" "fmt" "os" ) type Params struct { InputData string OutputPath string Satellite string DataId string LogFile string TempPath string Report string Result string Station string } // 定义 InputFileList 结构体 type InputFileList struct { InputData string `xml:"inputdata"` } // 定义 OutputFileList 结构体 type OutputFileList struct { Num int `xml:"num,attr"` OutputPath string `xml:"outputPath"` TempPath string `xml:"tempPath"` ReportFile string `xml:"reportFile"` ResultFile string `xml:"resultFile"` } // 定义 Params 结构体 type XMLParams struct { StationId string `xml:"stationId"` Sensor string `xml:"sensor"` DataId string `xml:"dataId"` SatelliteId string `xml:"satelliteId"` } // 定义 Task 结构体 type L0Task struct { XMLName xml.Name `xml:"task"` InputFileList InputFileList `xml:"inputFileList"` OutputFileList OutputFileList `xml:"outputfilelist"` Params XMLParams `xml:"params"` } // L0 ID const L0_ID = `{{.Satellite}}_{{.Sensor}}_{{.YYMMDD}}_{{.HHMMSS}}_{{.DataId}}_{{.Index}}` const L0TPLFile = "resource/template/satellite/sjy01.l0.xml.tpl" const L0TPL = ` {{.InputData}} {{.OutputPath}} {{.TempPath}} {{.ReportFile}} {{.ResultFile}} WN PMS {{.DataId}} SJY01 ` func LoadL0Params(fname string) (*Params, error) { data, err := os.ReadFile(fname) if err != nil { return nil, err } var task L0Task err = xml.Unmarshal(data, &task) if err != nil { return nil, err } var params Params params.InputData = task.InputFileList.InputData params.OutputPath = task.OutputFileList.OutputPath params.Satellite = task.Params.SatelliteId params.DataId = task.Params.DataId params.Report = task.OutputFileList.ReportFile params.Result = task.OutputFileList.ResultFile params.Station = task.Params.StationId params.LogFile = fmt.Sprintf("/tmp/SJY01/log/%s_l0.log", params.DataId) params.TempPath = task.OutputFileList.TempPath if params.TempPath == "" { params.TempPath = "/tmp/SJY01/data" } return ¶ms, nil }