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

Method Unique

codegen/scope.go:56–77  ·  view source on GitHub ↗

Unique returns a unique name for the given name. A suffix is appended to the name if given name is not unique. If suffixed name is still not unique, a counter value is added to the suffixed name until unique.

(name string, suffix ...string)

Source from the content-addressed store, hash-verified

54// name if given name is not unique. If suffixed name is still not unique, a
55// counter value is added to the suffixed name until unique.
56func (s *NameScope) Unique(name string, suffix ...string) string {
57 c, ok := s.counts[name]
58 if !ok {
59 s.counts[name]++
60 return name
61 }
62 if len(suffix) > 0 {
63 name += suffix[0]
64 c, ok = s.counts[name]
65 if !ok {
66 s.counts[name]++
67 return name
68 }
69 }
70 for i := c; ; i++ {
71 ret := name + strconv.Itoa(i+1)
72 if _, ok := s.counts[ret]; !ok {
73 s.counts[ret]++
74 return ret
75 }
76 }
77}
78
79// PeekUnique returns the name that Unique would return for the same inputs,
80// without mutating the scope.

Callers 15

ExampleServerFunction · 0.95
analyzeMethod · 0.95
ExampleCLIFunction · 0.95
exampleServerFunction · 0.95
InitStructFieldsFunction · 0.95
HashedUniqueMethod · 0.95
TestNameScope_UniqueFunction · 0.95
exampleSvrMainFunction · 0.95
analyzeMethod · 0.95
ExampleServiceFilesFunction · 0.95

Calls

no outgoing calls