FastModuleSourceKindCheck performs a quick heuristic check to determine whether a module ref string refers to a local path or a git source. Returns "" if the kind cannot be determined without further inspection.
( refString string, refPin string, )
| 21 | // whether a module ref string refers to a local path or a git source. |
| 22 | // Returns "" if the kind cannot be determined without further inspection. |
| 23 | func FastModuleSourceKindCheck( |
| 24 | refString string, |
| 25 | refPin string, |
| 26 | ) ModuleSourceKind { |
| 27 | switch { |
| 28 | case refPin != "": |
| 29 | return ModuleSourceKindGit |
| 30 | case len(refString) > 0 && (refString[0] == '/' || refString[0] == '.'): |
| 31 | return ModuleSourceKindLocal |
| 32 | case len(refString) > 1 && refString[0:2] == "..": |
| 33 | return ModuleSourceKindLocal |
| 34 | case strings.HasPrefix(refString, SchemeHTTP.Prefix()): |
| 35 | return ModuleSourceKindGit |
| 36 | case strings.HasPrefix(refString, SchemeHTTPS.Prefix()): |
| 37 | return ModuleSourceKindGit |
| 38 | case strings.HasPrefix(refString, SchemeSSH.Prefix()): |
| 39 | return ModuleSourceKindGit |
| 40 | case !strings.Contains(refString, "."): |
| 41 | // technically host names can not have any dot, but we can save a lot of work |
| 42 | // by assuming a dot-free ref string is a local path. Users can prefix |
| 43 | // args with a scheme:// to disambiguate these obscure corner cases. |
| 44 | return ModuleSourceKindLocal |
| 45 | default: |
| 46 | return "" |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | type ParsedRefString struct { |
| 51 | Kind ModuleSourceKind |
no test coverage detected