- fix security arbitrary path - fix linter Package AWS: - implement resolver v2 Package Cobra: - fix linter Package Config/component: - fix linter Package Context/Config: - Add function to set context Package Database/KV...: - Fix error - Fix collision pointer - Fix models - Fix circular dependencies - Add function Delete on driver, table and item - Add function new on drvier to prevent collision data when create item on table get / walk Package Duration: - Add type Duration based on time.Duration to allow transform duration to string instead of int64 nanosecond - Add function to parse in json, yaml, toml, text, cbor - Add function to allow convert type into mapstructure (spf13 viper, cobra...) Package File/Perm: - Add type Perm based on os.FileMode to allow marshall / unmashall it into octal form instead of string representation (-rwxrwxrwx) - Add function to marshall / unmarshall in json, yaml, toml, text, cbor - Add function to allow convert type into mapstructure (spf13 viper, cobra...) Package File/progress: - Fix linter Package HTTPServer : - Fix linter - Fix security by adding a default value if not set on config Package ioutils: - Fix Linter Package LDAP: - Add Clone function Package logger/hookfile: - Fix linter Package nats: - Fix linter Package Network/Protocol: - Fix bug with quote / Dbl Quote on unmarshall Package Password: - Replace password with crypto rand instead of math rand Package Size: - Fix potential overflow - Add function to format value into Int32, Int, Uint32, Uint, Float32 - Add function to parse Float64 into type Size Package Socket: - change config uint32 to golib Size, time.Duration to golib Duration - add TLS managment to server TCP, discard for UDP & Unix file Local Domain - add function Info Server to print information of server when listen is starting
Network package
This package is useful to retrieve network interface information and counter.
The information available are :
nameof the interface (cannot be empty)physicaladdress (or hardware address) (can be empty for example virtual ip or bridge)MTU(Maximu Transmission Unit) is the maximum size of packets could be transmitAddris the list of all network address (can be empty)Indexis the index for the current interface into the list all interface for current osFlagsare capabilities supported by the interface. You can find const for all flags available in golang/x/net package :FlagUp: interface is upFlagBroadcast: interface supports broadcast access capabilityFlagLoopback: interface is a loopback interfaceFlagPointToPoint: interface belongs to a point-to-point linkFlagMulticast: interface supports multicast access capability
Example of implement
You can get all interface with filter.
In this example we will search all interface who's have physical address and having at least on address =and match the list of flags composed here with only FlagUp :
// GetAllInterfaces(context.Context, onlyPhysical, hasAddr bool, atLeastMTU int, withFlags ...net.Flags)
list, err := network.GetAllInterfaces(context.Background(), true, true, 0, net.FlagUp)
You can also retrieve on interface based on his name or his phyisical address :
//NewInterface(context.Context, name, physical string)
i, e := NewInterface(context.Context, "eth0", "")
When you have you interface variable, you can use it to print for example the counter of received data.
The available statistics are grouped by way : In or Out In each group, the stats are :
StatBytes: Traffic in BytesStatPackets: Number of PacketsStatFifo: Number of packet in FIFOStatDrop: Number of packet droppedStatErr: Number of packet in Error
Stats are given as map[Stats]Number :
Statsis a self defined to map constant with a statement.Numberare still self defined type to allow formatting.Bytesis closed similar to Number but with different unit
This translation between bytes and number included into each type :
Number.AsBytesBytes.AsNumber
You can also convert this type as uint64 or as float64.
Now, we have all information to understand this example who's print all stat of sending traffic with unit :
fmt.Print("\tOut: \n")
l = i.GetStatOut()
for _, k := range network.ListStatsSort() {
s := network.Stats(k)
if v, ok := l[s]; ok {
fmt.Printf("\t\t%s\n", s.FormatLabelUnitPadded(v))
} else {
fmt.Printf("\t\t%s\n", s.FormatLabelUnitPadded(0))
}
}
Example
You can find an example in test/test-network
There result of this example is like this :
iface 'eth0' [00:15:5d:66:60:dd] :
Flags: up broadcast multicast
Addrs: {"addr":"172.25.59.95/20"} {"addr":"fe80::215:5dff:fe66:60dd/64"}
In:
Traffic: 27.33 GB
Packets: 20 M
Fifo: 0
Drop: 0
Error: 0
Out:
Traffic: 28.03 GB
Packets: 1118 K
Fifo: 0
Drop: 0
Error: 0