Created
June 30, 2021 06:49
-
-
Save wadeling/290651d139b3bb5bf0e1821bd2c56e42 to your computer and use it in GitHub Desktop.
Parse image name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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