MCPcopy Create free account
hub / github.com/docker/docker-language-server / extractImageLink

Function extractImageLink

internal/compose/documentLink.go:372–413  ·  view source on GitHub ↗
(nodeValue string)

Source from the content-addressed store, hash-verified

370}
371
372func extractImageLink(nodeValue string) (string, string) {
373 if strings.HasPrefix(nodeValue, "ghcr.io") {
374 return extractNonDockerHubImageLink(nodeValue, "ghcr.io", "https://", 0)
375 }
376
377 if strings.HasPrefix(nodeValue, "mcr.microsoft.com") {
378 if len(nodeValue) <= 18 {
379 return "", ""
380 }
381 idx := strings.LastIndex(nodeValue, ":")
382 if idx == 17 {
383 return "", ""
384 }
385 lastSlashIdx := strings.LastIndex(nodeValue, "/")
386 if lastSlashIdx == idx-1 || (idx != -1 && lastSlashIdx > idx) {
387 return "", ""
388 }
389 if idx == -1 {
390 return nodeValue, fmt.Sprintf("https://mcr.microsoft.com/artifact/mar/%v", nodeValue[18:])
391 }
392 return nodeValue[0:idx], fmt.Sprintf("https://mcr.microsoft.com/artifact/mar/%v", nodeValue[18:idx])
393 }
394
395 if strings.HasPrefix(nodeValue, "quay.io") {
396 return extractNonDockerHubImageLink(nodeValue, "quay.io", "https://quay.io/repository/", 8)
397 }
398
399 idx := strings.LastIndex(nodeValue, ":")
400 if idx == -1 {
401 idx := strings.Index(nodeValue, "/")
402 if idx == -1 {
403 return nodeValue, fmt.Sprintf("https://hub.docker.com/_/%v", nodeValue)
404 }
405 return nodeValue, fmt.Sprintf("https://hub.docker.com/r/%v", nodeValue)
406 }
407
408 slashIndex := strings.Index(nodeValue, "/")
409 if slashIndex == -1 {
410 return nodeValue[0:idx], fmt.Sprintf("https://hub.docker.com/_/%v", nodeValue[0:idx])
411 }
412 return nodeValue[0:idx], fmt.Sprintf("https://hub.docker.com/r/%v", nodeValue[0:idx])
413}
414
415func extractModelLink(nodeValue string) (string, string) {
416 if strings.HasPrefix(nodeValue, "hf.co") {

Callers 1

createImageLinkFunction · 0.85

Calls 1

Tested by

no test coverage detected