Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 697 Bytes

README.md

File metadata and controls

40 lines (27 loc) · 697 Bytes

go-realip-in-context

Reads Real IP from request and saves in context.

We use realip to find the client's real IP, then we save it to context. That allow us to get the client's IP in app code that doesn't have access to the request, only the context.

We expose a middleware and a function.

Usage

Examples use go-chi.

package main

import (
  // ...
  "github.com/nrfta/go-realip-in-context"
)

// ...
router := chi.NewRouter()

router.Use(realip.Middleware)
// ...
func something(ctx context.Context) {
  ip := realip.GetRealIP(ctx)

  fmt.Println(ip)
}

License

This project is licensed under the MIT License.