macs

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 3 Imported by: 0

README

github.com/cdzombak/macs

Golang MAC addresses & MAC address set which support JSON [un]marshaling.

Documentation: pkg.go.dev/github.com/cdzombak/macs

Installation

go get github.com/cdzombak/macs

License

MIT; see LICENSE in this repo.

Author

Chris Dzombak

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

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

Addr is a hardware/MAC address which supports JSON [un]marshaling.

func AddrFromNet

func AddrFromNet(addr net.HardwareAddr) *Addr

AddrFromNet creates an Addr from a net.HardwareAddr.

func MustParseMAC

func MustParseMAC(mac string) *Addr

MustParseMAC parses the given string to an Addr, or panics if parsing fails.

func ParseMAC

func ParseMAC(mac string) (*Addr, error)

ParseMAC parses the given string to an Addr, returning an error if parsing fails.

func (*Addr) Equals

func (a *Addr) Equals(other *Addr) bool

Equals returns true if the MAC address is equal to the given MAC address.

func (*Addr) IsZeroValue

func (a *Addr) IsZeroValue() bool

IsZeroValue returns true if the MAC address is the zero value.

func (*Addr) MarshalJSON

func (a *Addr) MarshalJSON() ([]byte, error)

MarshalJSON marshals the MAC address to JSON.

func (*Addr) NetHardwareAddr

func (a *Addr) NetHardwareAddr() net.HardwareAddr

NetHardwareAddr returns the MAC address as a net.HardwareAddr.

func (*Addr) String

func (a *Addr) String() string

String returns the string representation of the MAC address.

func (*Addr) UnmarshalJSON

func (a *Addr) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals the MAC address from JSON.

type Set

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

Set is a (non-concurrency-safe!) set of MAC addresses which supports [un]marshaling to/from a JSON array.

func EmptySet

func EmptySet() *Set

EmptySet returns a new empty set.

func Intersection

func Intersection(s1, s2 *Set) *Set

Intersection returns a new set containing the intersection of the two given sets.

func Union

func Union(s1, s2 *Set) *Set

Union returns a new set containing the union of the two given sets.

func (*Set) Add

func (s *Set) Add(mac *Addr)

Add adds the given MAC address to the set.

func (*Set) AddAllFrom

func (s *Set) AddAllFrom(other *Set)

AddAllFrom adds all MAC addresses from the given set to this set.

func (*Set) All

func (s *Set) All() []*Addr

All returns a slice of all MAC addresses in the set.

func (*Set) Contains

func (s *Set) Contains(mac *Addr) bool

Contains returns true if the set contains the given MAC address.

func (*Set) Len

func (s *Set) Len() int

Len returns the number of MAC addresses in the set.

func (*Set) MarshalJSON

func (s *Set) MarshalJSON() ([]byte, error)

MarshalJSON marshals the set to a JSON array of strings.

func (*Set) Remove

func (s *Set) Remove(mac *Addr)

Remove removes the given MAC address from the set.

func (*Set) UnmarshalJSON

func (s *Set) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a JSON array of strings into the set.

Jump to

Keyboard shortcuts

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