github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/docgen/api/unique.go (about)

     1  package docgen
     2  
     3  import "fmt"
     4  
     5  const strAlreadyExists = "'%s' already exists in '%s' (%s)"
     6  
     7  func unique() bool {
     8  	var failed bool
     9  
    10  	m := make(map[string]document)
    11  	for _, d := range Documents {
    12  		dup, ok := m[d.DocumentID]
    13  		if ok {
    14  			warning(d.SourcePath, fmt.Sprintf(strAlreadyExists, d.DocumentID, dup.SourcePath, dup.CategoryID))
    15  			failed = true
    16  			continue
    17  		}
    18  
    19  		for _, sym := range d.Synonyms {
    20  			dup, ok := m[sym]
    21  			if ok {
    22  				warning(d.SourcePath, fmt.Sprintf(strAlreadyExists, sym, dup.SourcePath, dup.CategoryID))
    23  				failed = true
    24  				continue
    25  			}
    26  			m[sym] = d
    27  		}
    28  
    29  		m[d.DocumentID] = d
    30  	}
    31  
    32  	return !failed
    33  }