January 2020
Intermediate to advanced
640 pages
16h 56m
English
Looking up links is a fairly trivial operation. All we need to do is acquire a read lock, look up the link by its ID, and do either of the following things:
The link lookup logic is outlined in the following code snippet:
func (s *InMemoryGraph) FindLink(id uuid.UUID) (*graph.Link, error) { s.mu.RLock() defer s.mu.RUnlock() link := s.links[id] if link == nil { return nil, xerrors.Errorf("find link: %w", graph.ErrNotFound) } lCopy := new(graph.Link) *lCopy = *link return lCopy, nil }
Since we want to ensure that no external code can modify the graph's contents without invoking the UpsertLink method, the FindLink implementation ...