MCPcopy Create free account
hub / github.com/goadesign/goa / PeekUnique

Method PeekUnique

codegen/scope.go:85–103  ·  view source on GitHub ↗

PeekUnique returns the name that Unique would return for the same inputs, without mutating the scope. This is useful when synthesizing type names or identifiers that are later reserved via Hash-based naming (e.g., GoTypeName/HashedUnique) and therefore must not increment the scope counters twice.

(name string, suffix ...string)

Source from the content-addressed store, hash-verified

83// reserved via Hash-based naming (e.g., GoTypeName/HashedUnique) and therefore
84// must not increment the scope counters twice.
85func (s *NameScope) PeekUnique(name string, suffix ...string) string {
86 c, ok := s.counts[name]
87 if !ok {
88 return name
89 }
90 if len(suffix) > 0 {
91 name += suffix[0]
92 c, ok = s.counts[name]
93 if !ok {
94 return name
95 }
96 }
97 for i := c; ; i++ {
98 ret := name + strconv.Itoa(i+1)
99 if _, ok := s.counts[ret]; !ok {
100 return ret
101 }
102 }
103}
104
105// Name returns a unique name for the given name by adding a counter value to
106// the name until unique. It returns the same value when called multiple times

Calls

no outgoing calls