问答

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

作者:admin 2021-09-10 我要评论

代码如下: package notifierimport ( "fmt" "strconv" "sync" "strings" "net" "net/http" "time" "container/list")type ClientInfo struct { pncode string f...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

代码如下:

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
###

看错了,不好意思。

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 明明使用了,但还是报错  imported and

    明明使用了,但还是报错 imported and

  • 遍历对象里面的对象再继续遍历里面的对

    遍历对象里面的对象再继续遍历里面的对

  • Nuxt.js设置同一个路由地址根据设备类

    Nuxt.js设置同一个路由地址根据设备类

  • create-react-app 是否可以移除不需要

    create-react-app 是否可以移除不需要

腾讯云代理商
海外云服务器