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

Upserting edges

The edge upsert logic in UpsertEdge has a lot of things in common with the UpsertLink implementation we examined in the previous section. The first thing we need to do is acquire the write lock and verify that the source and destination links for the edge actually exist:

s.mu.Lock()
defer s.mu.Unlock()

_, srcExists := s.links[edge.Src]
_, dstExists := s.links[edge.Dst]
if !srcExists || !dstExists {
    return xerrors.Errorf("upsert edge: %w", graph.ErrUnknownEdgeLinks)
}

Next, we scan the set of edges that originate from the specified source link and check whether we can find an existing edge to the same destination. If that happens to be the case, we simply update the entry's UpdatedAt field and copy its contents back 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