Skip to content

Instantly share code, notes, and snippets.

@wadeling
Created June 30, 2021 06:49
Show Gist options
  • Save wadeling/290651d139b3bb5bf0e1821bd2c56e42 to your computer and use it in GitHub Desktop.
Save wadeling/290651d139b3bb5bf0e1821bd2c56e42 to your computer and use it in GitHub Desktop.
Parse image name
package main
import (
"fmt"
"github.com/google/go-containerregistry/pkg/name"
)
func main() {
fmt.Println("start")
//imageName := "wade23/trivy/server:server-test"
imageName := "192.168.208.195:80/nginx/nginx:1.15"
var nameOpts []name.Option
nameOpts = append(nameOpts, name.Insecure)
ref, err := name.ParseReference(imageName, nameOpts...)
if err != nil {
fmt.Println("parse image name err",err)
}
tag:= ref.Identifier()
fullName := ref.Name()
repo := ref.Context()
repositoryName := repo.RepositoryStr()
registryStr := repo.RegistryStr()
fmt.Printf("tag %s,fullName %s,repositoryName %s,registryStr %s",tag,fullName,repositoryName,registryStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment