小编ica*_*ajo的帖子

不能使用(类型[] byte)作为类型io.Reader

我不明白错误,这是我在机器"A"中执行的main.go:

package main

import (
    "fmt"
    "net"
    "os"
    "github.com/mistifyio/go-zfs"
)

func main() {
    // Listen for incoming connections.
    l, err := net.Listen("tcp", "192.168.99.5:9977")
    if err != nil ...
    // Close the listener when the application closes.
    defer l.Close()
    fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT)
    for {
        // Listen for an incoming connection.
        conn, err := l.Accept()
        if err != nil ...

        //Handle connections in a new goroutine.
        go handleRequest(conn)
    }
}

// Handles incoming requests.
func handleRequest(conn …
Run Code Online (Sandbox Code Playgroud)

io byte go reader

5
推荐指数
2
解决办法
8307
查看次数

在循环中更新字符串值

我们执行for循环时是否可以更新字符串的值?

package main 
import (
    "fmt"
    "strings"
)

func Chop(r int, s string) string {
    return s[r:]
}

func main() {
    s:= "ThisIsAstring1ThisIsAstring2ThisIsAstring3"
    for strings.Contains(s, "string") {
        // Original value > ThisIsAstring1ThisIsAstring2ThisIsAstring3
        fmt.Println(s)
        // I delete a part of the string > ThisIsAstring1
        remove := len(s)/3
        // Now, I update the value of string > string := ThisIsAstring2ThisIsAstring3
        s := Chop(remove, s)
        fmt.Println(s)
        break
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道怎么做.

string for-loop go

-1
推荐指数
1
解决办法
96
查看次数

标签 统计

go ×2

byte ×1

for-loop ×1

io ×1

reader ×1

string ×1