Feat: Fprintf

This commit is contained in:
kayos@tcp.direct 2022-09-23 13:45:54 -07:00
parent 98a80f4427
commit 3139db4896
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
4 changed files with 31 additions and 10 deletions

@ -45,15 +45,22 @@ func TestBlakeEqualAndB64(t *testing.T) {
// sneakin in some code coverage rq dwai nbd
bogusRd, bogusWrt := io.Pipe()
bogusRd2, bogusWrt2 := io.Pipe()
t.Logf("\n")
go func() {
Fprint(io.MultiWriter(bogusWrt, os.Stdout), fmt.Sprintf("[PASS] based[0] = %s\n[PASS] based[1] = %s", string(based[0]), string(based[1])))
Fprint(io.MultiWriter(bogusWrt, os.Stdout), fmt.Sprintf("[PASS] based[0] = %s", string(based[0])))
Fprintf(io.MultiWriter(bogusWrt2, os.Stdout), "\n[PASS] based[1] = %s", string(based[0]))
}()
_ = bogusWrt.CloseWithError(io.ErrClosedPipe)
_ = bogusWrt2.CloseWithError(io.ErrClosedPipe)
_, err := bogusRd.Read([]byte{})
if err == nil {
t.Fatalf("should have been an error...")
}
_, err = bogusRd2.Read([]byte{})
if err == nil {
t.Fatalf("should have been an error...")
}
}
func TestAbs(t *testing.T) {

@ -47,13 +47,13 @@ func RNGUint32() uint32 {
return sharedRand.Uint32()
}
/*RNG returns integer with a maximum amount of 'n' using a global/shared instance of a splitmix64 rng.
/*
RNG returns integer with a maximum amount of 'n' using a global/shared instance of a splitmix64 rng.
- Benchmark_FastRandStr5-24 25205089 47.03 ns/op
- Benchmark_FastRandStr25-24 7113620 169.8 ns/op
- Benchmark_FastRandStr55-24 3520297 340.7 ns/op
- Benchmark_FastRandStr500-24 414966 2837 ns/op
- Benchmark_FastRandStr55555-24 3717 315229 ns/op
*/
func RNG(n int) int {
getSharedRand.Do(func() {

@ -2,14 +2,20 @@ package network
import ipa "inet.af/netaddr"
/*IterateNetRange will ingest:
- an inet.af/netaddr.Range
- an inet.af/netaddr.Prefix
- or a string to be parsed as either of the above options
- examples: (192.168.69.0/24) (192.168.69.0-192.168.69.254)
/*
IterateNetRange will ingest:
then it returns a channel that will stream all the individual netaddr.IP types within the given range or prefix.
if the input is invalid this function will return nil.*/
- an inet.af/netaddr.Range
- an inet.af/netaddr.Prefix
- or a string to be parsed as either of the above options
- examples: (192.168.69.0/24) (192.168.69.0-192.168.69.254)
then it returns a channel that will stream all the individual netaddr.IP types within the given range or prefix.
if the input is invalid this function will return nil.
*/
func IterateNetRange(ips interface{}) chan ipa.IP {
var addrs ipa.IPRange

@ -17,6 +17,14 @@ func Fprint(w io.Writer, s string) {
}
}
// Fprintf is fmt.Fprintf with error handling.
func Fprintf(w io.Writer, format string, items ...any) {
_, err := fmt.Fprintf(w, format, items...)
if err != nil {
log.Error().Str("fmt", format).Err(err).Msg("Fprintf failed!")
}
}
// Abs will give you the positive version of a negative integer, quickly.
func Abs(n int) int {
// ayyee smash 6ros