当前位置: 首页>>代码示例>>Golang>>正文


Golang dna.Sprintf函数代码示例

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


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


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