ipformat

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 5 Imported by: 0

README

GoDoc

Golang ip Formatting functions

All methods are fairly self explanatory, and reading the godoc page should explain everything. If something isn't clear, open an issue or submit a pull request.

Example

First, ensure the library is installed and up to date by running go get -u github.com/buffalo-news/ipFormat.

package main

import (
	"fmt"

	"github.com/buffalo-news/ipFormat"
)

func main() {
	ip1, _ := ipFormat.New("192.168.0.2/24")
	ip2, _ := ipFormat.New("192.168.0.6")

	ip1, _ = ip1.ToV6()
	ip2, _ = ip2.ToV6()

	fmt.Println(ip1.Address)
	fmt.Println(ip1.CIDR)
	fmt.Println(ip2.Address)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadUserIP

func ReadUserIP(r *http.Request) string

ReadUserIP gets the users IP address from the request @TODO: fix this to handle IPS properly building on logic from https://husobee.github.io/golang/ip-address/2015/12/17/remote-ip-go.html

Types

type IP

type IP struct {
	Address string // Original/full notation passed in
	Parts   []string
	TypeV6  bool
	Range   bool
	CIDR    int64
}

IP details about the IP address

func New

func New(ipString string) (IP, error)

New creates the internal IP struct

func (IP) CompressV6

func (ip IP) CompressV6() (IP, error)

CompressV6 takes all formats of ipv6 and strips them of uneeded characters

func (IP) ToV4 added in v1.1.0

func (ip IP) ToV4() (IP, error)

ToV4 converts ipv6 to ipv4

func (IP) ToV6

func (ip IP) ToV6() (IP, error)

ToV6 converts ipv4 to ipv6

Jump to

Keyboard shortcuts

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