GetReqHeader returns the HTTP request header specified by filed. This function is generic and can handle different headers type values. If the generic type cannot be matched to a supported type, the function returns the default value (if provided) or the zero value of type V.
(c Ctx, key string, defaultValue ...V)
| 478 | // If the generic type cannot be matched to a supported type, the function |
| 479 | // returns the default value (if provided) or the zero value of type V. |
| 480 | func GetReqHeader[V GenericType](c Ctx, key string, defaultValue ...V) V { |
| 481 | v, err := genericParseType[V](c.App().toString(c.Request().Header.Peek(key))) |
| 482 | if err != nil && len(defaultValue) > 0 { |
| 483 | return defaultValue[0] |
| 484 | } |
| 485 | return v |
| 486 | } |
| 487 | |
| 488 | // GetHeaders (a.k.a GetReqHeaders) returns the HTTP request headers. |
| 489 | // Returned value is only valid within the handler. Do not store any references. |