Compare commits
3 Commits
e0902d9ba4
...
b496ac3691
Author | SHA1 | Date | |
---|---|---|---|
b496ac3691 | |||
13e7a16178 | |||
3734a3eb3d |
20
atom.go
20
atom.go
@ -1,10 +1,12 @@
|
|||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,8 +63,17 @@ 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 {
|
||||||
_, _, err := mime.ParseMediaType(mediaType)
|
mediaType, _, err := mime.ParseMediaType(mediaType)
|
||||||
return err == nil
|
if 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.
|
||||||
@ -70,3 +81,8 @@ 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
6
id.go
@ -3,8 +3,6 @@ package atom
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ID struct {
|
type ID struct {
|
||||||
@ -13,8 +11,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 {
|
func NewID(id string) *ID {
|
||||||
return &ID{URI: IRI(fmt.Sprint("urn:uuid:", uuid.New()))}
|
return &ID{URI: IRI(id)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check checks the ID for incompatibilities with RFC4287. It returns an error.
|
// Check checks the ID for incompatibilities with RFC4287. It returns an error.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user