Compare commits
2 Commits
2480ad8843
...
7c09e8f8f8
Author | SHA1 | Date |
---|---|---|
Maxim Lebedev | 7c09e8f8f8 | |
Maxim Lebedev | 67930d3e2d |
|
@ -9,17 +9,45 @@ import (
|
|||
|
||||
// Entry represent a single microformats2 entry.
|
||||
type Entry struct {
|
||||
UpdatedAt time.Time
|
||||
PublishedAt time.Time
|
||||
DeletedAt time.Time
|
||||
URL *url.URL
|
||||
Params map[string]any
|
||||
Title string
|
||||
Description string
|
||||
Photo []*url.URL
|
||||
Syndications []*url.URL
|
||||
Content []byte
|
||||
Tags []string
|
||||
CreatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
Title string // p-name
|
||||
Description string // p-summary
|
||||
Content []byte // e-content
|
||||
PublishedAt time.Time // dt-published
|
||||
UpdatedAt time.Time // dt-updated
|
||||
// TODO(toby3d): Author string // p-author
|
||||
Tags []string // p-category
|
||||
URL *url.URL // u-url
|
||||
ID string // u-uid
|
||||
// TODO(toby3d): Location string // p-location
|
||||
Syndications []*url.URL // u-syndication
|
||||
// TODO(toby3d): Reply *url.URL // u-in-reply-to
|
||||
RSVP RSVP // p-rsvp
|
||||
// TODO(toby3d): Like *url.URL // u-like-of
|
||||
// TODO(toby3d): Repost *url.URL // u-repost-of
|
||||
|
||||
// Draft Properties
|
||||
// TODO(toby3d): Comments []string // p-comment
|
||||
Photo []*url.URL // u-photo
|
||||
Video []*url.URL // u-video
|
||||
|
||||
// Proposed Additions
|
||||
Audio []*url.URL // u-audio
|
||||
// TODO(toby3d): Like []*url.URL // u-like
|
||||
// TODO(toby3d): Repost []*url.URL // u-repost
|
||||
// TODO(toby3d): BookmarkOf []*url.URL // u-bookmark-of
|
||||
// TODO(toby3d): Featured []*url.URL // u-featured
|
||||
Latitude float32 // p-latitude
|
||||
Longitude float32 // p-longitude
|
||||
Altitude float32 // p-altitude
|
||||
// TODO(toby3d): Duration int // p-duration
|
||||
// TODO(toby3d): Size int // p-size
|
||||
// TODO(toby3d): ListenOf *url.URL // u-listen-of
|
||||
// TODO(toby3d): WatchOf *url.URL // u-watch-of
|
||||
// TODO(toby3d): ReadOf *url.URL // u-read-of
|
||||
// TODO(toby3d): TranslationOf *url.URL // u-translation-of
|
||||
// TODO(toby3d): Checkin *url.URL // u-checking
|
||||
}
|
||||
|
||||
// TestEntry returns a random valid Entry for tests.
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// RSVP represent a enum status relation to some event.
|
||||
type RSVP struct {
|
||||
rsvp string
|
||||
}
|
||||
|
||||
var (
|
||||
RSVPUnd RSVP = RSVP{} // "und"
|
||||
RSVPInterested RSVP = RSVP{"interested"} // "interested"
|
||||
RSVPMaybe RSVP = RSVP{"maybe"} // "maybe"
|
||||
RSVPNo RSVP = RSVP{"no"} // "no"
|
||||
RSVPYes RSVP = RSVP{"yes"} // "yes"
|
||||
)
|
||||
|
||||
var ErrRSVPSyntax error = Error{
|
||||
Description: fmt.Sprintf("got unsupported RSVP enum value, expect '%s', '%s', '%s' or '%s'", RSVPInterested,
|
||||
RSVPMaybe, RSVPNo, RSVPYes),
|
||||
Frame: xerrors.Caller(1),
|
||||
Code: http.StatusBadRequest,
|
||||
}
|
||||
|
||||
var stringsRSVPs = map[string]RSVP{
|
||||
RSVPInterested.rsvp: RSVPInterested,
|
||||
RSVPMaybe.rsvp: RSVPMaybe,
|
||||
RSVPNo.rsvp: RSVPNo,
|
||||
RSVPYes.rsvp: RSVPYes,
|
||||
}
|
||||
|
||||
func ParseRSVP(v string) (RSVP, error) {
|
||||
// NOTE(toby3d): Case-insensitive values, normalized to lowercase.
|
||||
if out, ok := stringsRSVPs[strings.ToLower(v)]; ok {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
return RSVPUnd, fmt.Errorf("cannot parse '%s' as RSVP enum: %w", v, ErrRSVPSyntax)
|
||||
}
|
||||
|
||||
func (rsvp RSVP) String() string {
|
||||
if rsvp.rsvp != "" {
|
||||
return rsvp.rsvp
|
||||
}
|
||||
|
||||
return "und"
|
||||
}
|
||||
|
||||
func (rsvp RSVP) GoString() string {
|
||||
return "domain.RSVP(" + rsvp.String() + ")"
|
||||
}
|
Loading…
Reference in New Issue