// Accept: text/html, text/*, application/json, */*; q=0
app.Get("/",func(c*fiber.Ctx)error{c.Accepts("text/plain","application/json")// "application/json", due to specificity
c.Accepts("application/json","text/html")// "text/html", due to first match
c.Accepts("image/png")// "", due to */* without q factor 0 is Not Acceptable
// ...
})
Media-Type parameters are supported.
支持媒体类型参数。
Example 3
示例 3
1
2
3
4
5
6
7
8
9
10
11
12
// Accept: text/plain, application/json; version=1; foo=bar
app.Get("/",func(c*fiber.Ctx)error{// Extra parameters in the accept are ignored
c.Accepts("text/plain;format=flowed")// "text/plain;format=flowed"
// An offer must contain all parameters present in the Accept type
c.Accepts("application/json")// ""
// Parameter order and capitalization does not matter. Quotes on values are stripped.
c.Accepts(`application/json;foo="bar";VERSION=1`)// "application/json;foo="bar";VERSION=1"
})
Example 4
示例 4
1
2
3
4
5
6
7
8
9
10
11
// Accept: text/plain;format=flowed;q=0.9, text/plain
// i.e., "I prefer text/plain;format=flowed less than other forms of text/plain"
app.Get("/",func(c*fiber.Ctx)error{// Beware: the order in which offers are listed matters.
// Although the client specified they prefer not to receive format=flowed,
// the text/plain Accept matches with "text/plain;format=flowed" first, so it is returned.
c.Accepts("text/plain;format=flowed","text/plain")// "text/plain;format=flowed"
// Here, things behave as expected:
c.Accepts("text/plain","text/plain;format=flowed")// "text/plain"
})
Fiber provides similar functions for the other accept headers.
app.Use(func(c*fiber.Ctx)error{c.Bind(fiber.Map{"Title":"Hello, World!",})})app.Get("/",func(c*fiber.Ctx)error{returnc.Render("xxx.tmpl",fiber.Map{})// Render will use Title variable
})
BodyRaw
Returns the raw request body.
返回原始请求正文。
Signature
签名
1
func(c*Ctx)BodyRaw()[]byte
Example
示例
1
2
3
4
5
6
// curl -X POST http://localhost:8080 -d user=john
app.Post("/",func(c*fiber.Ctx)error{// Get raw body from POST request:
returnc.Send(c.BodyRaw())// []byte("user=john")
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序内有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
了解更多…
Body
As per the header Content-Encoding, this method will try to perform a file decompression from the body bytes. In case no Content-Encoding header is sent, it will perform as BodyRaw.
// echo 'user=john' | gzip | curl -v -i --data-binary @- -H "Content-Encoding: gzip" http://localhost:8080
app.Post("/",func(c*fiber.Ctx)error{// Decompress body from POST request based on the Content-Encoding and return the raw content:
returnc.Send(c.Body())// []byte("user=john")
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序内有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
BodyParser
Binds the request body to a struct.
将请求正文绑定到结构。
It is important to specify the correct struct tag based on the content type to be parsed. For example, if you want to parse a JSON body with a field called Pass, you would use a struct field of json:"pass".
// Field names should start with an uppercase letter
typePersonstruct{Namestring`json:"name" xml:"name" form:"name"`Passstring`json:"pass" xml:"pass" form:"pass"`}app.Post("/",func(c*fiber.Ctx)error{p:=new(Person)iferr:=c.BodyParser(p);err!=nil{returnerr}log.Println(p.Name)// john
log.Println(p.Pass)// doe
// ...
})// Run tests with the following curl commands
// curl -X POST -H "Content-Type: application/json" --data "{\"name\":\"john\",\"pass\":\"doe\"}" localhost:3000
// curl -X POST -H "Content-Type: application/xml" --data "<login><name>john</name><pass>doe</pass></login>" localhost:3000
// curl -X POST -H "Content-Type: application/x-www-form-urlencoded" --data "name=john&pass=doe" localhost:3000
// curl -X POST -F name=john -F pass=doe http://localhost:3000
// curl -X POST "http://localhost:3000/?name=john&pass=doe"
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序中有效。请勿存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
ClearCookie
Expire a client cookie (or all cookies if left empty)
使客户端 cookie 过期(如果留空,则使所有 cookie 过期)
Signature
签名
1
func(c*Ctx)ClearCookie(key...string)
Example
示例
1
2
3
4
5
6
7
8
9
10
11
app.Get("/",func(c*fiber.Ctx)error{// Clears all cookies:
c.ClearCookie()// Expire specific cookie by name:
c.ClearCookie("user")// Expire multiple cookies by names:
c.ClearCookie("token","session","track_id","version")// ...
})
CAUTION
注意
Web browsers and other compliant clients will only clear the cookie if the given options are identical to those when creating the cookie, excluding expires and maxAge. ClearCookie will not set these values for you - a technique similar to the one shown below should be used to ensure your cookie is deleted.
app.Get("/set",func(c*fiber.Ctx)error{c.Cookie(&fiber.Cookie{Name:"token",Value:"randomvalue",Expires:time.Now().Add(24*time.Hour),HTTPOnly:true,SameSite:"lax",})// ...
})app.Get("/delete",func(c*fiber.Ctx)error{c.Cookie(&fiber.Cookie{Name:"token",// Set expiry date to the past
Expires:time.Now().Add(-(time.Hour*2)),HTTPOnly:true,SameSite:"lax",})// ...
})
ClientHelloInfo
ClientHelloInfo contains information from a ClientHello message in order to guide application logic in the GetCertificate and GetConfigForClient callbacks. You can refer to the ClientHelloInfo struct documentation for more information on the returned struct.
// GET http://example.com/hello
app.Get("/hello",func(c*fiber.Ctx)error{chi:=c.ClientHelloInfo()// ...
})
Context
Returns *fasthttp.RequestCtx that is compatible with the context.Context interface that requires a deadline, a cancellation signal, and other values across API boundaries.
返回与 context.Context 接口兼容的 *fasthttp.RequestCtx,该接口需要一个截止时间、一个取消信号以及跨 API 边界的其他值。
app.Get("/",func(c*fiber.Ctx)error{// Create cookie
cookie:=new(fiber.Cookie)cookie.Name="john"cookie.Value="doe"cookie.Expires=time.Now().Add(24*time.Hour)// Set cookie
c.Cookie(cookie)// ...
})
CookieParser
This method is similar to BodyParser, but for cookie parameters. It is important to use the struct tag “cookie”. For example, if you want to parse a cookie with a field called Age, you would use a struct field of cookie:"age".
此方法类似于 BodyParser,但适用于 cookie 参数。重要的是使用结构标记“cookie”。例如,如果您想解析一个名为 Age 的字段的 cookie,您将使用 cookie:"age" 的结构字段。
// Field names should start with an uppercase letter
typePersonstruct{Namestring`cookie:"name"`Ageint`cookie:"age"`Jobbool`cookie:"job"`}app.Get("/",func(c*fiber.Ctx)error{p:=new(Person)iferr:=c.CookieParser(p);err!=nil{returnerr}log.Println(p.Name)// Joseph
log.Println(p.Age)// 23
log.Println(p.Job)// true
})// Run tests with the following curl command
// curl.exe --cookie "name=Joseph; age=23; job=true" http://localhost:8000/
Cookies
Get cookie value by key, you could pass an optional default value that will be returned if the cookie key does not exist.
app.Get("/",func(c*fiber.Ctx)error{// Get cookie by key:
c.Cookies("name")// "john"
c.Cookies("empty","doe")// "doe"
// ...
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
Download 下载
Transfers the file from path as an attachment.
将文件从路径作为 attachment 传输。
Typically, browsers will prompt the user to download. By default, the Content-Disposition header filename= parameter is the file path (this typically appears in the browser dialog).
app.Post("/",func(c*fiber.Ctx)error{// Get first file from form field "document":
file,err:=c.FormFile("document")// Save file to root directory:
returnc.SaveFile(file,fmt.Sprintf("./%s",file.Filename))})
FormValue
Any form values can be retrieved by name, the first value from the given key is returned.
app.Post("/",func(c*fiber.Ctx)error{// Get first value from form field "name":
c.FormValue("name")// => "john" or "" if not exist
// ..
})
Returned value is only valid within the handler. Do not store any references.
返回的值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
改用Immutablesetting instead.
设置进行复制或使用。Read more…
阅读更多…
Fresh
When the response is still fresh in the client’s cache true is returned, otherwise false is returned to indicate that the client cache is now stale and the full response should be sent.
When a client sends the Cache-Control: no-cache request header to indicate an end-to-end reload request, Fresh will return false to make handling these requests transparent.
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序内有效。请勿存储任何引用。
Make copies or use the
改用Immutablesetting instead.
设置进行复制或使用。Read more…
阅读更多…
GetReqHeaders
Returns the HTTP request headers as a map. Since a header can be set multiple times in a single request, the values of the map are slices of strings containing all the different values of the header.
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序内有效。请勿存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
GetRespHeader
Returns the HTTP response header specified by the field.
Returned value is only valid within the handler. Do not store any references.
返回的值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
GetRespHeaders
Returns the HTTP response headers as a map. Since a header can be set multiple times in a single request, the values of the map are slices of strings containing all the different values of the header.
Returned value is only valid within the handler. Do not store any references.
返回的值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
GetRouteURL
Generates URLs to named routes, with parameters. URLs are relative, for example: “/user/1831”
Returns the hostname derived from the Host HTTP header.
返回从 Host HTTP 标头派生的主机名。
Signature
签名
1
func(c*Ctx)Hostname()string
Example
示例
1
2
3
4
5
6
7
// GET http://google.com/search
app.Get("/",func(c*fiber.Ctx)error{c.Hostname()// "google.com"
// ...
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
typeSomeStructstruct{NamestringAgeuint8}app.Get("/json",func(c*fiber.Ctx)error{// Create data struct:
data:=SomeStruct{Name:"Grame",Age:20,}returnc.JSON(data)// => Content-Type: application/json
// => "{"Name": "Grame", "Age": 20}"
returnc.JSON(fiber.Map{"name":"Grame","age":20,})// => Content-Type: application/json
// => "{"name": "Grame", "age": 20}"
returnc.JSON(fiber.Map{"type":"https://example.com/probs/out-of-credit","title":"You do not have enough credit.","status":403,"detail":"Your current balance is 30, but that costs 50.","instance":"/account/12345/msgs/abc",},"application/problem+json")// => Content-Type: application/problem+json
// => "{
// => "type": "https://example.com/probs/out-of-credit",
// => "title": "You do not have enough credit.",
// => "status": 403,
// => "detail": "Your current balance is 30, but that costs 50.",
// => "instance": "/account/12345/msgs/abc",
// => }"
})
JSONP JSONP
Sends a JSON response with JSONP support. This method is identical to JSON, except that it opts-in to JSONP callback support. By default, the callback name is simply callback.
发送带有 JSONP支持的 JSON 响应。此方法与 JSON 相同,但它启用了 JSONP
Override this by passing a named string in the method.
Returns a string corresponding to the HTTP method of the request: GET, POST, PUT, and so on.
返回一个字符串,该字符串对应于请求的 HTTP 方法: GET 、 POST 、 PUT 等。
Optionally, you could override the method by passing a string.
您可以选择通过传递字符串来覆盖该方法。
Signature
签名
1
func(c*Ctx)Method(override...string)string
Example
示例
1
2
3
4
5
6
7
8
app.Post("/",func(c*fiber.Ctx)error{c.Method()// "POST"
c.Method("GET")c.Method()// GET
// ...
})
MultipartForm
To access multipart form entries, you can parse the binary with MultipartForm(). This returns a map[string][]string, so given a key, the value will be a string slice.
app.Post("/",func(c*fiber.Ctx)error{// Parse the multipart form:
ifform,err:=c.MultipartForm();err==nil{// => *multipart.Form
iftoken:=form.Value["token"];len(token)>0{// Get key value:
fmt.Println(token[0])}// Get all files from "documents" key:
files:=form.File["documents"]// => []*multipart.FileHeader
// Loop through files:
for_,file:=rangefiles{fmt.Println(file.Filename,file.Size,file.Header["Content-Type"][0])// => "tutorial.pdf" 360641 "application/pdf"
// Save the files to disk:
iferr:=c.SaveFile(file,fmt.Sprintf("./%s",file.Filename));err!=nil{returnerr}}}returnerr})
Next
When Next is called, it executes the next method in the stack that matches the current route. You can pass an error struct within the method that will end the chaining and call the error handler.
调用 Next 时,它会执行与当前路由匹配的堆栈中的下一个方法。您可以在方法中传递一个错误结构,该结构将结束链接并调用错误处理程序。
// GET http://example.com/search?q=something
app.Get("/",func(c*fiber.Ctx)error{c.OriginalURL()// "/search?q=something"
// ...
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
Params 参数
Method can be used to get the route parameters, you could pass an optional default value that will be returned if the param key does not exist.
方法可用于获取路由参数,您可以传递一个可选的默认值,如果参数键不存在,则将返回该默认值。
INFO
信息
Defaults to empty string (""), if the param doesn’t exist.
For reasons of downward compatibility, the first parameter segment for the parameter character can also be accessed without the counter.
出于向下兼容性的原因,也可以在没有计数器的情况下访问参数字符的第一个参数段。
Example
示例
1
2
3
app.Get("/v1/*/shop/*",func(c*fiber.Ctx)error{c.Params("*")// outputs the values of the first wildcard segment
})
Returned value is only valid within the handler. Do not store any references.
返回值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置代替。Read more…
阅读更多…
ParamsInt
Method can be used to get an integer from the route parameters. Please note if that parameter is not in the request, zero will be returned. If the parameter is NOT a number, zero and an error will be returned
Defaults to the integer zero (0), if the param doesn’t exist.
如果参数不存在,则默认为整数零 ( 0 )。
Signature
签名
1
func(c*Ctx)ParamsInt(keystring)(int,error)
Example
示例
1
2
3
4
5
6
// GET http://example.com/user/123
app.Get("/user/:id",func(c*fiber.Ctx)error{id,err:=c.ParamsInt("id")// int 123 and no error
// ...
})
This method is equivalent of using atoi with ctx.Params
此方法相当于在 ctx.Params 中使用 atoi
ParamsParser
This method is similar to BodyParser, but for path parameters. It is important to use the struct tag “params”. For example, if you want to parse a path parameter with a field called Pass, you would use a struct field of params:“pass”
// GET http://example.com/user/111
app.Get("/user/:id",func(c*fiber.Ctx)error{param:=struct{IDuint`params:"id"`}{}c.ParamsParser(¶m)// "{"id": 111}"
// ...
})
Path
Contains the path part of the request URL. Optionally, you could override the path by passing a string. For internal redirects, you might want to call RestartRouting instead of Next.
// GET http://example.com/?field1=value1&field1=value2&field2=value3
app.Get("/",func(c*fiber.Ctx)error{m:=c.Queries()m["field1"]// "value2"
m["field2"]// value3
})
Example
示例
1
2
3
4
5
6
7
8
// GET http://example.com/?list_a=1&list_a=2&list_a=3&list_b[]=1&list_b[]=2&list_b[]=3&list_c=1,2,3
app.Get("/",func(c*fiber.Ctx)error{m:=c.Queries()m["list_a"]// "3"
m["list_b[]"]// "3"
m["list_c"]// "1,2,3"
})
Example
示例
1
2
3
4
5
6
7
// GET /api/posts?filters.author.name=John&filters.category.name=Technology
app.Get("/",func(c*fiber.Ctx)error{m:=c.Queries()m["filters.author.name"]// John
m["filters.category.name"]// Technology
})
This property is an object containing a property for each query string parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
Returned value is only valid within the handler. Do not store any references.
返回的值仅在处理程序中有效。不要存储任何引用。
Make copies or use the
制作副本或使用Immutablesetting instead.
设置。Read more…
阅读更多…
QueryBool
This property is an object containing a property for each query boolean parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
Please note if that parameter is not in the request, false will be returned. If the parameter is not a boolean, it is still tried to be converted and usually returned as false.
This property is an object containing a property for each query float64 parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
Please note if that parameter is not in the request, zero will be returned. If the parameter is not a number, it is still tried to be converted and usually returned as 1.
请注意,如果请求中没有该参数,则将返回零。如果该参数不是数字,仍会尝试进行转换,通常返回 1。
INFO
信息
Defaults to the float64 zero (0), if the param doesn’t exist.
This property is an object containing a property for each query integer parameter in the route, you could pass an optional default value that will be returned if the query key does not exist.
Please note if that parameter is not in the request, zero will be returned. If the parameter is not a number, it is still tried to be converted and usually returned as 1.
请注意,如果请求中没有该参数,则将返回零。如果该参数不是数字,仍会尝试进行转换,通常返回 1。
INFO
信息
Defaults to the integer zero (0), if the param doesn’t exist.
This method is similar to BodyParser, but for query parameters. It is important to use the struct tag “query”. For example, if you want to parse a query parameter with a field called Pass, you would use a struct field of query:"pass".
// Field names should start with an uppercase letter
typePersonstruct{Namestring`query:"name"`Passstring`query:"pass"`Products[]string`query:"products"`}app.Get("/",func(c*fiber.Ctx)error{p:=new(Person)iferr:=c.QueryParser(p);err!=nil{returnerr}log.Println(p.Name)// john
log.Println(p.Pass)// doe
log.Println(p.Products)// [shoe, hat]
// ...
})// Run tests with the following curl command
// curl "http://localhost:3000/?name=john&pass=doe&products=shoe,hat"
Range
A struct containing the type and a slice of ranges will be returned.
app.Get("/coffee",func(c*fiber.Ctx)error{returnc.Redirect("/teapot")})app.Get("/teapot",func(c*fiber.Ctx)error{returnc.Status(fiber.StatusTeapot).Send("🍵 short and stout 🍵")})
Redirects back to refer URL. It redirects to fallback URL if refer header doesn’t exists, with specified status, a positive integer that corresponds to an HTTP status code.
Renders a view with data and sends a text/html response. By default Render uses the default Go Template engine. If you want to use another View engine, please take a look at our Template middleware.
使用数据呈现视图并发送 text/html 响应。默认情况下, Render 使用默认的 Go Template 引擎。如果您想使用其他视图引擎,请查看我们的模板中间件。
This method is similar to BodyParser, but for request headers. It is important to use the struct tag “reqHeader”. For example, if you want to parse a request header with a field called Pass, you would use a struct field of reqHeader:"pass".
// Field names should start with an uppercase letter
typePersonstruct{Namestring`reqHeader:"name"`Passstring`reqHeader:"pass"`Products[]string`reqHeader:"products"`}app.Get("/",func(c*fiber.Ctx)error{p:=new(Person)iferr:=c.ReqHeaderParser(p);err!=nil{returnerr}log.Println(p.Name)// john
log.Println(p.Pass)// doe
log.Println(p.Products)// [shoe, hat]
// ...
})// Run tests with the following curl command
// curl "http://localhost:3000/" -H "name: john" -H "pass: doe" -H "products: shoe,hat"
Instead of executing the next method when calling Next, RestartRouting restarts execution from the first method that matches the current route. This may be helpful after overriding the path, i. e. an internal redirect. Note that handlers might be executed again which could result in an infinite loop.
在调用 Next 时,RestartRouting 从匹配当前路由的第一个方法重新开始执行,而不是执行下一个方法。这在覆盖路径后可能会有所帮助,即内部重定向。请注意,处理程序可能会再次执行,这可能会导致无限循环。
funcMyMiddleware()fiber.Handler{returnfunc(c*fiber.Ctx)error{beforeNext:=c.Route().Path// Will be '/'
err:=c.Next()afterNext:=c.Route().Path// Will be '/hello/:name'
returnerr}}
SaveFile
Method is used to save any multipart file to disk.
app.Post("/",func(c*fiber.Ctx)error{// Parse the multipart form:
ifform,err:=c.MultipartForm();err==nil{// => *multipart.Form
// Get all files from "documents" key:
files:=form.File["documents"]// => []*multipart.FileHeader
// Loop through files:
for_,file:=rangefiles{fmt.Println(file.Filename,file.Size,file.Header["Content-Type"][0])// => "tutorial.pdf" 360641 "application/pdf"
// Save the files to disk:
iferr:=c.SaveFile(file,fmt.Sprintf("./%s",file.Filename));err!=nil{returnerr}}returnerr}})
SaveFileToStorage
Method is used to save any multipart file to an external storage system.
storage:=memory.New()app.Post("/",func(c*fiber.Ctx)error{// Parse the multipart form:
ifform,err:=c.MultipartForm();err==nil{// => *multipart.Form
// Get all files from "documents" key:
files:=form.File["documents"]// => []*multipart.FileHeader
// Loop through files:
for_,file:=rangefiles{fmt.Println(file.Filename,file.Size,file.Header["Content-Type"][0])// => "tutorial.pdf" 360641 "application/pdf"
// Save the files to storage:
iferr:=c.SaveFileToStorage(file,fmt.Sprintf("./%s",file.Filename),storage);err!=nil{returnerr}}returnerr}})
Secure
A boolean property that is true , if a TLS connection is established.
一个布尔属性,如果建立了 TLS 连接,则为 true 。
Signature
签名
1
func(c*Ctx)Secure()bool
Example
示例
1
2
// Secure() method is equivalent to:
c.Protocol()=="https"
typeCustomTimetime.Time// String() returns the time in string
func(ct*CustomTime)String()string{t:=time.Time(*ct).String()returnt}// Register the converter for CustomTime type format as 2006-01-02
vartimeConverter=func(valuestring)reflect.Value{fmt.Println("timeConverter",value)ifv,err:=time.Parse("2006-01-02",value);err==nil{returnreflect.ValueOf(v)}returnreflect.Value{}}customTime:=fiber.ParserType{Customtype:CustomTime{},Converter:timeConverter,}// Add setting to the Decoder
fiber.SetParserDecoder(fiber.ParserConfig{IgnoreUnknownKeys:true,ParserType:[]fiber.ParserType{customTime},ZeroEmpty:true,})// Example to use CustomType, you pause custom time format not in RFC3339
typeDemostruct{DateCustomTime`form:"date" query:"date"`Titlestring`form:"title" query:"title"`Bodystring`form:"body" query:"body"`}app.Post("/body",func(c*fiber.Ctx)error{vardDemoc.BodyParser(&d)fmt.Println("d.Date",d.Date.String())returnc.JSON(d)})app.Get("/query",func(c*fiber.Ctx)error{vardDemoc.QueryParser(&d)fmt.Println("d.Date",d.Date.String())returnc.JSON(d)})// curl -X POST -F title=title -F body=body -F date=2021-10-20 http://localhost:3000/body
// curl -X GET "http://localhost:3000/query?title=title&body=body&date=2021-10-20"
SetUserContext
Sets the user specified implementation for context interface.
设置上下文接口的用户指定实现。
Signature
签名
1
func(c*Ctx)SetUserContext(ctxcontext.Context)
Example
示例
1
2
3
4
5
6
7
app.Get("/",func(c*fiber.Ctx)error{ctx:=context.Background()c.SetUserContext(ctx)// Here ctx could be any context implementation
// ...
})
app.Get("/",func(c*fiber.Ctx)error{ctx:=c.UserContext()// ctx is context implementation set by user
// ...
})
Vary
Adds the given header field to the Vary response header. This will append the header, if not already listed, otherwise leaves it listed in the current location.
A Boolean property, that is true, if the request’s X-Requested-With header field is XMLHttpRequest, indicating that the request was issued by a client library (such as jQuery).