Home > Net >  go fiber http functions
go fiber http functions

Time:01-03

On the home page of "gofiber.io" they show this code

package main

import (
    "log"

    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    app.Get("/", func (c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

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

In the code, the function inside the second argument of the "Get" function says it is returning an error but returns a c.SendString("Hello, World!"). What do I not understand about this that makes it ok to say you're returning an error but you are returning something else?

I admit I am new to Golang and even newer to Go Fiber so please help me understand this better.

CodePudding user response:

The resulting error is returned from SendString (nil, if no error)

See https://docs.gofiber.io/api/ctx#send

The signature for is:

func (c *Ctx) SendString(body string) error
  • Related