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

Function inferPackageName

codegen/import_cleanup.go:104–125  ·  view source on GitHub ↗

inferPackageName extracts the package name from an import path. Examples: - "fmt" -> "fmt" - "github.com/foo/bar" -> "bar" - "gopkg.in/yaml.v2" -> "yaml"

(path string)

Source from the content-addressed store, hash-verified

102// - "github.com/foo/bar" -> "bar"
103// - "gopkg.in/yaml.v2" -> "yaml"
104func inferPackageName(path string) string {
105 // Get the last component of the path
106 if idx := strings.LastIndex(path, "/"); idx >= 0 {
107 path = path[idx+1:]
108 }
109
110 // Remove version suffixes like .v2, .v3, etc.
111 if idx := strings.Index(path, ".v"); idx >= 0 {
112 path = path[:idx]
113 }
114
115 // Remove other suffixes after dots (less common)
116 if idx := strings.Index(path, "."); idx >= 0 {
117 // Only if it looks like a version or special suffix
118 suffix := path[idx:]
119 if len(suffix) > 1 && (suffix[1] >= '0' && suffix[1] <= '9' || suffix[1] == 'v') {
120 path = path[:idx]
121 }
122 }
123
124 return path
125}

Callers 1

buildImportMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected