res_interface_gen.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Code generated by ifacemaker; DO NOT EDIT.
  2. package fiber
  3. import (
  4. "bufio"
  5. "io"
  6. "github.com/valyala/fasthttp"
  7. )
  8. // Res is an interface for response-related Ctx methods.
  9. type Res interface {
  10. // App returns the *App reference to the instance of the Fiber application
  11. App() *App
  12. // Append the specified value to the HTTP response header field.
  13. // If the header is not already set, it creates the header with the specified value.
  14. Append(field string, values ...string)
  15. // Attachment sets the HTTP response Content-Disposition header field to attachment.
  16. Attachment(filename ...string)
  17. // ClearCookie expires a specific cookie by key on the client side.
  18. // If no key is provided it expires all cookies that came with the request.
  19. ClearCookie(key ...string)
  20. // RequestCtx returns *fasthttp.RequestCtx that carries a deadline
  21. // a cancellation signal, and other values across API boundaries.
  22. RequestCtx() *fasthttp.RequestCtx
  23. // Cookie sets a cookie by passing a cookie struct.
  24. Cookie(cookie *Cookie)
  25. // Download transfers the file from path as an attachment.
  26. // Typically, browsers will prompt the user for download.
  27. // By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog).
  28. // Override this default with the filename parameter.
  29. Download(file string, filename ...string) error
  30. // Response return the *fasthttp.Response object
  31. // This allows you to use all fasthttp response methods
  32. // https://godoc.org/github.com/valyala/fasthttp#Response
  33. Response() *fasthttp.Response
  34. // Format performs content-negotiation on the Accept HTTP header.
  35. // It uses Accepts to select a proper format and calls the matching
  36. // user-provided handler function.
  37. // If no accepted format is found, and a format with MediaType "default" is given,
  38. // that default handler is called. If no format is found and no default is given,
  39. // StatusNotAcceptable is sent.
  40. Format(handlers ...ResFmt) error
  41. // AutoFormat performs content-negotiation on the Accept HTTP header.
  42. // It uses Accepts to select a proper format.
  43. // The supported content types are text/html, text/plain, application/json, application/xml, application/vnd.msgpack, and application/cbor.
  44. // When text/html is selected, the body is treated as plain text and HTML-escaped before being wrapped in a <p> element.
  45. // For more flexible content negotiation, use Format.
  46. // If the header is not specified or there is no proper format, text/plain is used.
  47. AutoFormat(body any) error
  48. // Get (a.k.a. GetRespHeader) returns the HTTP response header specified by field.
  49. // Field names are case-insensitive
  50. // Returned value is only valid within the handler. Do not store any references.
  51. // Make copies or use the Immutable setting instead.
  52. Get(key string, defaultValue ...string) string
  53. // GetHeaders (a.k.a GetRespHeaders) returns the HTTP response headers.
  54. // Returned value is only valid within the handler. Do not store any references.
  55. // Make copies or use the Immutable setting instead.
  56. GetHeaders() map[string][]string
  57. // JSON converts any interface or string to JSON.
  58. // Array and slice values encode as JSON arrays,
  59. // except that []byte encodes as a base64-encoded string,
  60. // and a nil slice encodes as the null JSON value.
  61. // If the ctype parameter is given, this method will set the
  62. // Content-Type header equal to ctype. If ctype is not given,
  63. // The Content-Type header will be set to application/json; charset=utf-8.
  64. JSON(data any, ctype ...string) error
  65. // MsgPack converts any interface or string to MessagePack encoded bytes.
  66. // If the ctype parameter is given, this method will set the
  67. // Content-Type header equal to ctype. If ctype is not given,
  68. // The Content-Type header will be set to application/vnd.msgpack.
  69. MsgPack(data any, ctype ...string) error
  70. // CBOR converts any interface or string to CBOR encoded bytes.
  71. // If the ctype parameter is given, this method will set the
  72. // Content-Type header equal to ctype. If ctype is not given,
  73. // The Content-Type header will be set to application/cbor.
  74. CBOR(data any, ctype ...string) error
  75. // JSONP sends a JSON response with JSONP support.
  76. // This method is identical to JSON, except that it opts-in to JSONP callback support.
  77. // By default, the callback name is simply callback.
  78. JSONP(data any, callback ...string) error
  79. // XML converts any interface or string to XML.
  80. // This method also sets the content header to application/xml; charset=utf-8.
  81. XML(data any) error
  82. // Links joins the links followed by the property to populate the response's Link HTTP header field.
  83. Links(link ...string)
  84. // Location sets the response Location HTTP header to the specified path parameter.
  85. Location(path string)
  86. // OriginalURL contains the original request URL.
  87. // Returned value is only valid within the handler. Do not store any references.
  88. // Make copies or use the Immutable setting to use the value outside the Handler.
  89. OriginalURL() string
  90. // Redirect returns the Redirect reference.
  91. // Use Redirect().Status() to set custom redirection status code.
  92. // If status is not specified, status defaults to 303 See Other.
  93. // You can use Redirect().To(), Redirect().Route() and Redirect().Back() for redirection.
  94. Redirect() *Redirect
  95. // ViewBind Add vars to default view var map binding to template engine.
  96. // Variables are read by the Render method and may be overwritten.
  97. ViewBind(vars Map) error
  98. // getLocationFromRoute get URL location from route using parameters
  99. getLocationFromRoute(route *Route, params Map) (string, error)
  100. // GetRouteURL generates URLs to named routes, with parameters. URLs are relative, for example: "/user/1831"
  101. GetRouteURL(routeName string, params Map) (string, error)
  102. // Render a template with data and sends a text/html response.
  103. // We support the following engines: https://github.com/gofiber/template
  104. Render(name string, bind any, layouts ...string) error
  105. renderExtensions(bind any)
  106. // Send sets the HTTP response body without copying it.
  107. // From this point onward the body argument must not be changed.
  108. Send(body []byte) error
  109. // SendEarlyHints allows the server to hint to the browser what resources a page would need
  110. // so the browser can preload them while waiting for the server's full response. Only Link
  111. // headers already written to the response will be transmitted as Early Hints.
  112. //
  113. // This is a HTTP/2+ feature but all browsers will either understand it or safely ignore it.
  114. //
  115. // NOTE: Older HTTP/1.1 non-browser clients may face compatibility issues.
  116. //
  117. // See: https://developer.chrome.com/docs/web-platform/early-hints and
  118. // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Link#syntax
  119. SendEarlyHints(hints []string) error
  120. // SendFile transfers the file from the specified path.
  121. // By default, the file is not compressed. To enable compression, set SendFile.Compress to true.
  122. // The Content-Type response HTTP header field is set based on the file's extension.
  123. // If the file extension is missing or invalid, the Content-Type is detected from the file's format.
  124. SendFile(file string, config ...SendFile) error
  125. // SendStatus sets the HTTP status code and if the response body is empty,
  126. // it sets the correct status message in the body.
  127. SendStatus(status int) error
  128. // SendString sets the HTTP response body for string types.
  129. // This means no type assertion, recommended for faster performance
  130. SendString(body string) error
  131. // SendStream sets response body stream and optional body size.
  132. SendStream(stream io.Reader, size ...int) error
  133. // SendStreamWriter sets response body stream writer
  134. SendStreamWriter(streamWriter func(*bufio.Writer)) error
  135. // Set sets the response's HTTP header field to the specified key, value.
  136. Set(key, val string)
  137. setCanonical(key, val string)
  138. // Status sets the HTTP status for the response.
  139. // This method is chainable.
  140. Status(status int) Ctx
  141. // Type sets the Content-Type HTTP header to the MIME type specified by the file extension.
  142. Type(extension string, charset ...string) Ctx
  143. // Vary adds the given header field to the Vary response header.
  144. // This will append the header, if not already listed; otherwise, leaves it listed in the current location.
  145. Vary(fields ...string)
  146. // Write appends p into response body.
  147. Write(p []byte) (int, error)
  148. // Writef appends f & a into response body writer.
  149. Writef(f string, a ...any) (int, error)
  150. // WriteString appends s to response body.
  151. WriteString(s string) (int, error)
  152. // Release is a method to reset Res fields when to use ReleaseCtx()
  153. release()
  154. // Drop closes the underlying connection without sending any response headers or body.
  155. // This can be useful for silently terminating client connections, such as in DDoS mitigation
  156. // or when blocking access to sensitive endpoints.
  157. Drop() error
  158. // End immediately flushes the current response and closes the underlying connection.
  159. //
  160. // Note: End does not work when using streaming (e.g. fasthttp's HijackConn or SendStream),
  161. // because in streaming mode the connection is managed asynchronously and ctx.Conn() may return nil.
  162. End() error
  163. }