diff --git a/helpers/config.go b/helpers/config.go index b02ce71..4376dfd 100644 --- a/helpers/config.go +++ b/helpers/config.go @@ -5,7 +5,7 @@ import ( ) // Version Constants -const versionNum string = "2024.10.1" +const versionNum string = "2024.10.2" const versionSuffix string = "" const Version string = versionNum + versionSuffix diff --git a/pis/data.go b/pis/data.go index 2e73044..6408c75 100644 --- a/pis/data.go +++ b/pis/data.go @@ -14,21 +14,27 @@ import ( // Process the YAML data to a struct func processYaml(yamlStr string) (*[]database.PIS, error) { - var pis []PisData + // Define 'container' struct + var pisData struct { + Pis []PisData `yaml:"pis"` + } - // Unmarshal the YAML data into a slice of PisData - err := yaml.Unmarshal([]byte(yamlStr), &pis) + // Unmarshal the YAML data into the structure + err := yaml.Unmarshal([]byte(yamlStr), &pisData) if err != nil { return nil, fmt.Errorf("failed to unmarshal YAML: %v", err) } // Perform deduplication on the entire pis slice - err = deduplicateCodes(&pis) + err = deduplicateCodes(&pisData.Pis) if err != nil { return nil, err } - documents, err := convertPisForDatabase(&pis) + documents, err := convertPisForDatabase(&pisData.Pis) + if err != nil { + return nil, err + } return documents, nil } diff --git a/pis/update.go b/pis/update.go index 8a14f5a..c3544fb 100644 --- a/pis/update.go +++ b/pis/update.go @@ -9,6 +9,9 @@ import ( "os" "path/filepath" "strings" + + "git.fjla.uk/owlboard/timetable-mgr/log" + "go.uber.org/zap" ) const ( @@ -127,7 +130,7 @@ func extractFiles(gzipStream io.Reader, dest string) error { } outFile.Close() default: - fmt.Printf("Unable to handle filetype %c in %s\n", header.Typeflag, header.Name) + log.Warn("Unable to handle filetype", zap.String("Typeflag", string(header.Typeflag)), zap.String("Filename", header.Name)) } } return nil @@ -145,7 +148,7 @@ func extractYamlData(dir string) (string, error) { // Check if the path contains 'pis' and has a .yaml or .yml extension if strings.Contains(path, "/pis/") && !info.IsDir() && (strings.HasSuffix(info.Name(), ".yaml") || strings.HasSuffix(info.Name(), ".yml")) { - fmt.Printf("Processing YAML file in 'pis' directory: %s\n", path) + log.Debug("Processing YAML", zap.String("directory", path)) file, err := os.Open(path) if err != nil { @@ -179,7 +182,7 @@ func cleanupFiles(paths ...string) { for _, path := range paths { err := os.RemoveAll(path) if err != nil { - fmt.Printf("Error removing %s: %v\n", path, err) + log.Warn("Error removing file", zap.String("path", path), zap.Error(err)) } } }