简体   繁体   中英

go fiber http functions

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM