hub/internal/domain/topic.go

44 lines
775 B
Go
Raw Normal View History

2023-03-12 07:33:08 +00:00
package domain
import (
"net/url"
"testing"
"time"
2023-03-12 07:33:08 +00:00
"source.toby3d.me/toby3d/hub/internal/common"
)
type Topic struct {
CreatedAt time.Time
UpdatedAt time.Time
Self *url.URL
ContentType string
Content []byte
2023-03-12 07:33:08 +00:00
}
func TestTopic(tb testing.TB) *Topic {
tb.Helper()
now := time.Now().UTC().Add(-1 * time.Hour)
2023-03-12 07:33:08 +00:00
return &Topic{
CreatedAt: now,
UpdatedAt: now,
Self: &url.URL{Scheme: "https", Host: "example.com", Path: "/"},
ContentType: "text/html",
Content: []byte("hello, world"),
}
2023-03-12 07:33:08 +00:00
}
func (t Topic) AddQuery(q url.Values) {
q.Add(common.HubTopic, t.Self.String())
2023-03-12 07:33:08 +00:00
}
func (t Topic) Equal(target Topic) bool {
return t.Self.String() == target.Self.String()
2023-03-12 07:33:08 +00:00
}
func (t Topic) String() string {
return t.Self.String()
2023-03-12 07:33:08 +00:00
}