()
| 214 | } |
| 215 | |
| 216 | func getModules() (standard, nonstandard, unknown []moduleInfo, err error) { |
| 217 | bi, ok := debug.ReadBuildInfo() |
| 218 | if !ok { |
| 219 | err = fmt.Errorf("no build info") |
| 220 | return standard, nonstandard, unknown, err |
| 221 | } |
| 222 | |
| 223 | for _, modID := range caddy.Modules() { |
| 224 | modInfo, err := caddy.GetModule(modID) |
| 225 | if err != nil { |
| 226 | // that's weird, shouldn't happen |
| 227 | unknown = append(unknown, moduleInfo{caddyModuleID: modID, err: err}) |
| 228 | continue |
| 229 | } |
| 230 | |
| 231 | // to get the Caddy plugin's version info, we need to know |
| 232 | // the package that the Caddy module's value comes from; we |
| 233 | // can use reflection but we need a non-pointer value (I'm |
| 234 | // not sure why), and since New() should return a pointer |
| 235 | // value, we need to dereference it first |
| 236 | iface := any(modInfo.New()) |
| 237 | if rv := reflect.ValueOf(iface); rv.Kind() == reflect.Pointer { |
| 238 | iface = reflect.New(reflect.TypeOf(iface).Elem()).Elem().Interface() |
| 239 | } |
| 240 | modPkgPath := reflect.TypeOf(iface).PkgPath() |
| 241 | |
| 242 | // now we find the Go module that the Caddy module's package |
| 243 | // belongs to; we assume the Caddy module package path will |
| 244 | // be prefixed by its Go module path, and we will choose the |
| 245 | // longest matching prefix in case there are nested modules |
| 246 | var matched *debug.Module |
| 247 | for _, dep := range bi.Deps { |
| 248 | if strings.HasPrefix(modPkgPath, dep.Path) { |
| 249 | if matched == nil || len(dep.Path) > len(matched.Path) { |
| 250 | matched = dep |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | caddyModGoMod := moduleInfo{caddyModuleID: modID, goModule: matched} |
| 256 | |
| 257 | if strings.HasPrefix(modPkgPath, caddy.ImportPath) { |
| 258 | standard = append(standard, caddyModGoMod) |
| 259 | } else { |
| 260 | nonstandard = append(nonstandard, caddyModGoMod) |
| 261 | } |
| 262 | } |
| 263 | return standard, nonstandard, unknown, err |
| 264 | } |
| 265 | |
| 266 | func listModules(path string) error { |
| 267 | cmd := exec.Command(path, "list-modules", "--versions", "--skip-standard") |
no test coverage detected