package main
import (
"fmt"
"net/http"
)
func main() {
msg := "hello, world"
fmt.Println(msg)
err := http.ListenAndServe("0.0.0.0:8081", new(demo))
if err != nil {
fmt.Println(err.Error())
}
}
type demo struct {
}
func (d demo) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
fmt.Println("hello world")
writer.Write([]byte("hello\n"))
}
构建命令:GOOS=linux go build -gcflags=all="-N -l" demo ./main.go
2. 将构建出来的二进制scp到远端服务器
3. 在远端服务器启动demo二进制,./demo
4. 然后ps出进程号,ps -ef | grep demo
5. 然后执行如下命令
dlv --listen=xxx:8080 --headless=true --api-version=2 --log attach $pid
shell
–listen即远端服务器的地址,$pid即上面查询出来的进程id
6. 服务端的 *** 作就准备好了
7. 客户端,goland配置,点击Edit Configuration…
8. 配置Host和Port,Port改为–listen里的port,Host为服务器能访问的IP,如果是华为云或者阿里云的机器,即VIP
6. 然后点击小虫子进行debug,在goland打断点
7. 触发请求,即可进入断点
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)