• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang dna.Sprintf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中dna.Sprintf函数的典型用法代码示例。如果您正苦于以下问题:Golang Sprintf函数的具体用法?Golang Sprintf怎么用?Golang Sprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Sprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetAlbum

// GetAlbum returns a pointer to Album
//
// Notice: Once getting special albums' titles such as "Bảng Xếp Hạng Bài Hát Hàn Quốc ...",
// the albums will be discarded because album.Nsongs and album.Songids.Length() do not match.
func GetAlbum(id dna.Int) (*Album, error) {
	var album *Album = NewAlbum()
	album.Id = id
	album.Key = GetKey(id)
	c := make(chan bool, 2)

	go func() {
		c <- <-getAlbumFromMainPage(album)
	}()
	go func() {
		c <- <-getAlbumFromAPI(album)
	}()

	for i := 0; i < 2; i++ {
		<-c
	}

	if album.Nsongs != album.Songids.Length() {
		return nil, errors.New(dna.Sprintf("Zing - Album %v: Songids and Nsongs do not match", album.Id).String())
	} else if album.Nsongs == 0 && album.Songids.Length() == 0 {
		return nil, errors.New(dna.Sprintf("Zing - Album %v: No song found", album.Id).String())
	} else {
		album.Checktime = time.Now()
		return album, nil
	}
}
开发者ID:olragon,项目名称:dna,代码行数:30,代码来源:album.go


示例2: GetVideo

// GetVideo returns a video or an error
//
// Direct link:
// 	curl 'http://hcm.nhac.vui.vn/ajax/nghe_bai_hat/download_320k/472092' -H 'Cookie: pageCookie=13; ACCOUNT_ID=965257; token=3f363de2c081a3a3a685b1033e6f03b1%7C52ab4c37;' -v
func GetVideo(id dna.Int) (*Video, error) {
	var video *Video = NewVideo()
	video.Id = id
	c := make(chan bool, 2)

	go func() {
		c <- <-getVideoXML(video)
	}()
	go func() {
		c <- <-getVideoFromMainPage(video)
	}()

	for i := 0; i < 2; i++ {
		<-c
	}

	// Check how many bits in ResolutionFlags have value 1
	var count uint32 = 0
	for i := uint32(0); i < 5; i++ {
		if (int(video.ResolutionFlags)>>i)&1 == 1 {
			count += 1
		}
	}

	if video.Links.Length() == 0 {
		return nil, errors.New(dna.Sprintf("Chacha - Video %v: Link not found", video.Id).String())
	} else if dna.Int(count) != video.Links.Length() {
		return nil, errors.New(dna.Sprintf("Chacha - Video %v: Video Resolution flags and links do not match", video.Id).String())
	} else {
		video.Checktime = time.Now()
		return video, nil
	}
}
开发者ID:olragon,项目名称:dna,代码行数:37,代码来源:video.go


示例3: CSVRecord

func (song *Song) CSVRecord() []string {
	return []string{
		song.Id.ToString().String(),
		song.Key.String(),
		song.Title.String(),
		dna.Sprintf("%#v", song.Artists).Replace("dna.StringArray", "").String(),
		dna.Sprintf("%#v", song.Topics).Replace("dna.StringArray", "").String(),
		song.LinkKey.String(),
		song.Type.String(),
		song.Bitrate.ToString().String(),
		song.Official.String(),
		song.Likes.ToString().String(),
		song.Plays.ToString().String(),
		song.LinkShare.String(),
		song.StreamUrl.String(),
		song.Image.String(),
		song.Coverart.String(),
		song.Duration.ToString().String(),
		song.Linkdown.String(),
		song.LinkdownHQ.String(),
		song.Lyricid.ToString().String(),
		song.HasLyric.String(),
		song.Lyric.String(),
		song.LyricStatus.ToString().String(),
		song.HasLrc.String(),
		song.Lrc.String(),
		song.LrcUrl.String(),
		song.UsernameCreated.String(),
		song.Checktime.Format("2006-01-02 15:04:05"),
	}
}
开发者ID:olragon,项目名称:dna,代码行数:31,代码来源:song.go


示例4: GetEpisole

// GetEpisole returns an episole URL of a series.
func (urlb *URLBuilder) GetEpisole(movieid, ep dna.Int) dna.String {
	str := dna.Sprintf("movieid=%v&accesstokenkey=%v&ep=%v", movieid, ACCESS_TOKEN_KEY, ep)
	data := []byte(str.String())
	strBase64 := base64.StdEncoding.EncodeToString(data)
	sign := getMD5(dna.String(strBase64) + SECRET_KEY)
	return dna.Sprintf("%vmovieid=%v&accesstokenkey=%v&ep=%v&sign=%v", BASE_URL, movieid, ACCESS_TOKEN_KEY, ep, sign)
}
开发者ID:olragon,项目名称:dna,代码行数:8,代码来源:url_builder.go


示例5: GetChannel

// GetChannel returns TV channel URL.
func (urlb *URLBuilder) GetChannel(channelid dna.Int) dna.String {
	str := dna.Sprintf("channelid=%v&accesstokenkey=%v", channelid, ACCESS_TOKEN_KEY)
	data := []byte(str.String())
	strBase64 := base64.StdEncoding.EncodeToString(data)
	sign := getMD5(dna.String(strBase64) + SECRET_KEY)
	return dna.Sprintf("%vchannelid=%v&accesstokenkey=%v&sign=%v", CHANNEL_BASE_URL, channelid, ACCESS_TOKEN_KEY, sign)
}
开发者ID:olragon,项目名称:dna,代码行数:8,代码来源:url_builder.go


示例6: Show

func (hg *HourGlass) Show(message dna.String) {
	hg.lastLapDuration += hg.lap()
	if hg.lastLapDuration >= time.Second/2 {
		fmtClock := dna.Sprintf("%v", hg.GetRemainingTime()/time.Millisecond*time.Millisecond)
		format := dna.Sprintf("%v %v", message, fmtClock)
		hg.console.Erase(Line).Column(0)
		hg.console.Write(format)
		hg.lastLapDuration = 0
	}
}
开发者ID:olragon,项目名称:dna,代码行数:10,代码来源:hourglass.go


示例7: Show

// Show displays a message if lap is greater than 500 milliseconds
func (sw *StopWatch) Show(message dna.String) {
	sw.lastLapDuration += sw.Lap()
	if sw.lastLapDuration >= time.Second/2 {
		fmtClock := dna.Sprintf("%v", sw.Tick()/time.Millisecond*time.Millisecond)
		format := dna.Sprintf("%v %v", message, fmtClock)
		sw.console.Erase(Line).Column(0)
		sw.console.Write(format).HideCursor()
		sw.lastLapDuration = 0
	}

}
开发者ID:olragon,项目名称:dna,代码行数:12,代码来源:stopwatch.go


示例8: String

func (c Counter) String() string {
	c.mu.RLock()
	if c.Total > 0 {
		format := dna.String("%v✘ | %v✔")
		return string(dna.Sprintf(format, c.Fail, c.Pass))
	} else {
		format := dna.String("t:%v|n:%v|f:%v✘|p:%v✔|v:%v")
		return string(dna.Sprintf(format, getTimeFmt(c.ElapsedTime), c.Count, c.Fail, c.Pass, c.Speed))
	}
	c.mu.RUnlock()
	return ""
}
开发者ID:olragon,项目名称:dna,代码行数:12,代码来源:counter.go


示例9: CSVRecord

//CSVRecord returns a record to write csv format.
//
//psql -c "COPY sfartists (id,amg,name,genres,url_slug,image,rating,bio,checktime) FROM '/Users/daonguyenanbinh/Box Documents/Sites/golang/sfartists.csv' DELIMITER ',' CSV"
func (artist *Artist) CSVRecord() []string {
	return []string{
		artist.Id.ToString().String(),
		artist.AMG.ToString().String(),
		artist.Name.String(),
		dna.Sprintf("%#v", artist.Genres).Replace("dna.StringArray", "").String(),
		artist.UrlSlug.String(),
		artist.Image.String(),
		dna.Sprintf("%#v", artist.Rating).Replace("dna.IntArray", "").String(),
		artist.Bio.String(),
		artist.Checktime.Format("2006-01-02 15:04:05"),
	}
}
开发者ID:olragon,项目名称:dna,代码行数:16,代码来源:artist.go


示例10: CSVRecord

func (award *Award) CSVRecord() []string {
	return []string{
		award.Id.ToString().String(),
		award.Title.String(),
		award.Albumid.ToString().String(),
		award.Section.String(),
		award.Year.ToString().String(),
		award.Chart.String(),
		award.Peak.ToString().String(),
		award.Type.ToString().String(),
		award.Prize.String(),
		dna.Sprintf("%#v", award.Winnerids).Replace("dna.IntArray", "").String(),
		dna.Sprintf("%#v", award.Winners).Replace("dna.StringArray", "").String(),
	}
}
开发者ID:olragon,项目名称:dna,代码行数:15,代码来源:award.go


示例11: getSongPlays

// getSongPlays returns song plays
func getSongPlays(song *Song, body dna.String) {
	// POST METHOD
	// link := "http://www.nhaccuatui.com/interaction/api/hit-counter?jsoncallback=nct"
	// http.DefaulHeader.Set("Content-Type", "application/x-www-form-urlencoded ")
	// result, err := http.Post(dna.String(link), body)
	// // Log(link)
	// if err == nil {
	// 	data := &result.Data
	// 	tpl := dna.String(`{"counter":([0-9]+)}`)
	// 	playsArr := data.FindAllStringSubmatch(tpl, -1)
	// 	if len(playsArr) > 0 {
	// 		song.Plays = playsArr[0][1].ToInt()
	// 	}
	// }
	// GET METHOD
	link := "http://www.nhaccuatui.com/interaction/api/counter?jsoncallback=nct&listSongIds=" + song.Id.ToString()
	result, err := http.Get(link)
	if err == nil {
		data := &result.Data
		tpl := dna.Sprintf(`{"%v":([0-9]+)}`, song.Id)
		// dna.Log(data)
		playsArr := data.FindAllStringSubmatch(tpl, -1)
		if len(playsArr) > 0 {
			song.Plays = playsArr[0][1].ToInt()
		}
	}
}
开发者ID:olragon,项目名称:dna,代码行数:28,代码来源:song.go


示例12: GetSong

// GetSong returns a song or an error
//
// Direct link:
// 	curl 'http://hcm.nhac.vui.vn/ajax/nghe_bai_hat/download_320k/472092' -H 'Cookie: pageCookie=13; ACCOUNT_ID=965257; token=3f363de2c081a3a3a685b1033e6f03b1%7C52ab4c37;' -v
func GetSong(id dna.Int) (*Song, error) {
	var song *Song = NewSong()
	song.Id = id
	c := make(chan bool, 2)

	go func() {
		c <- <-getSongXML(song)
	}()
	go func() {
		c <- <-getSongFromMainPage(song)
	}()

	for i := 0; i < 2; i++ {
		<-c
	}
	if song.Type == "video" {
		song.Link = ""
		FoundVideos.Push(song.Id)
	}
	if song.Link == "" {
		return nil, errors.New(dna.Sprintf("Nhacvui - Song %v: Mp3 link not found", song.Id).String())
	} else {
		song.Checktime = time.Now()
		return song, nil
	}
}
开发者ID:olragon,项目名称:dna,代码行数:30,代码来源:song.go


示例13: UpdateSongFreaks

// UpdateSongFreaks gets lastest songs,albums,artists and videos from songfreaks.com
// The update process goes through 4 steps:
// 	Step 1: Initalizing db connection, loading site config and state handler.
// 	Step 2: Finding new songs, insert new albums,artists and videos if found.
// 	Step 3: Updating found new albums in Step 2.
// 	Step 4: Recovering failed sql statements in Step 2.
func UpdateSongFreaks() {
	db, err := sqlpg.Connect(sqlpg.NewSQLConfig(SqlConfigPath))
	dna.PanicError(err)
	siteConf, err := LoadSiteConfig("sf", SiteConfigPath)
	siteConf.NConcurrent = 20
	dna.PanicError(err)

	// Update new songs
	state := NewStateHandler(new(sf.APISongFreaksTrack), siteConf, db)
	state.TableName = "sfsongs"
	Update(state)

	// Update "ratings", "songids", "review_author", "review" of song
	ids := &[]dna.Int{}
	query := dna.Sprintf("SELECT id FROM sfalbums where checktime > '%v' AND array_length(songids, 1) is NULL", time.Now().Format("2006-01-02"))
	// dna.Log(query)
	err = db.Select(ids, query)
	if err != nil {
		dna.PanicError(err)
	}
	idsSlice := dna.IntArray(*ids)
	if idsSlice.Length() > 0 {
		state = NewStateHandlerWithExtSlice(new(sf.APISongFreaksAlbum), &idsSlice, siteConf, db)
		Update(state)

	} else {
		dna.Log("No new albums found")
	}

	// Recover failed sql statements
	RecoverErrorQueries(SqlErrorLogPath, db)

	CountDown(3*time.Second, QuittingMessage, EndingMessage)
	db.Close()
}
开发者ID:olragon,项目名称:dna,代码行数:41,代码来源:update_songfreaks.go


示例14: Update

// Update updates statement from GetUpdateStatment and returns error if available
//
// 	* structValue : A struct-typed value being scanned. Its fields have to be dna basic type or time.Time.
// 	* conditionColumn : A snake-case column name in the condition, usually it's an id
// 	* columns : A list of args of column names in the table being updated.
// 	* Returns an update statement.
// The error format is:
// 	Error description - $$$error$$$SQL_QUERY$$$error$$$
// Sql query is enclosed by `$$$error$$$`
func (db *DB) Update(structValue interface{}, conditionColumn dna.String, columns ...dna.String) error {
	tbName := GetTableName(structValue)
	updateQuery, err0 := GetUpdateStatement(tbName, structValue, conditionColumn, columns...)
	if err0 != nil {
		str := dna.Sprintf("%s - $$$error$$$%v$$$error$$$", err0.Error(), updateQuery).String()
		return errors.New(str)
	} else {
		_, err := db.Exec(updateQuery.String())
		if err != nil {
			str := dna.Sprintf("%s - $$$error$$$%v$$$error$$$", err.Error(), updateQuery).String()
			return errors.New(str)
		} else {
			return nil
		}
	}
}
开发者ID:olragon,项目名称:dna,代码行数:25,代码来源:db.go


示例15: GetAPIAlbum

// GetAPIAlbum returns an album or an error from API using POST method.
//
// The SOAP data has the following format:
//
// 	<?xml version="1.0" encoding="utf-8"?>
// 	<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
// 	  <soap:Header/>
// 	  <soap:Body>
// 	    <tem:getAlbum_v2 xmlns=" http://tempuri.org/ ">
// 	      <tem:token></tem:token>
// 	      <tem:id>86682</tem:id>
// 	      <tem:identify></tem:identify>
// 	    </tem:getAlbum_v2>
// 	  </soap:Body>
// 	</soap:Envelope>
func GetAPIAlbum(id dna.Int) (*APIAlbum, error) {
	if id == 0 {
		return nil, errors.New("Id is zero")
	}
	var dat dna.String = dna.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soap:Header/><soap:Body>
<tem:getAlbum_v2 xmlns=" http://tempuri.org/ "><tem:token></tem:token><tem:id>%v</tem:id><tem:identify></tem:identify></tem:getAlbum_v2></soap:Body>
</soap:Envelope>`, id)
	header := Header
	header.Set("SOAPAction", "http://tempuri.org/getAlbum_v2")
	ret, err := Post("http://service.keeng.vn/appwebservice/Service.asmx?wsdl", header, dat)
	if err != nil {
		return nil, err
	} else {
		var apiStatusAlbum APIStatusAlbum
		dataArr := ret.Data.FindAllStringSubmatch(`<return>(.+)</return>`, -1)
		if len(dataArr) > 0 {
			// dna.Log(data)
			err := json.Unmarshal([]byte(dataArr[0][1].DecodeHTML()), &apiStatusAlbum)
			if err != nil {
				return nil, err
			} else {
				return &apiStatusAlbum.Data, nil
			}
		} else {
			return nil, errors.New("No return value")
		}

	}
}
开发者ID:olragon,项目名称:dna,代码行数:45,代码来源:post.go


示例16: GetAPIArtistVideos

// GetAPIArtistVideos returns a list of albums of an artist or an error from API using POST method.
//
// The SOAP data has the following format:
//
// 	<?xml version="1.0" encoding="utf-8"?>
// 	<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
// 	  <soap:Header/>
// 	  <soap:Body>
// 	    <tem:getSinger_Detail_moi xmlns=" http://tempuri.org/ ">
// 	      <tem:token></tem:token>
// 	      <tem:singerid>1394</tem:singerid>
// 	      <tem:page>1</tem:page>
// 	      <tem:num>10</tem:num>
// 	      <tem:type>3</tem:type>
// 	    </tem:getSinger_Detail_moi>
// 	  </soap:Body>
// 	</soap:Envelope>
//
// The params:
//
// 	*singerid : an artist id
// 	*type : 3
// 	*page : current page for pagination
// 	*num : the number of items per page
// 	*token : empty
func GetAPIArtistVideos(id, page, num dna.Int) (*APIArtistVideos, error) {
	if id == 0 {
		return nil, errors.New("Id is zero")
	}
	var dat dna.String = dna.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soap:Header/><soap:Body>
<tem:getSinger_Detail_moi xmlns=" http://tempuri.org/ "><tem:token></tem:token><tem:singerid>%v</tem:singerid><tem:page>%v</tem:page><tem:num>%v</tem:num><tem:type>3</tem:type></tem:getSinger_Detail_moi></soap:Body>
</soap:Envelope>`, id, page, num)
	header := Header
	header.Set("SOAPAction", "http://tempuri.org/getSinger_Detail_moi")
	ret, err := Post("http://service.keeng.vn/appwebservice/Service.asmx?wsdl", header, dat)
	if err != nil {
		return nil, err
	} else {
		var apiArtistVideos APIArtistVideos
		data := ret.Data.FindAllStringSubmatch(`<return>(.+)</return>`, -1)[0][1].DecodeHTML()
		// dna.Log(data)
		err := json.Unmarshal([]byte(data), &apiArtistVideos)
		if err != nil {
			return nil, err
		} else {
			return &apiArtistVideos, nil
		}
	}
}
开发者ID:olragon,项目名称:dna,代码行数:50,代码来源:post.go


示例17: GetAPILyric

// GetAPILyric returns a lyric or an error from API using POST method.
//
// The SOAP data has the following format:
//
// 	<?xml version="1.0" encoding="utf-8"?>
// 	<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
// 	  <soap:Header/>
// 	  <soap:Body>
// 	    <tem:getLyric xmlns=" http://tempuri.org/ ">
// 	      <tem:token></tem:token>
// 	      <tem:id>1944090</tem:id>
// 	    </tem:getLyric>
// 	  </soap:Body>
// 	</soap:Envelope>
func GetAPILyric(id dna.Int) (*APILyric, error) {
	if id == 0 {
		return nil, errors.New("Id is zero")
	}
	var dat dna.String = dna.Sprintf(`<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soap:Header/><soap:Body>
<tem:getLyric xmlns=" http://tempuri.org/ "><tem:token></tem:token><tem:id>%v</tem:id></tem:getLyric></soap:Body>
</soap:Envelope>`, id)
	header := Header
	header.Set("SOAPAction", "http://tempuri.org/getLyric")
	ret, err := Post("http://service.keeng.vn/appwebservice/Service.asmx?wsdl", header, dat)
	if err != nil {
		return nil, err
	} else {
		var lyric APILyric
		data := ret.Data.FindAllStringSubmatch(`<return>(.+)</return>`, -1)[0][1].DecodeHTML()
		err := json.Unmarshal([]byte(data), &lyric)
		if err != nil {
			return nil, err
		} else {
			lyric.Data = lyric.Data.DecodeHTML()
			return &lyric, nil
		}
	}
}
开发者ID:olragon,项目名称:dna,代码行数:39,代码来源:post.go


示例18: GetMovie

// GetMovie returns a movie or an error.
func GetMovie(id dna.Int) (*Movie, error) {
	var movie *Movie = NewMovie()
	movie.Id = id
	c := make(chan bool, 1)

	go func() {
		c <- <-getMovieFromPage(movie)
	}()

	for i := 0; i < 1; i++ {
		<-c
	}

	if movie.Title == "" && movie.AnotherTitle == "" {
		return nil, errors.New(dna.Sprintf("Hdviet - Movie %v: Not available", movie.Id).String())
	} else {
		// Generating EpisodeKeyList
		if movie.IsSeries == false {
			EpisodeKeyList.Push(movie.Id * 1000)
		} else {
			for i := dna.Int(1); i <= movie.CurrentEps; i++ {
				EpisodeKeyList.Push(ToEpisodeKey(movie.Id, i))
			}
		}
		return movie, nil
	}

	// if movie.Link == "" || movie.Link == "/" {
	// 	return nil, errors.New(fmt.Sprintf("Nhacso - Movie %v: Mp3 link not found", movie.Id))
	// } else {
	// 	movie.Checktime = time.Now()
	// 	return movie, nil
	// }
}
开发者ID:olragon,项目名称:dna,代码行数:35,代码来源:movie.go


示例19: Save

func (episode *Episode) Save(db *sqlpg.DB) error {
	insertStmt := getInsertStmt(episode, dna.Sprintf("WHERE NOT EXISTS (SELECT 1 FROM %v WHERE movie_id=%v and ep_id=%v)", getTableName(episode), episode.MovieId, episode.EpId))
	_, err := db.Exec(insertStmt.String())
	if err != nil {
		err = errors.New(err.Error() + " $$$error$$$" + insertStmt.String() + "$$$error$$$")
	}
	return err
}
开发者ID:olragon,项目名称:dna,代码行数:8,代码来源:episode.go


示例20: Save

func (movie *Movie) Save(db *sqlpg.DB) error {
	insertStmt := getInsertStmt(movie, dna.Sprintf("WHERE NOT EXISTS (SELECT 1 FROM %v WHERE id=%v)", getTableName(movie), movie.Id))
	_, err := db.Exec(insertStmt.String())
	if err != nil {
		err = errors.New(err.Error() + " $$$error$$$" + insertStmt.String() + "$$$error$$$")
	}
	return err
}
开发者ID:olragon,项目名称:dna,代码行数:8,代码来源:movie.go



注:本文中的dna.Sprintf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dna.String函数代码示例发布时间:2022-05-24
下一篇:
Golang dna.Log函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap