[file/bandwidth] - ADD documentation: add enhanced README and TESTING guidelines - ADD tests: complete test suites with benchmarks, concurrency, and edge cases [file/perm] - ADD documentation: add enhanced README and TESTING guidelines - ADD tests: complete test suites with benchmarks, concurrency, and edge cases - ADD function to parse form "rwx-wxr-x" or "-rwx-w-r-x" - ADD function to ParseFileMode to convert os.FileMode to file.Perm [file/progress] - ADD documentation: add enhanced README and TESTING guidelines - ADD tests: complete test suites with benchmarks, concurrency, and edge cases [ioutils/...] - UPDATE documentation: update enhanced README and TESTING guidelines - UPDATE tests: complete test suites with benchmarks, concurrency, and edge cases [logger/...] - UPDATE documentation: update enhanced README and TESTING guidelines - ADD documentation: add enhanced README and TESTING guidelines for sub packages - UPDATE tests: complete test suites with benchmarks, concurrency, and edge cases - UPDATE config: remove FileBufferSize from OptionFile (rework hookfile) - UPDATE fields: expose Store function in interface - REWORK hookfile: rework package, use aggregator to allow multi write and single file - FIX hookstderr: fix bug with NonColorable - FIX hookstdout: fix bug with NonColorable - FIX hookwriter: fix bug with NonColorable [network/protocol] - ADD function IsTCP, IsUDP, IsUnixLike to check type of protocol [runner] - FIX typo [socket] - UPDATE documentation: update enhanced README and TESTING guidelines - ADD documentation: add enhanced README and TESTING guidelines for sub packages - UPDATE tests: complete test suites with benchmarks, concurrency, and edge cases - REWORK server: use context compatible io.reader, io.writer, io.closer instead of reader / writer - REWORK server: simplify, optimize server - REMOVE reader, writer type - ADD context: add new interface in root socket interface to expose context interface that extend context, io reader/writer/closer, dediacted function to server (IsConnected, ...)
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