本文整理汇总了Golang中strings.TrimSpace函数的典型用法代码示例。如果您正苦于以下问题:Golang TrimSpace函数的具体用法?Golang TrimSpace怎么用?Golang TrimSpace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TrimSpace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInsertRead
func TestInsertRead(t *testing.T) {
tmp := "/tmp/tiedot_test_col"
os.Remove(tmp)
defer os.Remove(tmp)
col, err := OpenCollection(tmp)
if err != nil {
t.Fatalf("Failed to open: %v", err)
return
}
defer col.Close()
docs := [][]byte{
[]byte("abc"),
[]byte("1234")}
ids := [2]int{}
if ids[0], err = col.Insert(docs[0]); ids[0] != 0 || err != nil {
t.Fatalf("Failed to insert: %d %v", ids[0], err)
}
if ids[1], err = col.Insert(docs[1]); err != nil {
t.Fatalf("Failed to insert: %v", err)
}
if doc0 := col.Read(ids[0]); doc0 == nil || strings.TrimSpace(string(doc0)) != string(docs[0]) {
t.Fatal("Failed to read", doc0)
}
if doc1 := col.Read(ids[1]); doc1 == nil || strings.TrimSpace(string(doc1)) != string(docs[1]) {
t.Fatalf("Failed to read")
}
// it shall not panic
col.Read(col.Size)
}
示例2: TestGraphNodeConfigModuleExpandFlatten
func TestGraphNodeConfigModuleExpandFlatten(t *testing.T) {
mod := testModule(t, "graph-node-module-flatten")
node := &GraphNodeConfigModule{
Path: []string{RootModuleName, "child"},
Module: &config.Module{},
Tree: nil,
}
g, err := node.Expand(&BasicGraphBuilder{
Steps: []GraphTransformer{
&ConfigTransformer{Module: mod},
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
fg := g.(GraphNodeFlatGraph)
actual := strings.TrimSpace(fg.FlattenGraph().String())
expected := strings.TrimSpace(testGraphNodeModuleExpandFlattenStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
示例3: TestContainerApiDeleteRemoveLinks
func (s *DockerSuite) TestContainerApiDeleteRemoveLinks(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top")
id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil)
out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
id2 := strings.TrimSpace(out)
c.Assert(waitRun(id2), check.IsNil)
links, err := inspectFieldJSON(id2, "HostConfig.Links")
c.Assert(err, check.IsNil)
if links != "[\"/tlink1:/tlink2/tlink1\"]" {
c.Fatal("expected to have links between containers")
}
status, _, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusNoContent)
linksPostRm, err := inspectFieldJSON(id2, "HostConfig.Links")
c.Assert(err, check.IsNil)
if linksPostRm != "null" {
c.Fatal("call to api deleteContainer links should have removed the specified links")
}
}
示例4: testStringMatch
func testStringMatch(t *testing.T, s fmt.Stringer, expected string) {
actual := strings.TrimSpace(s.String())
expected = strings.TrimSpace(expected)
if actual != expected {
t.Fatalf("Actual\n\n%s\n\nExpected:\n\n%s", actual, expected)
}
}
示例5: TestEventsContainerFilterBeforeCreate
// #18453
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
testRequires(c, DaemonIsLinux)
var (
out string
ch chan struct{}
)
ch = make(chan struct{})
// calculate the time it takes to create and start a container and sleep 2 seconds
// this is to make sure the docker event will recevie the event of container
since := daemonTime(c).Unix()
id, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(id)
waitRun(cID)
time.Sleep(2 * time.Second)
duration := daemonTime(c).Unix() - since
go func() {
out, _ = dockerCmd(c, "events", "-f", "container=foo", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()+2*duration))
close(ch)
}()
// Sleep 2 second to wait docker event to start
time.Sleep(2 * time.Second)
id, _ = dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
cID = strings.TrimSpace(id)
waitRun(cID)
<-ch
c.Assert(out, checker.Contains, cID, check.Commentf("Missing event of container (foo)"))
}
示例6: dmlTableMatch
func (blp *BinlogPlayer) dmlTableMatch(sqlSlice []string) bool {
if blp.tables == nil {
return true
}
if len(blp.tables) == 0 {
return true
}
var firstKw string
for _, sql := range sqlSlice {
firstKw = strings.TrimSpace(strings.Split(sql, BLPL_SPACE)[0])
if firstKw != "insert" && firstKw != "update" && firstKw != "delete" {
continue
}
streamCommentIndex := strings.Index(sql, BLPL_STREAM_COMMENT_START)
if streamCommentIndex == -1 {
//log.Warningf("sql doesn't have stream comment '%v'", sql)
//If sql doesn't have stream comment, don't match
return false
}
tableName := strings.TrimSpace(strings.Split(sql[(streamCommentIndex+len(BLPL_STREAM_COMMENT_START)):], BLPL_SPACE)[0])
for _, table := range blp.tables {
if tableName == table {
return true
}
}
}
return false
}
示例7: Profile
//资料修改
func (this *AccountController) Profile() {
user := models.User{Id: this.userid}
if err := user.Read(); err != nil {
this.showmsg(err.Error())
}
if this.isPost() {
errmsg := make(map[string]string)
password := strings.TrimSpace(this.GetString("password"))
newpassword := strings.TrimSpace(this.GetString("newpassword"))
newpassword2 := strings.TrimSpace(this.GetString("newpassword2"))
updated := false
if newpassword != "" {
if password == "" || util.Md5([]byte(password)) != user.Password {
errmsg["password"] = "当前密码错误"
} else if len(newpassword) < 6 {
errmsg["newpassword"] = "密码长度不能少于6个字符"
} else if newpassword != newpassword2 {
errmsg["newpassword2"] = "两次输入的密码不一致"
}
if len(errmsg) == 0 {
user.Password = util.Md5([]byte(newpassword))
user.Update("password")
updated = true
}
}
this.Data["updated"] = updated
this.Data["errmsg"] = errmsg
}
this.Data["user"] = user
this.display()
}
示例8: ParseHashtags
func ParseHashtags(text string) (string, string) {
words := strings.Fields(text)
hashtagString := ""
plainString := ""
for _, word := range words {
// trim off surrounding punctuation
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
// and remove extra pound #s
word = hashtagStart.ReplaceAllString(word, "#")
if validHashtag.MatchString(word) {
hashtagString += " " + word
} else {
plainString += " " + word
}
}
if len(hashtagString) > 1000 {
hashtagString = hashtagString[:999]
lastSpace := strings.LastIndex(hashtagString, " ")
if lastSpace > -1 {
hashtagString = hashtagString[:lastSpace]
} else {
hashtagString = ""
}
}
return strings.TrimSpace(hashtagString), strings.TrimSpace(plainString)
}
示例9: domainData
func (this *Domain) domainData(out chan interface{}, in chan int8) {
var (
tname = "zhejiang_urltrack_" + time.Now().Format("200601")
btime = timestamp.GetHourTimestamp(-1)
etime = timestamp.GetHourTimestamp(0)
)
sc := hbase.NewScan([]byte(tname), 10000, this.hb)
sc.StartRow = []byte(btime)
sc.StopRow = []byte(etime)
for {
row := sc.Next()
if row == nil {
break
}
ad := strings.TrimSpace(string(row.Columns["base:ad"].Value))
ua := strings.TrimSpace(string(row.Columns["base:ua"].Value))
cids := make([]string, 0, len(row.Columns)-2)
for _, v := range row.Columns {
if string(v.Family) == "cids" {
cids = append(cids, string(v.Qual))
}
}
out <- fmt.Sprintf("%s\t%s\t%s", ad, ua, strings.Join(cids, ","))
}
in <- 1
sc.Close()
}
示例10: TestLinksHostsFilesInject
func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
testRequires(c, SameHostDaemon, ExecSupport)
out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top")
idOne := strings.TrimSpace(out)
out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")
idTwo := strings.TrimSpace(out)
time.Sleep(1 * time.Second)
contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts")
if err != nil {
c.Fatal(err, string(contentOne))
}
contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts")
if err != nil {
c.Fatal(err, string(contentTwo))
}
if !strings.Contains(string(contentTwo), "onetwo") {
c.Fatal("Host is not present in updated hosts file", string(contentTwo))
}
}
示例11: TestRestartContainerwithRestartPolicy
func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *check.C) {
out1, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false")
out2, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false")
id1 := strings.TrimSpace(string(out1))
id2 := strings.TrimSpace(string(out2))
err := waitInspect(id1, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 30*time.Second)
c.Assert(err, checker.IsNil)
// TODO: fix racey problem during restart:
// https://jenkins.dockerproject.org/job/Docker-PRs-Win2Lin/24665/console
// Error response from daemon: Cannot restart container 6655f620d90b390527db23c0a15b3e46d86a58ecec20a5697ab228d860174251: remove /var/run/docker/libcontainerd/6655f620d90b390527db23c0a15b3e46d86a58ecec20a5697ab228d860174251/rootfs: device or resource busy
if _, _, err := dockerCmdWithError("restart", id1); err != nil {
// if restart met racey problem, try again
time.Sleep(500 * time.Millisecond)
dockerCmd(c, "restart", id1)
}
if _, _, err := dockerCmdWithError("restart", id2); err != nil {
// if restart met racey problem, try again
time.Sleep(500 * time.Millisecond)
dockerCmd(c, "restart", id2)
}
dockerCmd(c, "stop", id1)
dockerCmd(c, "stop", id2)
dockerCmd(c, "start", id1)
dockerCmd(c, "start", id2)
}
示例12: TestVolpluginRestartMultiMount
func (s *systemtestSuite) TestVolpluginRestartMultiMount(c *C) {
_, err := s.mon0cmd("sudo truncate -s0 /tmp/volplugin.log")
c.Assert(err, IsNil)
volName := fqVolume("policy1", genRandomVolume())
c.Assert(s.createVolume("mon0", volName, map[string]string{"unlocked": "true"}), IsNil)
out, err := s.dockerRun("mon0", false, true, volName, "sleep 10m")
c.Assert(err, IsNil, Commentf(out))
// test if any containers can start after this -- they should be able to.
// This just starts and stops a container quickly.
outErr, err := s.dockerRun("mon0", false, false, volName, "echo")
c.Assert(err, IsNil, Commentf(outErr))
out2, err := s.dockerRun("mon0", false, true, volName, "sleep 10m")
c.Assert(err, IsNil, Commentf(out2))
c.Assert(stopVolplugin(s.vagrant.GetNode("mon0")), IsNil)
c.Assert(startVolplugin(s.vagrant.GetNode("mon0")), IsNil)
c.Assert(waitForVolplugin(s.vagrant.GetNode("mon0")), IsNil)
time.Sleep(15 * time.Second)
out = strings.TrimSpace(out)
out2 = strings.TrimSpace(out2)
errout, err := s.mon0cmd(fmt.Sprintf("docker kill -s KILL '%s' && sleep 1 && docker rm '%s'", out, out))
c.Assert(err, IsNil, Commentf(errout))
errout, err = s.mon0cmd(fmt.Sprintf("docker kill -s KILL '%s' && sleep 1 && docker rm '%s'", out2, out2))
c.Assert(err, IsNil, Commentf(errout))
errout, err = s.mon0cmd("grep 500 /tmp/volplugin.log")
c.Assert(err, NotNil, Commentf(errout))
}
示例13: readJson
func readJson(r io.Reader) ([]byte, error) {
s, err := ioutil.ReadAll(r)
if err != nil {
return s, err
}
lines := make([]string, 0)
for _, line := range strings.Split(strings.Replace(string(s), "\r\n", "\n", -1), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "//") {
continue
}
lines = append(lines, line)
}
var b bytes.Buffer
for i, line := range lines {
if i < len(lines)-1 {
nextLine := strings.TrimSpace(lines[i+1])
if nextLine == "]" ||
nextLine == "]," ||
nextLine == "}" ||
nextLine == "}," {
if strings.HasSuffix(line, ",") {
line = strings.TrimSuffix(line, ",")
}
}
}
b.WriteString(line)
}
return b.Bytes(), nil
}
示例14: currentRev
func (g *Goop) currentRev(vcsCmd string, path string) (string, error) {
switch vcsCmd {
case "git":
cmd := exec.Command("git", "rev-parse", "--verify", "HEAD")
cmd.Dir = path
cmd.Stderr = g.stderr
rev, err := cmd.Output()
if err != nil {
return "", err
} else {
return strings.TrimSpace(string(rev)), err
}
case "hg":
cmd := exec.Command("hg", "log", "-r", ".", "--template", "{node}")
cmd.Dir = path
cmd.Stderr = g.stderr
rev, err := cmd.Output()
if err != nil {
return "", err
} else {
return strings.TrimSpace(string(rev)), err
}
}
return "", &UnsupportedVCSError{VCS: vcsCmd}
}
示例15: wrapText
func wrapText(s string, l int, prefix string) string {
// Basic text wrapping of s at spaces to fit in l
var ret string
s = strings.TrimSpace(s)
for len(s) > l {
// Try to split on space
suffix := ""
pos := strings.LastIndex(s[:l], " ")
if pos < 0 {
pos = l - 1
suffix = "-\n"
}
if len(ret) != 0 {
ret += "\n" + prefix
}
ret += strings.TrimSpace(s[:pos]) + suffix
s = strings.TrimSpace(s[pos:])
}
if len(s) > 0 {
if len(ret) != 0 {
ret += "\n" + prefix
}
return ret + s
}
return ret
}