Compare commits

..

No commits in common. "b496ac3691ffe4ae52102812bd5fc0dc36a1fe2c" and "e0902d9ba4ce5d2081e7f91a7a42ca06a28c1e21" have entirely different histories.

2 changed files with 6 additions and 20 deletions

20
atom.go
View File

@ -1,12 +1,10 @@
package atom package atom
import ( import (
"fmt"
"mime" "mime"
"regexp" "regexp"
"strings" "strings"
"github.com/google/uuid"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -63,17 +61,8 @@ func isXMLMediaType(mediaType string) bool {
// isValidMediaType checks whether a string is a valid media type. It returns a // isValidMediaType checks whether a string is a valid media type. It returns a
// bool. // bool.
func isValidMediaType(mediaType string) bool { func isValidMediaType(mediaType string) bool {
mediaType, _, err := mime.ParseMediaType(mediaType) _, _, err := mime.ParseMediaType(mediaType)
if err != nil { return err == nil
return false
}
typeParts := strings.Split(mediaType, "/")
if len(typeParts) != 2 || typeParts[0] == "" || typeParts[1] == "" {
return false
}
return true
} }
// isValidLanguageTag checks whether a LanguageTag is valid. It returns a bool. // isValidLanguageTag checks whether a LanguageTag is valid. It returns a bool.
@ -81,8 +70,3 @@ func isValidLanguageTag(tag LanguageTag) bool {
_, err := language.Parse(string(tag)) _, err := language.Parse(string(tag))
return err == nil return err == nil
} }
// NewURN generates an new valid IRI based on a UUID. It returns an IRI.
func NewURN() IRI {
return IRI(fmt.Sprint("urn:uuid:", uuid.New()))
}

6
id.go
View File

@ -3,6 +3,8 @@ package atom
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/google/uuid"
) )
type ID struct { type ID struct {
@ -11,8 +13,8 @@ type ID struct {
} }
// NewID creates a new ID. It returns a *ID. // NewID creates a new ID. It returns a *ID.
func NewID(id string) *ID { func NewID() *ID {
return &ID{URI: IRI(id)} return &ID{URI: IRI(fmt.Sprint("urn:uuid:", uuid.New()))}
} }
// Check checks the ID for incompatibilities with RFC4287. It returns an error. // Check checks the ID for incompatibilities with RFC4287. It returns an error.