checking in some WIP

* added some netx funcs
* added netx/dnsx
* currently updating docs and adding *x funcs to sprigx
This commit is contained in:
brent saner
2026-02-24 17:41:57 -05:00
parent 4770052b52
commit c6fc692f5e
14 changed files with 2773 additions and 646 deletions

View File

@@ -17,6 +17,9 @@ Last rendered {localdatetime}
// BEGIN variable attributes
:sprig_ver: 3
:psutil_ver: 4
:git_owner: r00t2
:git_repo: go_goutils
:git_repo_full: {git_owner}/{git_repo}
:mod_me: r00t2.io/goutils
:pkg_me: tplx/sprigx
:src_root: https://git.r00t2.io
@@ -25,8 +28,12 @@ Last rendered {localdatetime}
:mod_sprig: github.com/Masterminds/sprig/v{sprig_ver}
:mod_psutil: github.com/shirou/gopsutil/v{psutil_ver}
:import_sprig: {mod_sprig}
:src_base: {src_root}/r00t2/go_goutils/src/branch/master
:src_dir: {src_base}/{pkg_me}
:src_base: {src_root}/{git_repo_full}
:src_git: {src_base}.git
:src_tree: {src_base}/src/branch/master
:src_raw: {src_base}/raw/branch/master
:src_dir: {src_tree}/{pkg_me}
:src_dir_raw: {src_raw}/{pkg_me}
:import_me: {mod_me}/{pkg_me}
:godoc_me: {godoc_root}/{import_me}
:godoc_sprig: {godoc_root}/{import_sprig}
@@ -42,11 +49,57 @@ They provide functions that offer more enriched use cases and domain-specific da
====
If you are reading this README on the Go Module Directory documentation ({godoc_me})
or the directory landing page ({src_dir}), it may not render correctly.
Anchor-links (links within this document to other sections of this document) will likely also not work.
Be sure to view it at properly via {src_dir}/README.adoc[the AsciiDoc rendering^]
or by downloading and viewing the {src_dir}/README.html[HTML version^] and/or {src_dir}/README.pdf[PDF version^].
Be sure to view it at properly via {src_dir}/README.adoc[the in-repo AsciiDoc rendering^]
or by downloading and viewing the {src_dir_raw}/README.html[HTML version^] in a browser locally
and/or <<rndr_pdf, rendering a PDF version>>.
====
[id="rndr"]
== How do I Render These Docs?
This documentation is written in https://asciidoc.org/[AsciiDoc^] (with https://asciidoctor.org/[AsciiDoctor^] extensions).
To re-render all docs (including <<rndr_pdf>>):
[source,bash, subs="attributes"]
----
git clone {src_git}
cd {git_repo}
.githooks/pre-commit/01-docgen
----
[id="rndr_html"]
=== HTML
HTML output is re-rendered and included in git {src_dir}/.githooks/pre-commit/01-docgen[on each commit^] automatically (via https://github.com/gabyx/Githooks[`github:gabyx/Githooks`^])
but can be re-rendered on-demand locally via:
[source,bash, subs="attributes"]
----
git clone {src_git}
cd {git_repo}
export orig_dir="$(pwd)"
cd {pkg_me}
asciidoctor -a ROOTDIR="${orig_dir}/" -o README.html README.adoc
----
[id="rndr_pdf"]
=== PDF
This documentation can be rendered to PDF via https://docs.asciidoctor.org/pdf-converter/latest/[`asciidoctor-pdf`^].
It is not included in git automatically because binary files that change on each commit is not a good idea for git,
especially for a repo that gets cloned as part of a library inclusion in a module/package dependency system (like `gomod`).
To render as PDF:
[source,bash,subs="attributes"]
----
git clone {src_git}
cd {git_repo}
export orig_dir="$(pwd)"
cd {pkg_me}
asciidoctor-pdf -a ROOTDIR="${orig_dir}/" -o README.pdf README.adoc
----
[id="use"]
== How do I Use SprigX?
@@ -81,10 +134,10 @@ var (
----
====
They can even be combined/used together.
They can even be combined/used together,
[%collapsible]
.Like this.
.like this.
====
[source,go,subs="attributes"]
----
@@ -125,10 +178,8 @@ If a `<template>.FuncMap` is added via `.Funcs()` *after* template parsing, it w
For example, if both `sprig` and `sprigx` provide a function `foo`:
this will use `foo` from `sprigx`
[%collapsible]
.(show)
.this will use `foo` from `sprigx`
====
[source,go,subs="attributes"]
----
@@ -157,10 +208,8 @@ var (
----
====
whereas this will use `foo` from `sprig`
[%collapsible]
.(show)
.whereas this will use `foo` from `sprig`
====
[source,go,subs="attributes"]
----
@@ -189,10 +238,10 @@ var (
----
====
and a function can even be explicitly [[override]]overridden.
and a function can even be explicitly [[override]]overridden,
[%collapsible]
.(show)
.like this.
====
This would override a function `foo` and `foo2` in `sprigx` from `foo` and `foo2` from `sprig`, but leave all other `sprig` functions untouched.
@@ -233,6 +282,7 @@ var (
[id="lib"]
== Library Functions
These are generally intended to be used *outside* the template in the actual Go code.
[id="lib_cmbfmap"]
@@ -261,7 +311,7 @@ func CombinedHtmlFuncMap(preferSprigX bool) (fmap template.FuncMap)
----
This function returns an {godoc_root}/html/template#FuncMap[`html/template.FuncMap`] function map (like <<lib_hfmap>>) combined with
{godoc_sprig}#HtmlFuncMap[`github.com/Masterminds/sprig/v3.HtmlFuncMap`^].
{godoc_sprig}#HtmlFuncMap[`{import_sprig}.HtmlFuncMap`^].
If `preferSprigx` is true, SprigX function names will override Sprig functions with the same name.
If false, Sprig functions will override conflicting SprigX functions with the same name.
@@ -275,7 +325,7 @@ func CombinedTxtFuncMap(preferSprigX bool) (fmap template.FuncMap)
----
This function returns a {godoc_root}/text/template#FuncMap[`text/template.FuncMap`] function map (like <<lib_tfmap>>) combined with
{godoc_sprig}#TxtFuncMap[`github.com/Masterminds/sprig/v3.TxtFuncMap`^].
{godoc_sprig}#TxtFuncMap[`{import_sprig}.TxtFuncMap`^].
If `preferSprigx` is true, SprigX function names will override Sprig functions with the same name.
If false, Sprig functions will override conflicting SprigX functions with the same name.
@@ -669,6 +719,132 @@ func netipxRange(from, to netip.Addr) (ipRange netipx.IPRange)
`netipxRange` directly calls {godoc_root}/go4.org/netipx#IPRangeFrom[`go4.org/netipx.IPRangeFrom`^].
[id="fn_netx"]
==== `netx`
These template functions contain capabilities from {godoc_root}/{mod_me}/netx[`{mod_me}/netx`^].
[id="fn_netx_addrrfc"]
===== `netxAddrRfc`
[source,go]
.Function Signature
----
func netxAddrRfc(addr netip.Addr) (rfcStr string)
----
`netxAddrRfc` directly calls {godoc_root}/{mod_me}/netx#AddrRfc[`{mod_me}/netx.AddrRfc`^].
[id="fn_netx_cidr4ipmask"]
===== `netxCidr4IpMask`
[source,go]
.Function Signature
----
func netxCidr4IpMask(cidr uint8) (ipMask net.IPMask, err error)
----
`netxCidr4IpMask` directly calls {godoc_root}/{mod_me}/netx#Cidr4ToIPMask[`{mod_me}/netx.Cidr4ToIPMask`^].
[id="fn_netx_cidr4mask"]
===== `netxCidr4Mask`
[source,go]
.Function Signature
----
func netxCidr4Mask(cidr uint8) (mask uint32, err error)
----
`netxCidr4IpMask` directly calls {godoc_root}/{mod_me}/netx#Cidr4ToMask[`{mod_me}/netx.Cidr4ToMask`^].
[id="fn_netx_cidr4str"]
===== `netxCidr4Str`
[source,go]
.Function Signature
----
func netxCidr4Str(cidr uint8) (maskStr string, err error)
----
`netxCidr4Str` directly calls {godoc_root}/{mod_me}/netx#Cidr4ToStr[`{mod_me}/netx.Cidr4ToStr`^].
[id="fn_netx_familyver"]
===== `netxFamilyVer`
[source,go]
.Function Signature
----
func netxFamilyVer(family uint16) (ipVer int)
----
`netxFamilyVer` directly calls {godoc_root}/{mod_me}/netx#FamilyToVer[`{mod_me}/netx.FamilyToVer`^].
[id="fn_netx_getaddrfam"]
===== `netxGetAddrFam`
[source,go]
.Function Signature
----
func netxGetAddrFam(addr netip.Addr) (family uint16)
----
`netxGetAddrFam` directly calls {godoc_root}/{mod_me}/netx#GetAddrFamily[`{mod_me}/netx.GetAddrFamily`^].
[id="fn_netx_getipfam"]
===== `netxGetIpFam`
[source,go]
.Function Signature
----
func netxGetIpFam(ip net.IP) (family uint16)
----
`netxGetIpFam` directly calls {godoc_root}/{mod_me}/netx#GetAddrFamily[`{mod_me}/netx.GetIpFamily`^].
[id="fn_netx_iprfc"]
===== `netxIpRfc`
[source,go]
.Function Signature
----
func netxIpRfc(ip net.IP) (rfcStr string)
----
`netxIpRfc` directly calls {godoc_root}/{mod_me}/netx#IpRfc[`{mod_me}/netx.IpRfc`^].
[id="fn_netx_iprfcstr"]
===== `netxIpRfcStr`
[source,go]
.Function Signature
----
func netxIpRfcStr(s string) (rfcStr string)
----
`netxIpRfcStr` directly calls {godoc_root}/{mod_me}/netx#IpRfcStr[`{mod_me}/netx.IpRfcStr`^].
[id="fn_netx_ipstriprfc"]
===== `netxIpStripRfc`
[source,go]
.Function Signature
----
func netxIpStripRfc(s string) (stripStr string)
----
`netxIpStripRfc` directly calls {godoc_root}/{mod_me}/netx#IpStripRfcStr[`{mod_me}/netx.IpStripRfcStr`^].
[id="fn_netx_ip4maskcidr"]
===== `netxIp4MaskCidr`
[source,go]
.Function Signature
----
func netxIp4MaskCidr(ipMask net.IPMask) (cidr uint8, err error)
----
`netxIp4MaskCidr` directly calls {godoc_root}/{mod_me}/netx#IPMask4ToCidr[`{mod_me}/netx.IPMask4ToCidr`^].
[id="fn_netx_ip4maskmask"]
===== `netxIp4MaskMask`
[source,go]
.Function Signature
----
func netxIp4MaskMask(ipMask net.IPMask) (mask uint32, err error)
----
`netxIp4MaskMask` directly calls {godoc_root}/{mod_me}/netx#IPMask4ToMask[`{mod_me}/netx.IPMask4ToMask`^].
// TODO
[id="fn_num"]
=== Numbers/Math