Skip to content

3JoB/atreugo-realip

 
 

Repository files navigation

Atreugo RealIP

Realip library adapted for Atreugo.

License Build

Example

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)
	}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.4%
  • Makefile 1.6%