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


Golang String.String方法代码示例

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


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

示例1: amGetErrIds

func amGetErrIds(inputFile dna.String, mode dna.Int) *dna.IntArray {
	var ret = dna.IntArray{}
	b, err := ioutil.ReadFile(inputFile.String())
	if err != nil {
		panic(err)
	}
	data := dna.String(string(b))
	lines := data.Split("\n")
	for _, line := range lines {
		switch mode {
		case 1:
			idArr := line.FindAllStringSubmatch(`([0-9]+) Post.+no such host`, 1)
			if len(idArr) > 0 {
				ret.Push(idArr[0][1].ToInt())
			}
			idArr = line.FindAllStringSubmatch(`Timeout.+at id :([0-9]+)`, 1)
			if len(idArr) > 0 {
				ret.Push(idArr[0][1].ToInt())
			}
		case 2:
			ret.Push(line.ToInt())
		}
	}
	if mode == 1 {
		err = ioutil.WriteFile(inputFile.String(), []byte{}, 0644)
		if err != nil {
			dna.Log("Cannot write to file1:", err.Error())
		}

	}
	ret = ret.Unique()
	return &ret
}
开发者ID:olragon,项目名称:dna,代码行数:33,代码来源:update_allmusic.go

示例2: IsValidTable

func IsValidTable(tblName dna.String, db *sqlpg.DB) dna.Bool {
	_, err := db.Exec("select * from " + tblName.String() + " limit 0")
	if err == nil {
		return true
	} else {
		return false
	}
}
开发者ID:olragon,项目名称:dna,代码行数:8,代码来源:func.go

示例3: DecodePath

// DecodePath decodes encoded string such as "MjAxMyUyRjExJTJGMDUlMkYwJTJGMiUyRjAyN2UzN2M4NDUwMWFlOTEwNGNkZjgyMDZjYWE4OTkzLm1wMyU3QzI="
// into its real path on server such as "/2013/11/05/0/2/027e37c84501ae9104cdf8206caa8993.mp3|2"
func DecodePath(encodedPath dna.String) dna.String {
	ret, err := base64.StdEncoding.DecodeString(encodedPath.String())
	if err == nil {
		escape, err := url.QueryUnescape(string(ret))
		if err == nil {
			return dna.String(escape)
		} else {
			return ""
		}
	} else {
		return ""
	}
}
开发者ID:olragon,项目名称:dna,代码行数:15,代码来源:decode_path.go

示例4: startVPN

func startVPN(vpnAppName, vpnAppUrl dna.String) chan *exec.Cmd {
	c := make(chan *exec.Cmd)
	dna.Log("Starting", vpnAppName)
	go func() {
		cmd := exec.Command(vpnAppUrl.String())
		c <- cmd
		err := cmd.Run()
		if err != nil {
			dna.Log(err.Error())
		}
	}()

	return c
}
开发者ID:olragon,项目名称:dna,代码行数:14,代码来源:update_lyricfind.go

示例5: getType

func getType(str dna.String) dna.String {
	switch {
	case str.Match(`(?mis)MP3`) == true:
		return "mp3"
	case str.Match(`(?mis)M4A`) == true:
		return "m4a"
	case str.Match(`(?mis)MP4`) == true:
		return "mp4"
	case str.Match(`(?mis)FLAC`) == true:
		return "flac"
	case str.Match(`(?mis)FLV`) == true:
		return "flv"
	default:
		dna.Log("No type found at: " + str.String())
		return ""
	}
}
开发者ID:olragon,项目名称:dna,代码行数:17,代码来源:link_formats.go

示例6: Post

func Post(url dna.String, bodyStr dna.String) (*Result, error) {
	client := &http.Client{}
	// dna.Log(bodyStr)
	req, err := http.NewRequest("POST", url.String(), strings.NewReader(bodyStr.String()))
	req.Header = DefaulHeader
	req.Header.Add("Host", url.ToPrimitiveValue())
	res, err := client.Do(req)
	if err != nil {
		return new(Result), err
	}

	var data []byte
	var myErr error

	switch res.Header.Get("Content-Encoding") {
	case "gzip":
		var reader io.ReadCloser
		reader, err := gzip.NewReader(res.Body)
		if err != nil {
			return new(Result), err
		}
		data, myErr = ioutil.ReadAll(reader)
		reader.Close()
	case "deflate":
		// Logv("sdsafsd")
		reader, err := zlib.NewReader(res.Body)
		if err != nil {
			return new(Result), err
		}
		data, myErr = ioutil.ReadAll(reader)
		reader.Close()
	default:
		data, myErr = ioutil.ReadAll(res.Body)
	}

	if myErr != nil {
		return new(Result), myErr
	}

	res.Body.Close()
	return NewResult(dna.Int(res.StatusCode), dna.String(res.Status), res.Header, dna.String(data)), nil
}
开发者ID:olragon,项目名称:dna,代码行数:42,代码来源:http.go

示例7: ForeachLine

// ForeachLine loops through every line a file.
// An anynomous input function has line, index as params
func ForeachLine(filePath dna.String, lineFunc func(dna.String, dna.Int)) {

	var err error
	var line []byte
	f, err := os.Open(filePath.String())
	if err != nil {
		dna.Log("error opening file: %v\n", err)
		os.Exit(1)
	}
	defer f.Close()
	r := bufio.NewReaderSize(f, 4*1024)

	i := 0
	err = nil
	for err == nil {
		i += 1
		line, _, err = r.ReadLine()
		lineFunc(dna.String(string(line)), dna.Int(i))
	}
}
开发者ID:olragon,项目名称:dna,代码行数:22,代码来源:func.go

示例8: DecryptLRC

//DecryptLRC returns LRC string from encrypted string.
//
//For example: Given a song id 2882720 with a key 9Fd4zVvPMIbf
//and an XML source file http://www.nhaccuatui.com/flash/xml?key1=8bfe9db992afaff5dc931dffca1b5c7b
//
//The encrypted lyric file url lies in <lyric> tags
// http://lrc.nct.nixcdn.com/2013/12/29/0/a/5/b/1388320374102.lrc
func DecryptLRC(data dna.String) (dna.String, error) {
	// CODE_SPECIAL "M z s 2 d k v t u 5 o d u" separated by space
	keyStr := irrcrpt(dna.Sprintf("%s", []byte{0x4d, 0x7a, 0x73, 0x32, 0x64, 0x6b, 0x76, 0x74, 0x75, 0x35, 0x6f, 0x64, 0x75}), 1)
	keyStrInHex := hex.EncodeToString(keyStr.ToBytes())

	keyStrInBytes, err := hex.DecodeString(keyStrInHex)
	if err != nil {
		return "", err
	}
	ret, err := hex.DecodeString(data.String())
	if err != nil {
		return "", err
	}
	cipher, err := rc4.NewCipher(keyStrInBytes)
	if err != nil {
		return "", err
	} else {
		cipher.XORKeyStream(ret, ret)
		return dna.String(string(ret)), nil
	}
}
开发者ID:olragon,项目名称:dna,代码行数:28,代码来源:decrypt_lrc.go

示例9: RecoverSQLLogError

// RecoverSQLLogError re-executes failed sql queries in sql error log file from specified path.
// It returns the number of failed -reexec queries, and new failed
// queries will be written to the file
//
// The format of error file is:
// 	Error description - $$$error$$$SQL_QUERY$$$error$$$
// Therefore only get statements enclosed by special `$$$error$$$`
func RecoverSQLLogError(sqlErrFilePath dna.String, db *sqlpg.DB) dna.Int {
	var errCount = 0
	var errStrings = dna.StringArray{}
	b, err := ioutil.ReadFile(sqlErrFilePath.String())
	if err != nil {
		panic(err)
	}
	data := dna.String(string(b))
	// dna.Log("\n", data.Length())
	sqlArr := data.FindAllString(`(?mis)\$\$\$error\$\$\$.+?\$\$\$error\$\$\$`, -1)
	// dna.Log("\nTOTAL SQL STATEMENTS FOUND:", sqlArr.Length())
	for _, val := range sqlArr {
		sqlStmtArr := val.FindAllStringSubmatch(`(?mis)\$\$\$error\$\$\$(.+?)\$\$\$error\$\$\$`, -1)
		if len(sqlStmtArr) > 0 {
			_, err := db.Exec(sqlStmtArr[0][1].String())
			if err != nil {
				if dna.String(err.Error()).Contains(`duplicate key value violates unique constraint`) == false {
					errCount += 1
					errStrings.Push("$$$error$$$" + sqlStmtArr[0][1] + "$$$error$$$")
				}
			}
		}
	}
	if errCount == 0 {
		err = ioutil.WriteFile(sqlErrFilePath.String(), []byte{}, 0644)
	} else {
		err = ioutil.WriteFile(sqlErrFilePath.String(), []byte(errStrings.Join("\n").String()), 0644)
	}
	if err != nil {
		panic(err)
	}
	return dna.Int(errCount)
}
开发者ID:olragon,项目名称:dna,代码行数:40,代码来源:sqlrecover.go

示例10: Save

func (users *Users) Save(db *sqlpg.DB) error {
	var queries dna.String = ""
	// var err error
	// for _, user := range users.List {
	// 	if user.IsValid() == true {
	// 		err = db.InsertIgnore(user)
	// 	}
	// }
	// return err

	for _, user := range users.List {
		if user.IsValid() == true {
			queries += sqlpg.GetInsertStatement("ziusers", user, false) + "\n"
		}
	}
	mutex.Lock()
	n, err := SongFile.WriteString(queries.String())
	if err != nil {
		dna.Log("Cannot write to file while getting song", err.Error(), "\n\n")
	}
	TotalBytes += dna.Int(n)
	mutex.Unlock()
	return nil
}
开发者ID:olragon,项目名称:dna,代码行数:24,代码来源:user.go

示例11: ToSiteid

// ToSiteid returns a siteid id from a short form.
// For example: "ns" is for NhacSo
func ToSiteid(shortForm dna.String) dna.Int {
	switch shortForm {
	case "ns":
		return NhacSo
	case "zi":
		return Zing
	case "nct":
		return NhacCuaTui
	case "cc":
		return ChaCha
	case "nv":
		return NhacVui
	case "csn":
		return ChiaSeNhac
	case "hdv":
		return HDViet
	case "ke":
		return Keeng
	case "sf":
		return SongFreaks
	case "am":
		return AllMusic
	case "lw":
		return LyricWiki
	case "ml":
		return MetroLyrics
	case "lf":
		return LyricFind
	case "vg":
		return VietGiaiTri
	case "mv":
		return MusicVNN
	default:
		panic("Cannot convert shortform to siteid - GOT:" + shortForm.String())
	}
}
开发者ID:olragon,项目名称:dna,代码行数:38,代码来源:constants.go

示例12: QueryRow

func (db *DB) QueryRow(query dna.String, args ...interface{}) *Row {
	row := db.DB.QueryRow(query.String(), args...)
	return &Row{row}
}
开发者ID:olragon,项目名称:dna,代码行数:4,代码来源:db.go

示例13: Query

// QueryRecords is a reimplementation of sql.Db.Query().
// But it returns *Rows not *sql.Rows and error and takes query param as dna.String type
func (db *DB) Query(query dna.String, args ...interface{}) (*Rows, error) {
	rows, err := db.DB.Query(query.String(), args...)
	return &Rows{rows}, err
}
开发者ID:olragon,项目名称:dna,代码行数:6,代码来源:db.go

示例14: EncodePath

// EncodePath encodes "/2013/11/05/0/2/027e37c84501ae9104cdf8206caa8993.mp3|2"
// to base64 string.
func EncodePath(path dna.String) dna.String {
	escape := url.QueryEscape(path.String())
	return dna.String(base64.StdEncoding.EncodeToString([]byte(escape)))
}
开发者ID:olragon,项目名称:dna,代码行数:6,代码来源:decode_path.go

示例15: getMD5

func getMD5(s dna.String) dna.String {
	h := md5.New()
	io.WriteString(h, s.String())
	return dna.Sprintf("%x", h.Sum(nil))
}
开发者ID:olragon,项目名称:dna,代码行数:5,代码来源:url_builder.go


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