remoteaddr

package
v0.0.0-...-56ccf34 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2017 License: MIT Imports: 1 Imported by: 0

README

RemoteAddr Middleware

RemoteAddr provides middleware for sanitizing the RemoteAddr based on other possible headers.

Install

go get github.com/syntaqx/echo-middleware/remoteaddr

Getting Started

Here's a simple example application using remoteaddr and Echo. Save this file as main.go

package main

import (
    "net/http"

    "github.com/labstack/echo"
    "github.com/syntaqx/echo-middleware/remoteaddr"
)

func main() {
    e := echo.New()

    e.Use(remoteaddr.New().Handler)

    e.Get("/", func(c *echo.Context) error {
        return c.HTML(http.StatusOK, c.Request().RemoteAddr)
    })

    e.Run(":8080")
}

Then, run your server:

go run main.go

The server now runs on localhost:8080

$ curl -D - -H 'Origin: http://localhost' http://localhost:8080/

You should recieve a response giving you back your IP address (which, in this case will either be 127.0.0.1 or ::1). Now you can use that value safely, knowing it's being looked after!

Documentation

Index

Constants

View Source
const (
	TrueClientIP   = "True-Client-IP"   // Edge providers (such as Akamai)
	TrueRealIP     = "True-Real-IP"     // Proxies (like Nginx)
	XForwardedFor  = "X-Forwarded-For"  // External proxies (like an ELB or router)
	XOriginatingIP = "X-Originating-IP" // Defacto email header
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RemoteAddr

type RemoteAddr struct {
}

RemoteAddr http handler

func New

func New() *RemoteAddr

New creates a new RemoteAddr handler

func (*RemoteAddr) Handler

func (ra *RemoteAddr) Handler(h http.Handler) http.Handler

Handler provides a http.HandlerFunc interface

func (*RemoteAddr) HandlerFunc

func (ra *RemoteAddr) HandlerFunc(w http.ResponseWriter, r *http.Request)

HandlerFunc provides a Martini compatible handler interface

func (*RemoteAddr) ServeHTTP

func (ra *RemoteAddr) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP provides a Negroni compatible interface

Jump to

Keyboard shortcuts

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