HTTP 服务不工作

HTTP service doesn't work

我正在尝试使用 Hprose 在 Go 中实现 RPC 服务器。它工作正常,但在添加了更多功能后却没有:/

有趣的是,它甚至在其他 http 库(如 fasthttp)上也不起作用。 ListenAndServe() 方法似乎在执行期间卡在某个地方,因为它从来没有 returns。可能是什么原因造成的?

package main


import (
    "net/http"
    "fmt"
     "github.com/hprose/hprose-golang/rpc"
    log "logutil"
)

func main() {
    log.InitializeLogger()
    InitializeEthClient()
    InitializeClients()
    server := rpc.NewHTTPService()

    // TxtStorage functions
    server.AddFunction("DeployTxtStorage", DeployNewTxtStorage)
    server.AddFunction("GetPackedData", GetPackedData)
    server.AddFunction("GetReputation", GetReputation)
    server.AddFunction("GetEventsForReputation", GetEventsForReputation)
    server.AddFunction("GetEventsForData", GetEventsForData)

    // Clients functions
    server.AddFunction("RegisterClient", RegisterClient)

    log.Info("Registered server functions!")
    err := http.ListenAndServe(":8080", server)
    fmt.Println(err)
    log.Info("Waiting for incoming connections...")
    log.WriteAway()
}

ListenAndServe 正在阻塞,它不会 return 除非遇到错误。你似乎期待你的最后几行打印出来

Waiting for incoming connections...

但这永远不会发生,因为服务器是 运行。您确定它不只是按预期工作吗?