Create isValidMediaType and isValidLanguageTag

This commit is contained in:
Jason Streifling 2024-10-16 18:30:22 +02:00
parent 39bd0776c5
commit 4fe133a394
3 changed files with 18 additions and 1 deletions

12
atom.go
View File

@ -4,6 +4,8 @@ import (
"mime" "mime"
"regexp" "regexp"
"strings" "strings"
"golang.org/x/text/language"
) )
type ( type (
@ -66,3 +68,13 @@ func isXMLMediaType(mediaType string) bool {
return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml") return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml")
} }
func isValidMediaType(mediaType string) bool {
_, _, err := mime.ParseMediaType(mediaType)
return err == nil
}
func isValidLanguageTag(tag LanguageTag) bool {
_, err := language.Parse(string(tag))
return err == nil
}

5
go.mod
View File

@ -2,4 +2,7 @@ module streifling.com/jason/atom-feed
go 1.23.2 go 1.23.2
require github.com/google/uuid v1.6.0 require (
github.com/google/uuid v1.6.0
golang.org/x/text v0.19.0
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=