[英]go fiber http functions
On the home page of "gofiber.io" they show this code在“gofiber.io”的主页上,他们显示了这段代码
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!")
.在代码中,“Get”function 的第二个参数中的 function 表示它正在返回错误,但返回的是
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.我承认我是 Golang 的新手,甚至是 Go Fiber 的新手,所以请帮助我更好地理解这一点。
The resulting error is returned from SendString ( nil
, if no error)结果错误从 SendString 返回(
nil
,如果没有错误)
See https://docs.gofiber.io/api/ctx#send参见https://docs.gofiber.io/api/ctx#send
The signature for is:的签名是:
func (c *Ctx) SendString(body string) error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.