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
import (
"fmt"
"mime"
"regexp"
"strings"
"github.com/google/uuid"
"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
// bool.
func isValidMediaType(mediaType string) bool {
mediaType, _, err := mime.ParseMediaType(mediaType)
if err != nil {
return false
}
typeParts := strings.Split(mediaType, "/")
if len(typeParts) != 2 || typeParts[0] == "" || typeParts[1] == "" {
return false
}
return true
_, _, err := mime.ParseMediaType(mediaType)
return err == nil
}
// 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))
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 (
"errors"
"fmt"
"github.com/google/uuid"
)
type ID struct {
@ -11,8 +13,8 @@ type ID struct {
}
// NewID creates a new ID. It returns a *ID.
func NewID(id string) *ID {
return &ID{URI: IRI(id)}
func NewID() *ID {
return &ID{URI: IRI(fmt.Sprint("urn:uuid:", uuid.New()))}
}
// Check checks the ID for incompatibilities with RFC4287. It returns an error.