在本地主机上使用光纤而不是 运行

Go fiber not running on localhost

我正在使用这个 web 框架:https://github.com/gofiber/fiber

我想 运行 他们给出的基本示例 "hello world"

我复制了代码并将其放入名为 main.go

的文件中
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
//  Github Repository: https://github.com/gofiber/fiber
//  API Documentation: https://docs.gofiber.io

package main

import (
    "log"

    "github.com/gofiber/fiber"
)

func main() {
    // Fiber instance
    app := fiber.New()

    // Routes
    app.Get("/", hello)

    // Start server
    log.Fatal(app.Listen(3000))
}

// Handler
func hello(c *fiber.Ctx) {
    c.Send("Hello, World !")
}

在我 运行 脚本之前,我还确保使用 go get -u github.com/gofiber/fiber.

安装框架

然后 运行正在 go run main.go 文件 运行s 但它没有 运行 在我的本地主机上并告诉我它是 运行ning在 HOST[::]

我怎样才能做到 运行 在 localhost 而不是 HOST[::]。我试图查看它是否在我的本地主机上,但它根本不存在。

来自fiber godoc reference

func (*App) Listen ¶ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error Listen serves HTTP requests from the given addr or port. You can pass an optional *tls.Config to enable TLS.

  • app.Listen(8080) - app.Listen("8080") - app.Listen(":8080") - app.Listen("127.0.0.1:8080")

你可以这样做:

app.Listen("localhost:3000")

端口 3000 上可能有其他东西 运行。切换到另一个端口。

app.Listen(8000)

app.Listen函数的参数必须是一个字符串,如果你想定义端口是强制性的两点:

log.Fatal(app.Listen(":3000"))