Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Defining a Go interface for the link graph

To satisfy the list of operations from the previous section, we shall define the Graph interface as follows:

type Graph interface {
    UpsertLink(link *Link) error
    FindLink(id uuid.UUID) (*Link, error)

    UpsertEdge(edge *Edge) error
    RemoveStaleEdges(fromID uuid.UUID, updatedBefore time.Time) error

    Links(fromID, toID uuid.UUID, retrievedBefore time.Time) (LinkIterator, error)
    Edges(fromID, toID uuid.UUID, updatedBefore time.Time) (EdgeIterator, error)
}

The first two methods allow us to upsert a Link model and retrieve it from the backing store if we are aware of its ID. In the following code, you can see the definition of the Link type, whose fields match the ones from the ER diagram:

type Link struct ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content