Skip to content

Commit

Permalink
Add filename regex
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandromr committed Nov 12, 2022
1 parent dc601b0 commit 8291e4f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cmd/formatter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"os"
"regexp"

"github.com/italiaremote/awesome-italia-remote/pkg/cmp"
)
Expand All @@ -16,6 +17,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
fileNameRegex := regexp.MustCompile(`([a-zA-Z0-9\_\-]+).json$`)

for _, companyFiles := range companiesFile {
fileName := dataPath + companyFiles.Name()
Expand All @@ -25,6 +27,10 @@ func main() {
}
var company cmp.Company

if !fileNameRegex.MatchString(fileName) {
log.Fatalln("Invalid filename, use only letters. numbers and - _")
}

err = json.Unmarshal(file, &company)
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit 8291e4f

Please sign in to comment.