The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
zhwguest

一直不知道如何直接判断 golang 的 http server 已经启动进入侦听状态了

  •  
  •   zhwguest · Oct 29, 2024 · 2688 views
    This topic created in 559 days ago, the information mentioned may be changed or developed.

    不知道为什么

    9 replies    2024-10-29 16:20:01 +08:00
    justseemore
        1
    justseemore  
       Oct 29, 2024
    netstat -anp | grep 端口
    fds
        2
    fds  
       Oct 29, 2024
    goroutine 会卡在那里呀。如果退出监听状态程序就继续执行了。你如果需要可以在语句前后改一下别的变量,记录状态,不过得注意并发安全。不清楚你是想实现什么,就是随便说说。这种问题可以问 gpt 。
    bv
        3
    bv  
       Oct 29, 2024   ❤️ 3
    lis, err := net.Listen("tcp", ":8080")
    if err != nil {
    fmt.Printf("listen error: %v\n", err)
    return
    }
    fmt.Println("listening on port 8080")

    srv := &http.Server{}
    srv.Serve(lis)
    changz
        4
    changz  
       Oct 29, 2024
    健康检查+探针
    phithon
        5
    phithon  
       Oct 29, 2024
    可以用 wait-for-it
    tairan2006
        6
    tairan2006  
       Oct 29, 2024
    http 探针啊。。这和别的语言有啥区别么
    Ackvincent
        7
    Ackvincent  
       Oct 29, 2024
    telnet 一下?
    guanzhangzhang
        8
    guanzhangzhang  
       Oct 29, 2024
    代码里的话,如果是多端口 server ,你可以找些 grpc 和 http port 的项目看下
    外部的话就有个/healthz 之类的路由外部探测
    leonshaw
        9
    leonshaw  
       Oct 29, 2024
    先 Listen() 再 Serve()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   984 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 68ms · UTC 20:14 · PVG 04:14 · LAX 13:14 · JFK 16:14
    ♥ Do have faith in what you're doing.