本文整理汇总了Golang中strings.SplitAfter函数的典型用法代码示例。如果您正苦于以下问题:Golang SplitAfter函数的具体用法?Golang SplitAfter怎么用?Golang SplitAfter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SplitAfter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUpdatedMsg
func TestUpdatedMsg(t *testing.T) {
testsOld := []map[string]model.MeasurementsProperty{
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
nil,
}
testsUpdated := []map[string]model.MeasurementsProperty{
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {false, []string{""}, 60}, "tcpconn": {true, []string{""}, 60}},
{"fping": {false, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
nil,
{"fping": {true, []string{""}, 60}, "tcpping": {true, []string{""}, 60}, "tcpconn": {false, []string{""}, 60}},
}
expecteds := []string{
"<fping Disabled> <tcpping Disabled> <tcpconn Disabled> ",
"<fping Enabled> <tcpping Enabled> <tcpconn Enabled> ",
"<fping Disabled> ",
"<fping Disabled> <tcpconn Enabled> ",
"",
"<tcpping Disabled> <tcpconn Disabled> ",
"<fping Enabled> <tcpping Enabled> ",
}
for i, _ := range testsOld {
o := testsOld[i]
u := testsUpdated[i]
msg := updatedMsg(o, u)
msgSlice := strings.SplitAfter(msg, "> ")
msgMap := make(map[string]bool)
for _, m := range msgSlice {
if m == "" {
continue
}
msgMap[m] = true
}
expectedSlice := strings.SplitAfter(expecteds[i], "> ")
expectedMap := make(map[string]bool)
for _, m := range expectedSlice {
if m == "" {
continue
}
expectedMap[m] = true
}
if !reflect.DeepEqual(expectedMap, msgMap) {
t.Error(expectedMap, msgMap)
}
t.Log(msg)
}
}
示例2: main
func main() {
obytes, _ := ioutil.ReadFile(os.Args[1])
nbytes, _ := ioutil.ReadFile(os.Args[2])
o := strings.SplitAfter(string(obytes), "\n", -1)
n := strings.SplitAfter(string(nbytes), "\n", -1)
fmt.Println(patience.Diff(o, n))
}
示例3: Flush
// Flush the spans for a request in zipkin format
func Flush(t gotocol.TraceContextType, trace []*spannotype) {
var zip zipkinspan
var ctx string
n := -1
sort.Sort(ByCtx(trace))
for _, a := range trace {
//fmt.Println(*a)
if ctx != a.Ctx { // new span
if ctx != "" { // not the first
WriteZip(zip)
file.WriteString(",")
zip.Annotations = nil
}
n++
zip.Traceid = fmt.Sprintf("%016d", t) // pad id's to 16 characters to keep zipkin happy
zip.Name = a.Imp
s := strings.SplitAfter(a.Ctx, "s") // tXpYsZ -> [tXpYs, Z]
p := strings.TrimSuffix(strings.SplitAfter(s[0], "p")[1], "s") // tXpYs -> [tXp, Ys] -> Ys -> Y
zip.Id = "000000000000000"[0:(16-len(s[1]))] + s[1] // pad id's to 16 characters to keep zipkin happy
if p != "0" {
zip.ParentId = "000000000000000"[0:(16-len(p))] + p // pad id's to 16 characters to keep zipkin happy
}
ctx = a.Ctx
}
var ann zipkinannotation
ann.Endpoint.Servicename = a.Host
ann.Endpoint.Ipv4 = dhcp.Lookup(a.Host)
ann.Endpoint.Port = 8080
ann.Timestamp = a.Timestamp / 1000 // convert from UnixNano to Microseconds
ann.Value = a.Value
zip.Annotations = append(zip.Annotations, ann)
}
WriteZip(zip)
}
示例4: createRedirectServer
func createRedirectServer(t *testing.T) *httptest.Server {
ts := createTestServer(func(w http.ResponseWriter, r *http.Request) {
t.Logf("Method: %v", r.Method)
t.Logf("Path: %v", r.URL.Path)
if r.Method == GET {
if strings.HasPrefix(r.URL.Path, "/redirect-host-check-") {
cntStr := strings.SplitAfter(r.URL.Path, "-")[3]
cnt, _ := strconv.Atoi(cntStr)
if cnt != 7 { // Testing hard stop via logical
if cnt >= 5 {
http.Redirect(w, r, "http://httpbin.org/get", http.StatusTemporaryRedirect)
} else {
http.Redirect(w, r, fmt.Sprintf("/redirect-host-check-%d", (cnt+1)), http.StatusTemporaryRedirect)
}
}
} else if strings.HasPrefix(r.URL.Path, "/redirect-") {
cntStr := strings.SplitAfter(r.URL.Path, "-")[1]
cnt, _ := strconv.Atoi(cntStr)
http.Redirect(w, r, fmt.Sprintf("/redirect-%d", (cnt+1)), http.StatusTemporaryRedirect)
}
}
})
return ts
}
示例5: FindNamespace
func FindNamespace(host string) (string, error) {
//Attempt to access the host website
resp, err := http.Get(host)
if err == nil {
bytes, err := ioutil.ReadAll(resp.Body)
if err == nil {
//Successfully accessed the website!
body := string(bytes)
//Parse body looking for "v23.namespace.root="
//If found, return number after that
//Else keep looking
if strings.Contains(body, "v23.namespace.root=") {
//formatting return string
namespaces := strings.SplitAfter(body, "v23.namespace.root=")
for i := 1; i < len(namespaces); i += 2 {
namespaceWithJunk := namespaces[i]
namespace := strings.SplitAfter(namespaceWithJunk, "\n")[0]
cleanNamespace := strings.TrimSpace(namespace)
if cleanNamespace != "" {
return cleanNamespace, nil
}
}
}
}
}
//no instance of "v23.namespace.root=" is found
return "", errors.New("No namespace found")
}
示例6: Fprint
func (d *FileDiff) Fprint(f io.Writer) (e os.Error) {
switch d.Change {
case plumbing.Added:
fmt.Fprintln(f, color.String("Added "+d.Name, color.Meta))
case plumbing.Deleted:
fmt.Fprintln(f,color.String("Deleted "+d.Name, color.Meta))
case plumbing.Modified:
if d.OldMode != d.NewMode { fmt.Fprintln(f,d) }
oldf, newf, e := d.OldNewStrings()
if e != nil {
debug.Printf("Had trouble reading file and old %s: %s\n", d.Name, e.String())
return
}
if newf == oldf {
debug.Println("File "+d.Name+" is unchanged.")
return
}
newer := strings.SplitAfter(newf,"\n",-1)
older := strings.SplitAfter(oldf,"\n",-1)
mychunks := patience.Diff(older, newer)
lastline := 0
debug.Printf("File %s has %d chunks changed\n",d.Name,len(mychunks))
if len(mychunks) == 0 {
debug.Println("File "+d.Name+" mysteriously looks unchanged.")
return
}
if mychunks[0].Line-4 > lastline {
lastline = mychunks[0].Line - 4
}
fmt.Fprintf(f,color.String("¤¤¤ %s %d ¤¤¤\n", color.Meta),d.Name,lastline+1)
for _,ch := range mychunks {
if ch.Line > lastline + 6 {
for i:=lastline; i<lastline+3; i++ {
fmt.Fprint(f," ",newer[i])
}
fmt.Fprintf(f,color.String("¤¤¤ %s %d ¤¤¤\n", color.Meta),
d.Name,ch.Line-4+1)
for i:=ch.Line-4; i<ch.Line-1; i++ {
fmt.Fprint(f," ",newer[i])
}
} else {
for i:=lastline; i<ch.Line-1; i++ {
fmt.Fprint(f," ",newer[i])
}
}
fmt.Fprint(f,ch)
lastline = ch.Line - 1 + len(ch.New)
}
for i:=lastline; i<len(newer) && i < lastline+3;i++ {
fmt.Fprint(f," ",newer[i])
}
default:
fmt.Fprintln(f,d)
}
return
}
示例7: getIpAddress
func getIpAddress() string {
out, err := exec.Command("ifconfig", "eth0").Output()
if err != nil {
log.Fatal(err)
}
lines := strings.SplitAfter(string(out), "\n")
addresses := strings.SplitAfter(lines[1], ":")
address := strings.SplitAfter(addresses[1], " ")
return strings.TrimSpace(address[0])
}
示例8: GetSimilarTracks
// Returns similar tracks
func GetSimilarTracks(track *Track, collections Collections) (similarTracks SimilarTracks, err error) {
var chans = []chan CommandResult{}
for i := 0; i < len(collections); i++ {
ch := make(chan CommandResult)
RunCommand(fmt.Sprintf("musly -p \"%s\" -k20 -c \"%s\"", track.Pathname, collections[i].Pathname), ch)
chans = append(chans, ch)
}
var crs = []CommandResult{}
for i := 0; i < len(chans); i++ {
mr := <-chans[i]
crs = append(crs, mr)
}
var stdouts bytes.Buffer
for i := 0; i < len(crs); i++ {
stdouts.WriteString(crs[i].Stdout + "\n")
}
occuriences := map[string]float64{}
similaritySum := map[string]float64{}
scanner := bufio.NewScanner(strings.NewReader(stdouts.String()))
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "track-id") == false {
continue
}
pathname := strings.Replace(strings.SplitAfter(line, "track-origin: ")[1], "/collection", "", 1)
similarity, _ := strconv.ParseFloat(strings.Split(strings.SplitAfter(line, "track-similarity: ")[1], ", ")[0], 64)
similaritySum[pathname] += similarity
occuriences[pathname]++
}
similarTracks = SimilarTracks{}
for pathname, similarity := range similaritySum {
similarity, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", 100-(similarity/occuriences[pathname]*100)), 64)
similarTracks = append(similarTracks, SimilarTrack{NewTrack(pathname), similarity})
}
sort.Sort(similarTracks)
return
}
示例9: loadTokens
// loadTokens imports auth keys from rootkey.csv (AWS keyset)
func loadTokens(key *Keys) bool {
if tokens, err := ioutil.ReadFile("rootkey.csv"); err == nil {
temp := strings.Split(string(tokens), "\n")
if len(temp) == 2 {
key.AccessKey = strings.SplitAfter(temp[0], "=")[1]
key.SecretKey = strings.SplitAfter(temp[1], "=")[1]
return true
}
}
log.Println("Error loading tokens from rootkey.csv")
return false
}
示例10: Stats
//Stats gets the cpu and memory usage of a process
func (cp *ChildProcess) Stats() (map[string]string, error) {
stats, err := exec.Command("ps", "-p", strconv.Itoa(cp.PID), "-o", "%cpu,%mem").Output()
if err != nil {
return map[string]string{}, err
}
statsStr := strings.Trim(strings.SplitAfter(string(stats), "\n")[1], " ")
l := strings.SplitAfter(statsStr, " ")
return map[string]string{
"cpu": l[0],
"mem": strings.Replace(l[2], "\n", "", -1),
}, nil
}
示例11: String
func (s Patch) String() (out string) {
out = s.Header
for _, f := range s.File {
if len(out) > 0 { out += "\n" }
// out += string(f.Verb) + " " + f.Src
if f.OldMode != 0 && f.NewMode != 0 {
out += "\n" + fmt.Sprint(f.OldMode) + " -> " + fmt.Sprint(f.NewMode)
}
if f.OldMode != 0 && f.NewMode == 0 { // The file has been removed!
out += color.String("\nRemoved "+ f.Src, color.Meta)
continue
}
switch d := f.Diff.(type) {
default:
if f.Diff == patch.NoDiff {
// There is nothing here to see...
} else {
out += fmt.Sprintf("\nunexpected type %T", f.Diff) // %T prints type
}
case patch.TextDiff:
for _, chunk := range d {
older := strings.SplitAfter(string(chunk.Old), "\n",-1)
newer := strings.SplitAfter(string(chunk.New), "\n",-1)
lastline:=chunk.Line
mychunks := patience.DiffFromLine(chunk.Line, older, newer)
fmt.Println(color.String("¤¤¤¤¤¤ "+f.Src+string(chunk.Line)+" ¤¤¤¤¤¤", color.Meta))
for _,ch := range mychunks {
if ch.Line > lastline + 6 {
for i:=lastline+1; i<lastline+4; i++ {
fmt.Print(" ",newer[i-chunk.Line])
}
fmt.Println(color.String("¤¤¤¤¤¤ "+f.Src+string(chunk.Line-3)+" ¤¤¤¤¤¤", color.Meta))
for i:=ch.Line-3; i<ch.Line; i++ {
fmt.Print(" ",newer[i-chunk.Line])
}
} else {
for i:=lastline; i<ch.Line; i++ {
fmt.Print(" ",newer[i-chunk.Line])
}
}
fmt.Print(ch)
lastline = ch.Line + len(ch.New)
}
for i:=lastline-chunk.Line; i<len(newer);i++ {
fmt.Print(" ",newer[i])
}
}
}
}
return
}
示例12: splitAfterMultiple
// extension of strings.SplitAfter to split string multiple times using multiple
// split strings
func splitAfterMultiple(x string, s []string) []string {
if len(s) == 0 {
return []string{}
}
r := strings.SplitAfter(x, s[0])
for _, sx := range s[1:] {
t := make([]string, 0, len(r))
for _, ry := range r {
t = append(t, strings.SplitAfter(ry, sx)...)
}
r = t
}
return r
}
示例13: FindVAppByID
func (v *Vdc) FindVAppByID(vappid string) (VApp, error) {
// Horrible hack to fetch a vapp with its id.
// urn:vcloud:vapp:00000000-0000-0000-0000-000000000000
err := v.Refresh()
if err != nil {
return VApp{}, fmt.Errorf("error refreshing vdc: %s", err)
}
urnslice := strings.SplitAfter(vappid, ":")
urnid := urnslice[len(urnslice)-1]
for _, resents := range v.Vdc.ResourceEntities {
for _, resent := range resents.ResourceEntity {
hrefslice := strings.SplitAfter(resent.HREF, "/")
hrefslice = strings.SplitAfter(hrefslice[len(hrefslice)-1], "-")
res := strings.Join(hrefslice[1:], "")
if res == urnid && resent.Type == "application/vnd.vmware.vcloud.vApp+xml" {
u, err := url.ParseRequestURI(resent.HREF)
if err != nil {
return VApp{}, fmt.Errorf("error decoding vdc response: %s", err)
}
// Querying the VApp
req := v.c.NewRequest(map[string]string{}, "GET", *u, nil)
resp, err := checkResp(v.c.Http.Do(req))
if err != nil {
return VApp{}, fmt.Errorf("error retrieving vApp: %s", err)
}
newvapp := NewVApp(v.c)
if err = decodeBody(resp, newvapp.VApp); err != nil {
return VApp{}, fmt.Errorf("error decoding vApp response: %s", err)
}
return *newvapp, nil
}
}
}
return VApp{}, fmt.Errorf("can't find vApp")
}
示例14: getOathToken
func getOathToken(userID string, userCode string) {
fmt.Println("Getting the OAuthToken")
//CHANGE FROM LOCALHOST
requestString := "https://foursquare.com/oauth2/access_token?client_id=5ATHFEOTK5EU23DGQXCJ4XHYF1OWTBDIIV2CHXBAYQN0X5IO&client_secret=F1SZ1YRLHF4RURVU40QTC5NCB4Y3AHPM4MMIXHFDCRZZD4R0&grant_type=authorization_code&redirect_uri=https://localhost/afterlanding.html&code=" + userCode
fmt.Println(requestString)
response, err := http.Get(requestString)
if response.StatusCode != 200 {
fmt.Println("error")
body, _ := ioutil.ReadAll(response.Body)
fmt.Println("Body: ", string(body))
return
}
check(err)
body, _ := ioutil.ReadAll(response.Body)
fmt.Println("Body: ", string(body))
strings := strings.SplitAfter(string(body), ":")
fmt.Println("Strings after Split: ", strings)
session, err := mgo.Dial("localhost")
check(err)
defer session.Close()
session.SetMode(mgo.Monotonic, true)
c := session.DB("test").C("foursqare")
toInsert := foursquareInformation{userID, strings[1], make([]string, 0), make([]string, 0)}
c.Insert(&toInsert)
//I presume we would here go get the user's data
}
示例15: bootstrapFixImports
func bootstrapFixImports(text, srcFile string) string {
lines := strings.SplitAfter(text, "\n")
inBlock := false
for i, line := range lines {
if strings.HasPrefix(line, "import (") {
inBlock = true
continue
}
if inBlock && strings.HasPrefix(line, ")") {
inBlock = false
continue
}
if strings.HasPrefix(line, `import "`) || strings.HasPrefix(line, `import . "`) ||
inBlock && (strings.HasPrefix(line, "\t\"") || strings.HasPrefix(line, "\t. \"")) {
line = strings.Replace(line, `"cmd/`, `"bootstrap/cmd/`, -1)
for _, dir := range bootstrapDirs {
if strings.HasPrefix(dir, "cmd/") {
continue
}
line = strings.Replace(line, `"`+dir+`"`, `"bootstrap/`+dir+`"`, -1)
}
lines[i] = line
}
}
lines[0] = "// Do not edit. Bootstrap copy of " + srcFile + "\n\n//line " + srcFile + ":1\n" + lines[0]
return strings.Join(lines, "")
}