FullModuleName is a helper function that returns the embedded module name. This is the parent directory that an embedded code base should use as prefix.
(moduleName string)
| 114 | // FullModuleName is a helper function that returns the embedded module name. |
| 115 | // This is the parent directory that an embedded code base should use as prefix. |
| 116 | func FullModuleName(moduleName string) string { |
| 117 | pc, _, _, ok := runtime.Caller(1) |
| 118 | if !ok { |
| 119 | panic("caller info not found") |
| 120 | } |
| 121 | s := runtime.FuncForPC(pc).Name() |
| 122 | chunks := strings.Split(s, "/") |
| 123 | if len(chunks) < 2 { |
| 124 | // programming error |
| 125 | panic("split pattern not found") |
| 126 | } |
| 127 | name := chunks[len(chunks)-2] |
| 128 | if name == "" { |
| 129 | panic("name not found") |
| 130 | } |
| 131 | if moduleName == "" { // in case we only want to know the module name |
| 132 | return name |
| 133 | } |
| 134 | return name + "/" + moduleName // do the concat for the user! |
| 135 | } |