remoteaddr

package module
v0.0.0-...-94dd5d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-remoteaddr

get remote addr from http.Request

package main

import (
    "github.com/9glt/go-remoteaddr"
    "net/http"
    "fmt"
)

func main() {
    request, _ := http.NewRequest("GET", "/path", nil)
    request.Header.Set("X-Forwarded-For", "192.168.100.100")
    request.Header.Set("X-Real-IP", "192.168.100.100")
    request.RemoteAddr = "127.0.0.1:123123"
    
    addr := remoteaddr.IP(request, []string{"proxy-ip-address1","proxy-ip-addres2"})
    fmt.Printf("%+v", addr)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

type Addr struct {
	IP          string
	XForIP      string
	XRealIP     string
	BehindProxy bool
}

func IP

func IP(r *http.Request, proxies []string, depth int) Addr

IP takes *http.Request, proxies ips and depth - how many proxies before my app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL