commontypes

package module
v0.0.0-...-99c65ab Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 8 Imported by: 7

README

Commontypes

I've found I'm always manually creating these types in various projects, so rather than continuing to do them by hand every single time, I'm going to dump them up here and import them.

Have included (Unm|M)arshalText and (Unm|M)arshalJSON for all types for convenient loading from configuration files/json blobs.

Types

network.go

Network and Networks - used for creating ip whitelists/blacklists

url.go

Not as often used as Network/Networks but still useful

duration.go

time.Duration wrapper - Everyone has written ths one before

keyfile.go

loading key files as string or referenced file://, read only - really

TODO

  • Documentation
  • Write tests
  • Add more

Copyright 2016 Shannon Wynter

Licensed under The MIT License

Documentation

Overview

Package commontypes provides the few types I'm always creating for various projects. I've decided that rather than continuing to do them by hand every single time, I'm going to dump them up here and import them.

Have included (Unm|M)arshalText and (Unm|M)arshalJSON for all types for convenient loading from configuration files/json blobs.

Index

Constants

This section is empty.

Variables

View Source
var PrivateNetworks = Networks{
	Network{&net.IPNet{IP: net.IP{0, 0, 0, 0}, Mask: net.IPMask{255, 0, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{10, 0, 0, 0}, Mask: net.IPMask{255, 0, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{100, 64, 0, 0}, Mask: net.IPMask{255, 192, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{127, 0, 0, 0}, Mask: net.IPMask{255, 0, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{172, 16, 0, 0}, Mask: net.IPMask{255, 240, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{192, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 0}}},
	Network{&net.IPNet{IP: net.IP{192, 0, 2, 0}, Mask: net.IPMask{255, 255, 255, 0}}},
	Network{&net.IPNet{IP: net.IP{192, 88, 99, 0}, Mask: net.IPMask{255, 255, 255, 0}}},
	Network{&net.IPNet{IP: net.IP{192, 168, 0, 0}, Mask: net.IPMask{255, 255, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{198, 18, 0, 0}, Mask: net.IPMask{255, 254, 0, 0}}},
	Network{&net.IPNet{IP: net.IP{198, 51, 100, 0}, Mask: net.IPMask{255, 255, 255, 0}}},
	Network{&net.IPNet{IP: net.IP{203, 0, 113, 0}, Mask: net.IPMask{255, 255, 255, 0}}},
}

PrivateNetworks is a list of commonly defined private networks most useful for figuring out if a private ip address has been provided

Functions

This section is empty.

Types

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (*Duration) Unmarshal

func (d *Duration) Unmarshal(s string) (err error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type IP

type IP struct {
	net.IP
}

func (*IP) IsUnspecified

func (i *IP) IsUnspecified() bool

func (*IP) MarshalJSON

func (i *IP) MarshalJSON() ([]byte, error)

func (*IP) MarshalText

func (i *IP) MarshalText() ([]byte, error)

func (*IP) UnmarshalJSON

func (i *IP) UnmarshalJSON(data []byte) error

func (*IP) UnmarshalTOML

func (i *IP) UnmarshalTOML(text []byte) error

func (*IP) UnmarshalText

func (i *IP) UnmarshalText(text []byte) error

type KeyFile

type KeyFile struct {
	// contains filtered or unexported fields
}

func (*KeyFile) Bytes

func (f *KeyFile) Bytes() []byte

func (*KeyFile) MarshalJSON

func (f *KeyFile) MarshalJSON() ([]byte, error)

func (*KeyFile) MarshalText

func (f *KeyFile) MarshalText() ([]byte, error)

func (*KeyFile) Unmarshal

func (f *KeyFile) Unmarshal(s string) error

func (*KeyFile) UnmarshalJSON

func (f *KeyFile) UnmarshalJSON(data []byte) error

func (*KeyFile) UnmarshalText

func (f *KeyFile) UnmarshalText(text []byte) error

type Network

type Network struct {
	*net.IPNet
}

func (*Network) MarshalJSON

func (n *Network) MarshalJSON() ([]byte, error)

func (*Network) MarshalText

func (n *Network) MarshalText() ([]byte, error)

func (*Network) Unmarshal

func (n *Network) Unmarshal(s string) (err error)

func (*Network) UnmarshalJSON

func (n *Network) UnmarshalJSON(data []byte) error

func (*Network) UnmarshalTOML

func (n *Network) UnmarshalTOML(text []byte) error

func (*Network) UnmarshalText

func (n *Network) UnmarshalText(text []byte) error

type Networks

type Networks []Network

func (*Networks) Contains

func (n *Networks) Contains(ip net.IP) bool

func (*Networks) Empty

func (n *Networks) Empty() bool

type Regexp

type Regexp struct {
	*regexp.Regexp
}

func (*Regexp) MarshalJSON

func (r *Regexp) MarshalJSON() ([]byte, error)

func (*Regexp) MarshalText

func (r *Regexp) MarshalText() ([]byte, error)

func (*Regexp) Unmarshal

func (r *Regexp) Unmarshal(s string) (err error)

func (*Regexp) UnmarshalJSON

func (r *Regexp) UnmarshalJSON(data []byte) error

func (*Regexp) UnmarshalTOML

func (r *Regexp) UnmarshalTOML(text []byte) error

func (*Regexp) UnmarshalText

func (r *Regexp) UnmarshalText(text []byte) error

type Regexps

type Regexps []Regexp

func (*Regexps) Match

func (r *Regexps) Match(b []byte) bool

func (*Regexps) MatchString

func (r *Regexps) MatchString(s string) bool

type URL

type URL struct {
	*url.URL
}

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

func (URL) MarshalTOML

func (u URL) MarshalTOML() (interface{}, error)

func (*URL) MarshalText

func (u *URL) MarshalText() ([]byte, error)

func (*URL) Unmarshal

func (u *URL) Unmarshal(s string) (err error)

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

func (*URL) UnmarshalTOML

func (u *URL) UnmarshalTOML(text []byte) error

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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