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


Golang strings.TrimRight函数代码示例

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


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

示例1: ExecBin

func (w *Worker) ExecBin(binPath string, args []string, maxRunTime int64) (string, error) {
	var cmd *exec.Cmd
	var stdout bytes.Buffer
	var stderr bytes.Buffer
	var err error

	if len(args) == 0 {
		cmd = exec.Command(binPath)
	} else {
		cmd = exec.Command(binPath, args...)
	}

	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	cmd.Start() // attention!

	err, _ = w.CmdRunWithTimeout(cmd,
		time.Duration(maxRunTime)*time.Second,
	)
	if err != nil {
		return "", err
	}
	if len(stderr.String()) != 0 {
		errMsg := strings.TrimRight(stderr.String(), "\n")
		return "", errors.NewError(errMsg)
	}

	return strings.TrimRight(stdout.String(), "\n"), nil
}
开发者ID:jameswei,项目名称:kingtask,代码行数:29,代码来源:worker.go

示例2: Fill

func (p *Post) Fill(url string) {
	doc, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatal(err)
	}

	//   doc.Find(".blog-post").Each(func(i int, s *goquery.Selection) {
	//     band := s.Find("h3").Text()
	//     title := s.Find("i").Text()
	//     fmt.Printf("Review %d: %s - %s\n", i, band, title)
	//   })

	title := doc.Find(".blog-post").Find(".blog-post-title").Text()
	date := doc.Find(".blog-post").Find(".blog-post-meta").Text()
	text, _ := doc.Find(".blog-post").Find("span").Html()
	slug := strings.TrimLeft(url, "http://speedyspin.ru/")

	p.Body = text
	p.Shortmessage = text
	p.Slug = slug
	p.Status = 1
	p.Title = title

	p.Created, _ = fmtdate.Parse("DD.MM.YYYY", strings.TrimRight(date, " автор Виталий"))
	p.Modified, _ = fmtdate.Parse("DD.MM.YYYY", strings.TrimRight(date, " автор Виталий"))
}
开发者ID:xenamorph,项目名称:quick,代码行数:26,代码来源:sp.go

示例3: GetDeviceSizeInBytes

func (p partedPartitioner) GetDeviceSizeInBytes(devicePath string) (uint64, error) {
	p.logger.Debug(p.logTag, "Getting size of disk remaining after first partition")

	stdout, _, _, err := p.cmdRunner.RunCommand("parted", "-m", devicePath, "unit", "B", "print")
	if err != nil {
		return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
	}

	allLines := strings.Split(stdout, "\n")
	if len(allLines) < 3 {
		return 0, bosherr.Errorf("Getting remaining size of `%s'", devicePath)
	}

	partitionInfoLines := allLines[1:3]
	deviceInfo := strings.Split(partitionInfoLines[0], ":")
	deviceFullSizeInBytes, err := strconv.ParseUint(strings.TrimRight(deviceInfo[1], "B"), 10, 64)
	if err != nil {
		return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
	}

	firstPartitionInfo := strings.Split(partitionInfoLines[1], ":")
	firstPartitionEndInBytes, err := strconv.ParseUint(strings.TrimRight(firstPartitionInfo[2], "B"), 10, 64)
	if err != nil {
		return 0, bosherr.WrapErrorf(err, "Getting remaining size of `%s'", devicePath)
	}

	remainingSizeInBytes := deviceFullSizeInBytes - firstPartitionEndInBytes - 1

	return remainingSizeInBytes, nil
}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:30,代码来源:parted_partitioner.go

示例4: decodeTime

func decodeTime(r io.Reader, f reflect.Value) error {
	s, err := decodeStr(r)
	if err != nil {
		return err
	}
	var t time.Time
	if s != "" {
		// Samsung has trailing dots.
		s = strings.TrimRight(s, ".")

		// Jolla Sailfish has trailing "Z".
		s = strings.TrimRight(s, "Z")

		t, err = time.Parse(timeFormat, s)
		if err != nil {
			// Nokia lumia has numTZ
			t, err = time.Parse(timeFormatNumTZ, s)
			if err != nil {
				return err
			}
		}
	}
	f.Set(reflect.ValueOf(t))
	return nil
}
开发者ID:YoshikuniShiku,项目名称:go-mtpfs,代码行数:25,代码来源:encoding.go

示例5: processString

// processString is utilized by DecodeHDU to process string-type values in the header
// it uses a 3-state machine to process double single quotes
func processString(s string) (string, int, error) {
	var buf bytes.Buffer

	state := 0
	for i, char := range s {
		quote := (char == '\'')
		switch state {
		case 0:
			if !quote {
				return "", i, fmt.Errorf("fitsio: string does not start with a quote (%q)", s)
			}
			state = 1
		case 1:
			if quote {
				state = 2
			} else {
				buf.WriteRune(char)
				state = 1
			}
		case 2:
			if quote {
				buf.WriteRune(char)
				state = 1
			} else {
				return strings.TrimRight(buf.String(), " "), i, nil
			}
		}
	}
	if s[len(s)-1] == '\'' {
		return strings.TrimRight(buf.String(), " "), len(s), nil
	}
	return "", 0, fmt.Errorf("fitsio: string ends prematurely (%q)", s)
}
开发者ID:ramvasanth,项目名称:fitsio,代码行数:35,代码来源:utils.go

示例6: String

func (d *Decimal) String() (s string) {
	if len(d.a) == 0 {
		return "0"
	}
	if d.neg {
		s = "-"
	}
	value := d.a.string10()
	multiplier := len(d.b.string10())
	if multiplier == 1 {
		return s + value
	}
	valsize := len(value)
	diff := multiplier - valsize
	if diff > 0 {
		s += "0"
		rhs := ""
		for i := 0; i < diff-1; i++ {
			rhs += "0"
		}
		rhs = strings.TrimRight(rhs+value, "0")
		if len(rhs) > 0 {
			return s + "." + rhs
		}
		return "0"
	}
	diff = valsize - multiplier + 1
	rhs := strings.TrimRight(value[diff:], "0")
	if len(rhs) > 0 {
		return s + value[:diff] + "." + rhs
	}
	return s + value[:diff]
}
开发者ID:benlaurie,项目名称:ampify,代码行数:33,代码来源:decimal.go

示例7: TestRunCommandsEnvStdOutAndErrAndRC

func (s *RunCommandSuite) TestRunCommandsEnvStdOutAndErrAndRC(c *gc.C) {
	// TODO(bogdanteleaga): powershell throws another exit status code when
	// outputting to stderr using Write-Error. Either find another way to
	// output to stderr or change the checks
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: Have to figure out a good way to output to stderr from powershell")
	}
	ctx, err := s.contextFactory.HookContext(hook.Info{Kind: hooks.ConfigChanged})
	c.Assert(err, jc.ErrorIsNil)
	paths := runnertesting.NewRealPaths(c)
	runner := runner.NewRunner(ctx, paths)

	commands := `
echo $JUJU_CHARM_DIR
echo this is standard err >&2
exit 42
`
	result, err := runner.RunCommands(commands)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(result.Code, gc.Equals, 42)
	c.Assert(strings.TrimRight(string(result.Stdout), "\r\n"), gc.Equals, paths.GetCharmDir())
	c.Assert(strings.TrimRight(string(result.Stderr), "\r\n"), gc.Equals, "this is standard err")
	c.Assert(ctx.GetProcess(), gc.NotNil)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:25,代码来源:runner_test.go

示例8: createRegularModeData

func createRegularModeData(index int, offset int, infoType DockerInfoType, cont *goDocker.Container) (info string) {

	switch infoType {
	case ImageInfo:
		info = cont.Config.Image
	case Names:
		info = cont.Name
		if cont.Node != nil {
			info = cont.Node.Name + info
		}
	case PortInfo:
		info = createPortsString(cont.NetworkSettings.Ports, ",")
	case BindInfo:
		info = strings.TrimRight(strings.Join(cont.HostConfig.Binds, ","), ",")
	case CommandInfo:
		info = cont.Path + " " + strings.Join(cont.Args, " ")
	case EnvInfo:
		info = strings.TrimRight(strings.Join(cont.Config.Env, ","), ",")
	case EntrypointInfo:
		info = strings.Join(cont.Config.Entrypoint, " ")
	case VolumesInfo:
		volStr := ""
		for intVol, hostVol := range cont.Volumes {
			volStr += intVol + ":" + hostVol + ","
		}
		info = strings.TrimRight(volStr, ",")
	case TimeInfo:
		info = cont.State.StartedAt.Format(time.RubyDate)
	default:
		Error.Println("Unhandled info type", infoType)
	}
	return
}
开发者ID:byrnedo,项目名称:dockdash,代码行数:33,代码来源:view.go

示例9: repoKeys

// get repository keys from s3
func (remote *S3Remote) repoKeys(prefix string) (keys, error) {
	repoKeys := make(keys)

	prefix = strings.TrimLeft(strings.TrimRight(prefix, "/"), "/")
	keyPrefix := strings.TrimRight(remote.KeyPrefix, "/")

	bucketPrefix := keyPrefix + "/" + prefix
	remotePrefix := keyPrefix + "/"

	bucket := remote.getBucket()

	cnt, err := bucket.GetBucketContentsWithPrefix(bucketPrefix)
	if err != nil {
		return repoKeys, fmt.Errorf("getting bucket contents at prefix '%s': %s", prefix, err)
	}

	for _, key := range *cnt {
		if key.Key == "" {
			continue
		}

		plainKey := strings.TrimPrefix(key.Key, remotePrefix)

		if strings.HasSuffix(plainKey, ".sum") {
			plainKey = strings.TrimSuffix(plainKey, ".sum")
			repoKeys.Get(plainKey, remote).sumKey = key.Key

		} else {
			repoKeys.Get(plainKey, remote).s3Key = key
		}
	}

	return repoKeys, nil
}
开发者ID:wolfeidau,项目名称:dogestry,代码行数:35,代码来源:s3.go

示例10: readMetadata

// readMetadata reads and parses the metadata for the next entry in the archive.
func (ar *Archive) readMetadata() *Entry {
	buf := make([]byte, entryLen)
	_, err := io.ReadFull(ar.fd, buf)
	if err == io.EOF {
		// No entries left.
		return nil
	}
	if err != nil || buf[entryLen-2] != '`' || buf[entryLen-1] != '\n' {
		log.Fatal("file is not an archive: bad entry")
	}
	entry := new(Entry)
	entry.name = strings.TrimRight(string(buf[:16]), " ")
	if len(entry.name) == 0 {
		log.Fatal("file is not an archive: bad name")
	}
	buf = buf[16:]
	str := string(buf)
	get := func(width, base, bitsize int) int64 {
		v, err := strconv.ParseInt(strings.TrimRight(str[:width], " "), base, bitsize)
		if err != nil {
			log.Fatal("file is not an archive: bad number in entry: ", err)
		}
		str = str[width:]
		return v
	}
	// %-16s%-12d%-6d%-6d%-8o%-10d`
	entry.mtime = get(12, 10, 64)
	entry.uid = int(get(6, 10, 32))
	entry.gid = int(get(6, 10, 32))
	entry.mode = os.FileMode(get(8, 8, 32))
	entry.size = get(10, 10, 64)
	return entry
}
开发者ID:2thetop,项目名称:go,代码行数:34,代码来源:pack.go

示例11: generateInsertSql

//生成插入的SQL语句,和对应的参数
func generateInsertSql(model interface{}) (string, []interface{}, *TableInfo, error) {
	tbinfo, err := getTableInfo(model)
	if err != nil {
		return "", nil, nil, err
	}

	//如果结构体中没有字段,抛出异常
	if len(tbinfo.Fields) == 0 {
		return "", nil, nil, errors.New(tbinfo.Name + "结构体中没有字段")
	}
	strSql := "insert into " + tbinfo.Name
	strField := ""
	strValue := ""
	var param []interface{}
	for _, v := range tbinfo.Fields {
		if v.IsAutoGenerate { //跳过自动增长的自段
			continue
		}
		strField += v.Name + ","
		strValue += "?,"
		param = append(param, v.Value.Interface())
	}
	if strField == "" {
		return "", nil, nil, errors.New(tbinfo.Name + "结构体中没有字段,或只有自增自段")
	}
	strField = strings.TrimRight(strField, ",")
	strValue = strings.TrimRight(strValue, ",")
	strSql += " (" + strField + ") values(" + strValue + ")"
	return strSql, param, tbinfo, nil
}
开发者ID:peidachang,项目名称:SimpleDb,代码行数:31,代码来源:orm.go

示例12: String

// String returns the Value as a string for human consumption. Native values are
// represented as decimal XRP rather than drips.
func (v Value) String() string {
	if v.IsZero() {
		return "0"
	}
	if !v.IsNative() && v.isScientific() {
		value := strconv.FormatUint(v.num, 10)
		origLen := len(value)
		value = strings.TrimRight(value, "0")
		offset := strconv.FormatInt(v.offset+int64(origLen-len(value)), 10)
		if v.negative {
			return "-" + value + "e" + offset
		}
		return value + "e" + offset
	}
	rat := v.Rat()
	if v.IsNative() {
		rat.Quo(rat, big.NewRat(int64(xrpPrecision), 1))
	}
	left := rat.FloatString(0)
	if rat.IsInt() {
		return left
	}
	length := len(left)
	if v.negative {
		length -= 1
	}
	return strings.TrimRight(rat.FloatString(32-length), "0")
}
开发者ID:askk,项目名称:ripple,代码行数:30,代码来源:value.go

示例13: inWatch

func inWatch(event_path, fn string) bool {
	event_fn := event_path
	if strings.HasPrefix(event_path, "SUCCESS:") {
		event_fn = event_path[9:]
	} else if strings.HasPrefix(event_path, "FAIL:") {
		event_fn = event_path[6:]
	}
	if strings.HasSuffix(event_fn, "/") {
		event_fn = strings.TrimRight(event_fn, "/")
	}
	if strings.HasSuffix(fn, "/") {
		fn = strings.TrimRight(fn, "/")
	}
	if event_fn == fn {
		return true
	}
	dir, _ := filepath.Split(event_fn)
	if strings.HasSuffix(dir, "/") {
		dir = strings.TrimRight(dir, "/")
	}
	if fn == dir {
		return true
	}
	return false
}
开发者ID:qjpcpu,项目名称:watchman,代码行数:25,代码来源:watchman.go

示例14: PrintFor

func (p *CPrinter) PrintFor(init, cond, post string) {
	init = strings.TrimRight(init, SEMI)
	post = strings.TrimRight(post, SEMI)

	onlycond := len(init) == 0 && len(post) == 0

	if len(cond) == 0 {
		cond = "true"
	}

	if onlycond {
		// make it a while
		p.PrintLevel(NONE, "while (", cond)
	} else {
		p.PrintLevel(NONE, "for (")
		if len(init) > 0 {
			p.Print(init)
		}
		p.Print("; " + cond + ";")
		if len(post) > 0 {
			p.Print(" " + post)
		}

	}
	p.Print(") ")
}
开发者ID:raff,项目名称:walkngo,代码行数:26,代码来源:cprinter.go

示例15: getGoCompilerVersion

func getGoCompilerVersion() (uint, error) {
	if goCompilerVersion == nil {
		args := []string{goCompiler_exe.name, "-V"}
		stdout, _, err := goCompiler_exe.run(args /*dir*/, "" /*in*/, "" /*mergeStdoutAndStderr*/, true)
		if err != nil {
			return 0, errors.New("failed to determine Go compiler version: " + err.Error())
		}

		stdout = strings.TrimSpace(stdout)
		var stdout_split []string = strings.Split(stdout, " ")
		if len(stdout_split) < 3 {
			return 0, errors.New("failed to extract [Go compiler version] from string \"" + stdout + "\"" +
				" (possible cause: you didn't have the Mercurial versioning system installed when you were compiling the Go distribution)")
		}

		version, err := strconv.ParseUint(strings.TrimRight(stdout_split[2], "+"), 10, 0)
		if (err != nil) && (len(stdout_split) >= 4) {
			version, err = strconv.ParseUint(strings.TrimRight(stdout_split[3], "+"), 10, 0)
		}
		if err != nil {
			return 0, errors.New("failed to extract [Go compiler version] from string \"" + stdout + "\"")
		}

		goCompilerVersion = new(uint)
		*goCompilerVersion = uint(version)
	}

	return *goCompilerVersion, nil
}
开发者ID:remogatto,项目名称:goam,代码行数:29,代码来源:arch.go


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