Good pieces of code

Make and Map

type esDoc struct {
LinkID string `json:"LinkID"`
URL string `json:"URL"`
Title string `json:"Title"`
Content string `json:"Content"`
IndexedAt time.Time `json:"IndexedAt"`
PageRank float64 `json:"PageRank,omitempty"`
}
// Document describes a web-oage whose content has been indexed by Links 'R' Us.
type Document struct {
LinkID uuid.UUID
URL string
Title string
Content string
IndexedAt time.Time
PageRank float64
}
func mapEsDoc(d *esDoc) *index.Document {
return &index.Document{
LinkID: uuid.MustParse(d.LinkID),
URL: d.URL,
Title: d.Title,
Content: d.Content,
IndexedAt: d.IndexedAt.UTC(),
PageRank: d.PageRank,
}
}
func makeEsDoc(d *index.Document) esDoc {
// Note: we intentionally skip PageRank as we don't want updates to
// overwrite existing PageRank values.
return esDoc{
LinkID: d.LinkID.String(),
URL: d.URL,
Title: d.Title,
Content: d.Content,
IndexedAt: d.IndexedAt.UTC(),
}
}
Last updated on