Skip to content

Commit

Permalink
chore: change interface{} to any (#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickajacks1 committed Jan 14, 2024
1 parent 38b8e74 commit 5941027
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 112 deletions.
6 changes: 3 additions & 3 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,10 @@ func (c *DefaultCtx) Render(name string, bind Map, layouts ...string) error {
return nil
}

func (c *DefaultCtx) renderExtensions(bind interface{}) {
func (c *DefaultCtx) renderExtensions(bind any) {
if bindMap, ok := bind.(Map); ok {
// Bind view map
c.viewBindMap.Range(func(key, value interface{}) bool {
c.viewBindMap.Range(func(key, value any) bool {
keyValue, ok := key.(string)
if !ok {
return true
Expand All @@ -1305,7 +1305,7 @@ func (c *DefaultCtx) renderExtensions(bind interface{}) {
// Check if the PassLocalsToViews option is enabled (by default it is disabled)
if c.app.config.PassLocalsToViews {
// Loop through each local and set it in the map
c.fasthttp.VisitUserValues(func(key []byte, val interface{}) {
c.fasthttp.VisitUserValues(func(key []byte, val any) {
// check if bindMap doesn't contain the key
if _, ok := bindMap[c.app.getString(key)]; !ok {
// Set the key and value in the bindMap
Expand Down
8 changes: 4 additions & 4 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@ func Test_Ctx_JSON(t *testing.T) {
require.Equal(t, `{"Age":20,"Name":"Grame"}`, string(c.Response().Body()))
require.Equal(t, "application/problem+json", string(c.Response().Header.Peek("content-type")))

testEmpty := func(v interface{}, r string) {
testEmpty := func(v any, r string) {
err := c.JSON(v)
require.NoError(t, err)
require.Equal(t, r, string(c.Response().Body()))
Expand All @@ -2713,7 +2713,7 @@ func Test_Ctx_JSON(t *testing.T) {
t.Parallel()

app := New(Config{
JSONEncoder: func(v interface{}) ([]byte, error) {
JSONEncoder: func(v any) ([]byte, error) {
return []byte(`["custom","json"]`), nil
},
})
Expand Down Expand Up @@ -2804,7 +2804,7 @@ func Test_Ctx_JSONP(t *testing.T) {
t.Parallel()

app := New(Config{
JSONEncoder: func(v interface{}) ([]byte, error) {
JSONEncoder: func(v any) ([]byte, error) {
return []byte(`["custom","json"]`), nil
},
})
Expand Down Expand Up @@ -2881,7 +2881,7 @@ func Test_Ctx_XML(t *testing.T) {
t.Parallel()

app := New(Config{
XMLEncoder: func(v interface{}) ([]byte, error) {
XMLEncoder: func(v any) ([]byte, error) {
return []byte(`<custom>xml</custom>`), nil
},
})
Expand Down
6 changes: 3 additions & 3 deletions docs/api/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ agent.BodyStream(strings.NewReader("body=stream"), -1)
JSON sends a JSON request by setting the Content-Type header to the `ctype` parameter. If no `ctype` is passed in, the header is set to `application/json`.

```go title="Signature"
func (a *Agent) JSON(v interface{}, ctype ...string) *Agent
func (a *Agent) JSON(v any, ctype ...string) *Agent
```

```go title="Example"
Expand All @@ -284,7 +284,7 @@ agent.JSON(fiber.Map{"success": true})
XML sends an XML request by setting the Content-Type header to `application/xml`.

```go title="Signature"
func (a *Agent) XML(v interface{}) *Agent
func (a *Agent) XML(v any) *Agent
```

```go title="Example"
Expand Down Expand Up @@ -636,7 +636,7 @@ code, body, errs := agent.String()
Struct returns the status code, bytes body and errors of url. And bytes body will be unmarshalled to given v.
```go title="Signature"
func (a *Agent) Struct(v interface{}) (code int, body []byte, errs []error)
func (a *Agent) Struct(v any) (code int, body []byte, errs []error)
```
```go title="Example"
Expand Down
24 changes: 12 additions & 12 deletions docs/api/ctx.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ It is important to specify the correct struct tag based on the content type to b
| `text/xml` | xml |

```go title="Signature"
func (c *Ctx) BodyParser(out interface{}) error
func (c *Ctx) BodyParser(out any) error
```

```go title="Example"
Expand Down Expand Up @@ -481,7 +481,7 @@ This method is similar to [BodyParser](ctx.md#bodyparser), but for cookie parame
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"`.

```go title="Signature"
func (c *Ctx) CookieParser(out interface{}) error
func (c *Ctx) CookieParser(out any) error
```

```go title="Example"
Expand Down Expand Up @@ -866,7 +866,7 @@ JSON also sets the content header to the `ctype` parameter. If no `ctype` is pas
:::
```go title="Signature"
func (c *Ctx) JSON(data interface{}, ctype ...string) error
func (c *Ctx) JSON(data any, ctype ...string) error
```
```go title="Example"
Expand Down Expand Up @@ -918,7 +918,7 @@ Sends a JSON response with JSONP support. This method is identical to [JSON](ctx
Override this by passing a **named string** in the method.
```go title="Signature"
func (c *Ctx) JSONP(data interface{}, callback ...string) error
func (c *Ctx) JSONP(data any, callback ...string) error
```
```go title="Example"
Expand Down Expand Up @@ -972,7 +972,7 @@ This is useful if you want to pass some **specific** data to the next middleware
:::
```go title="Signature"
func (c *Ctx) Locals(key interface{}, value ...interface{}) interface{}
func (c *Ctx) Locals(key any, value ...any) any
```
```go title="Example"
Expand Down Expand Up @@ -1204,7 +1204,7 @@ This method is equivalent of using `atoi` with ctx.Params
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"
```go title="Signature"
func (c *Ctx) ParamsParser(out interface{}) error
func (c *Ctx) ParamsParser(out any) error
```
```go title="Example"
Expand Down Expand Up @@ -1444,7 +1444,7 @@ This method is similar to [BodyParser](ctx.md#bodyparser), but for query paramet
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"`.
```go title="Signature"
func (c *Ctx) QueryParser(out interface{}) error
func (c *Ctx) QueryParser(out any) error
```
```go title="Example"
Expand Down Expand Up @@ -1593,7 +1593,7 @@ app.Get("/back", func(c fiber.Ctx) error {
Renders a view with data and sends a `text/html` response. By default `Render` uses the default [**Go Template engine**](https://pkg.go.dev/html/template/). If you want to use another View engine, please take a look at our [**Template middleware**](https://docs.gofiber.io/template).
```go title="Signature"
func (c *Ctx) Render(name string, bind interface{}, layouts ...string) error
func (c *Ctx) Render(name string, bind any, layouts ...string) error
```
## Request
Expand All @@ -1617,7 +1617,7 @@ This method is similar to [BodyParser](ctx.md#bodyparser), but for request heade
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"`.
```go title="Signature"
func (c *Ctx) ReqHeaderParser(out interface{}) error
func (c *Ctx) ReqHeaderParser(out any) error
```
```go title="Example"
Expand Down Expand Up @@ -1916,7 +1916,7 @@ Allow you to config BodyParser/QueryParser decoder, base on schema's options, pr
func SetParserDecoder(parserConfig fiber.ParserConfig{
IgnoreUnknownKeys bool,
ParserType []fiber.ParserType{
Customtype interface{},
Customtype any,
Converter func(string) reflect.Value,
},
ZeroEmpty bool,
Expand Down Expand Up @@ -2142,7 +2142,7 @@ app.Get("/", func(c fiber.Ctx) error {
Writef adopts the string with variables
```go title="Signature"
func (c *Ctx) Writef(f string, a ...interface{}) (n int, err error)
func (c *Ctx) Writef(f string, a ...any) (n int, err error)
```
```go title="Example"
Expand Down Expand Up @@ -2197,7 +2197,7 @@ XML also sets the content header to **application/xml**.
:::
```go title="Signature"
func (c *Ctx) XML(data interface{}) error
func (c *Ctx) XML(data any) error
```
```go title="Example"
Expand Down
2 changes: 1 addition & 1 deletion docs/api/middleware/adaptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Converter for net/http handlers to/from Fiber request handlers, special thanks t
| FiberHandlerFunc | `FiberHandlerFunc(h fiber.Handler) http.HandlerFunc` | fiber.Handler -> http.HandlerFunc
| FiberApp | `FiberApp(app *fiber.App) http.HandlerFunc` | Fiber app -> http.HandlerFunc
| ConvertRequest | `ConvertRequest(c fiber.Ctx, forServer bool) (*http.Request, error)` | fiber.Ctx -> http.Request
| CopyContextToFiberContext | `CopyContextToFiberContext(context interface{}, requestContext *fasthttp.RequestCtx)` | context.Context -> fasthttp.RequestCtx
| CopyContextToFiberContext | `CopyContextToFiberContext(context any, requestContext *fasthttp.RequestCtx)` | context.Context -> fasthttp.RequestCtx

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/api/middleware/recover.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ app.Get("/", func(c fiber.Ctx) error {
|:------------------|:--------------------------------|:--------------------------------------------------------------------|:-------------------------|
| Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
| EnableStackTrace | `bool` | EnableStackTrace enables handling stack trace. | `false` |
| StackTraceHandler | `func(fiber.Ctx, interface{})` | StackTraceHandler defines a function to handle stack trace. | defaultStackTraceHandler |
| StackTraceHandler | `func(fiber.Ctx, any)` | StackTraceHandler defines a function to handle stack trace. | defaultStackTraceHandler |

## Default Config

Expand Down
8 changes: 4 additions & 4 deletions docs/api/middleware/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ This middleware uses our [Storage](https://github.com/gofiber/storage) package t

```go
func New(config ...Config) *Store
func (s *Store) RegisterType(i interface{})
func (s *Store) RegisterType(i any)
func (s *Store) Get(c fiber.Ctx) (*Session, error)
func (s *Store) Delete(id string) error
func (s *Store) Reset() error

func (s *Session) Get(key string) interface{}
func (s *Session) Set(key string, val interface{})
func (s *Session) Get(key string) any
func (s *Session) Set(key string, val any)
func (s *Session) Delete(key string)
func (s *Session) Destroy() error
func (s *Session) Reset() error
Expand All @@ -33,7 +33,7 @@ func (s *Session) SetExpiry(exp time.Duration)
```

:::caution
Storing `interface{}` values are limited to built-ins Go types.
Storing `any` values are limited to built-ins Go types.
:::

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Fiber provides a Views interface to provide your own template engine:
```go
type Views interface {
Load() error
Render(io.Writer, string, interface{}, ...string) error
Render(io.Writer, string, any, ...string) error
}
```
</TabItem>
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type (
Error bool
FailedField string
Tag string
Value interface{}
Value any
}

XValidator struct {
Expand All @@ -53,7 +53,7 @@ type (
// for more information see: https://github.com/go-playground/validator
var validate = validator.New()

func (v XValidator) Validate(data interface{}) []ErrorResponse {
func (v XValidator) Validate(data any) []ErrorResponse {
validationErrors := []ErrorResponse{}

errs := validate.Struct(data)
Expand Down
2 changes: 1 addition & 1 deletion docs/partials/routing/handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app.Post("/api/register", func(c fiber.Ctx) error {
**Use** can be used for middleware packages and prefix catchers. These routes will only match the beginning of each path i.e. `/john` will match `/john/doe`, `/johnnnnn` etc

```go title="Signature"
func (app *App) Use(args ...interface{}) Router
func (app *App) Use(args ...any) Router
```

```go title="Examples"
Expand Down
Loading

0 comments on commit 5941027

Please sign in to comment.