Realip library adapted for Atreugo.
package main
import (
"fmt"
"github.com/savsgio/atreugo/v11"
"github.com/3JoB/atreugo-realip"
)
func main() {
config := atreugo.Config{
Addr: "0.0.0.0:8000",
}
server := atreugo.New(config)
server.GET("/", func(ctx *atreugo.RequestCtx) error {
return ctx.TextResponse(fmt.Printf("Your Client IP is: %s", realip.FromRequest(ctx)))
})
server.GET("/cf", func(ctx *atreugo.RequestCtx) error {
// realip.County Only available on Cloudflare.
// If you need other ways to determine the country,
// you need to access the IP database yourself.
return ctx.TextResponse(fmt.Printf("Your Client IP is: %s, from %s", realip.FromRequest(ctx), realip.County(ctx)))
})
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}