From 4fe133a394ede26da22acba1bb1164183029da0b Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 16 Oct 2024 18:30:22 +0200 Subject: [PATCH] Create isValidMediaType and isValidLanguageTag --- atom.go | 12 ++++++++++++ go.mod | 5 ++++- go.sum | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/atom.go b/atom.go index 850bbc8..c4a1bca 100644 --- a/atom.go +++ b/atom.go @@ -4,6 +4,8 @@ import ( "mime" "regexp" "strings" + + "golang.org/x/text/language" ) type ( @@ -66,3 +68,13 @@ func isXMLMediaType(mediaType string) bool { 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 +} diff --git a/go.mod b/go.mod index ecd0ab9..54d50a3 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module streifling.com/jason/atom-feed 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 +) diff --git a/go.sum b/go.sum index 7790d7c..3eb98bc 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ 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= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=