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

Iterating links/edges

To obtain an iterator for the graph links or edges, users need to invoke the Links or Edges methods. Let's take a look at how the Links method is implemented:

func (s *InMemoryGraph) Links(fromID, toID uuid.UUID, retrievedBefore time.Time) (graph.LinkIterator, error) {
    from, to := fromID.String(), toID.String()

    s.mu.RLock()
    var list []*graph.Link
    for linkID, link := range s.links {
        if id := linkID.String(); id >= from && id < to && link.RetrievedAt.Before(retrievedBefore) {
            list = append(list, link)
        }
    }
    s.mu.RUnlock()

    return &linkIterator{s: s, links: list}, nil
}

In the preceding implementation, we obtain a read lock and then proceed to iterate all the links in the graph, searching for the ones that belong to the

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