明明使用了,但还是报错 imported and not used: "time"

代码如下:

package notifier

import (
    "fmt"
    "strconv"
    "sync"
    "strings"
    "net"
    "net/http"
    "time"
    "container/list"
)

type ClientInfo struct {
    pncode string
    frpcState string
}

var mtx sync.Mutex
var infoList = list.New()

func InfoListPushBack(pncode string, frpcState string) {
    info := ClientInfo {pncode, frpcState}
    mtx.Lock()
    infoList.PushBack(info)
    mtx.Unlock()
}


func dialTimeout(network, addr string) (net.Conn, error) {
    return net.DialTimeout(network, addr, time.Second*1)
}

 func SendFrpcState(pncode string, frpcState string) bool {
    url := "http://xxxxxxxxxx"
    body := "machineCode=" + pncode + "&state=" + frpcState
    payload := strings.NewReader(body)

    transport := http.Transport{
        Dial: dialTimeout,
        DisableKeepAlives: true,
    }

    client := &http.Client{
        Transport: &transport,
    }

    var res = false

    req, err := http.NewRequest("POST", url, payload)
    if err == nil {
        req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
        req.Header.Add("Content-length", strconv.Itoa(len(body)))
        resp, _ := client.Do(req)
        if resp != nil {
            defer resp.Body.Close()
            if resp.StatusCode == 200 { // 说明成功
                res = true
            }
        }
    }

    fmt.Printf("[%s] --> [%s]\n", pncode, frpcState)

    return res
}

func NotifyEvent() {
    for true {
        mtx.Lock()
        if infoList.Len() > 0 {
            var element =  infoList.Front()
            op, ok := element.Value.(ClientInfo)
            if ok {
                if SendFrpcState(op.pncode, op.frpcState) {
                    infoList.Remove(element)
                }
            }
        }
        mtx.Unlock()
        time.Sleep(time.Duration(500) * time.Microsecond) // 在这里使用了
    }
}

go 的版本是:go version go1.12.7 linux/amd64

报错信息是:

hapoa@hapoa-virtual-machine:~/projects/frp/src/github.com/fatedier/frp$ make -f ./Makefile.my 
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o ./frps_linux_amd64 ./cmd/frps
# github.com/fatedier/frp/server/proxy
server/proxy/proxy.go:24:2: imported and not used: "time"
make: *** [app] 错误 2
阅读 4.6k
1 个回答

看错了,不好意思。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题