当前位置:网站首页>Golang through pointer for Range implements the change of the value of the element in the slice

Golang through pointer for Range implements the change of the value of the element in the slice

2022-07-05 18:54:00 Learn programming notes

*(&build.Args[2])=destination
*(&build.Args[6])=cacherepo
// Resolve when editing again ,workflow template The problem of not getting updates .
// Latest solutions : adopt argo workflow Global parameter mechanism to solve 
builds := argoflowObject.Spec.Templates.Build
for _, build := range builds {
    
	repoUrl:=build.BuildFormData.RepoUrl
	if strings.Contains(repoUrl,"https://"){
    
		repoUrl=strings.ReplaceAll(build.BuildFormData.RepoUrl,"https://","")
	}
	if strings.Contains(repoUrl,"http://"){
    
		repoUrl=strings.ReplaceAll(build.BuildFormData.RepoUrl,"http://","")
	}
	finalImageName:=repoUrl+"/"+build.BuildFormData.ImageName+":"+build.BuildFormData.ImageTag
	destination := build.Args[2]
	cacherepo := build.Args[6]
	destination=strings.Split(destination,"=")[0]+"="+finalImageName
	cacherepo=strings.Split(cacherepo,"=")[0]+"="+repoUrl+"/"+build.BuildFormData.ImageName
	*(&build.Args[2])=destination
	*(&build.Args[6])=cacherepo
	fmt.Println("build.Args:",build.Args)
}
原网站

版权声明
本文为[Learn programming notes]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051836328546.html