本文整理汇总了Golang中dna.StringArray.ForEach方法的典型用法代码示例。如果您正苦于以下问题:Golang StringArray.ForEach方法的具体用法?Golang StringArray.ForEach怎么用?Golang StringArray.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dna.StringArray
的用法示例。
在下文中一共展示了StringArray.ForEach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getStringifiedSongUrls
func getStringifiedSongUrls(urls dna.StringArray) dna.String {
var baseLink = dna.String("")
songUrls := []SongUrl{}
urls.ForEach(func(val dna.String, idx dna.Int) {
// dna.Log(val)
// Finding bitrate
switch {
case val.Match(`128kbps`) == true:
songUrl := getSongUrl(val, "128kbps")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
songUrls = append(songUrls, *songUrl)
case val.Match(`320kbps`) == true:
songUrl := getSongUrl(val, "320kbps")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
songUrls = append(songUrls, *songUrl)
case val.Match(`32kbps`) == true:
songUrl := getSongUrl(val, "32kbps")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
songUrls = append(songUrls, *songUrl)
case val.Match(`500kbps`) == true:
songUrl := getSongUrl(val, "500kbps")
songUrl.Link = baseLink + "m4a/file-name.m4a"
songUrls = append(songUrls, *songUrl)
case val.Match(`Lossless`) == true:
songUrl := getSongUrl(val, "Lossless")
songUrl.Link = baseLink + "flac/file-name.flac"
songUrls = append(songUrls, *songUrl)
}
})
// http://data.chiasenhac.com/downloads/1184/2/1183017-cfc5f7df/flac/file-name.flac
// replace the link 500kps and lossless with available link, apply for registered user only
// and reduce the link length
var ret = dna.StringArray{}
for _, songUrl := range songUrls {
var br dna.String
if songUrl.Bitrate == "Lossless" {
br = "1411"
} else {
br = songUrl.Bitrate.Replace("kbps", "")
}
t := `"(` + songUrl.Link + "," + songUrl.Type + "," + songUrl.Size.ToString() + "," + br + `)"`
ret.Push(t)
}
// dna.Log(`{` + ret.Join(",") + `}`)
return `{` + ret.Join(",") + `}`
}
示例2: getStringifiedVideoUrls
func getStringifiedVideoUrls(urls dna.StringArray) dna.String {
var baseLink = dna.String("")
videoUrls := []VideoUrl{}
urls.ForEach(func(val dna.String, idx dna.Int) {
// dna.Log(val)
// Finding bitrate
switch {
case val.Match(`MV 360p`) == true:
songUrl := getVideoUrl(val, "360p")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
videoUrls = append(videoUrls, *songUrl)
case val.Match(`MV 480p`) == true:
songUrl := getVideoUrl(val, "480p")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
videoUrls = append(videoUrls, *songUrl)
case val.Match(`MV 180p`) == true:
songUrl := getVideoUrl(val, "180p")
baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
videoUrls = append(videoUrls, *songUrl)
case val.Match(`HD 720p`) == true:
songUrl := getVideoUrl(val, "720p")
songUrl.Link = baseLink + "m4a/file-name.mp4"
videoUrls = append(videoUrls, *songUrl)
case val.Match(`HD 1080p`) == true:
songUrl := getVideoUrl(val, "1080p")
songUrl.Link = baseLink + "flac/file-name.mp4"
videoUrls = append(videoUrls, *songUrl)
}
})
var ret = dna.StringArray{}
for _, videoUrl := range videoUrls {
t := `"(` + videoUrl.Link + "," + videoUrl.Type + "," + videoUrl.Size.ToString() + "," + videoUrl.Resolution.Replace("p", "") + `)"`
ret.Push(t)
}
// dna.Log(`{` + ret.Join(",") + `}`)
return `{` + ret.Join(",") + `}`
}