0

I am using this web framework for go: https://github.com/gofiber/fiber

I want to run the basic example they gave called "hello world"

I copied the code and put it in a file called 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 !")
}

Before I ran the script I also made sure to install the framework by using go get -u github.com/gofiber/fiber.

Then running go run main.go the file runs but it doesn't run on my local host and tells me it is running on HOST[::]

How can I make it so it runs on localhost rather than HOST[::]. I tried to see if it was on my localhost and it is not there at all.

Here is the output I get

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
bobdylan01
  • 158
  • 2
  • 10

3 Answers3

4

From 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")

You can do:

app.Listen("localhost:3000")
stevenferrer
  • 2,504
  • 1
  • 22
  • 33
1

The argument of app.Listen function must be an string and if u want define the port is mandatory the two points:

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

There is probably something else running on port 3000. Switch to another port.

app.Listen(8000)
jayson mulwa
  • 81
  • 1
  • 3