v1.16.7
ADDED: * uuidx FIXED: * sprigx docs consistency
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
14
tplx/sprigx/TODO
Normal file
14
tplx/sprigx/TODO
Normal file
@@ -0,0 +1,14 @@
|
||||
- osReadFileBytes
|
||||
- osReadFileStr
|
||||
- osReadDir
|
||||
|
||||
- `dns*` funcs (net)
|
||||
- `url*` funcs (net/url)
|
||||
- `uuid*` funcs (github.com/google/uuid and r00t2.io/goutils/uuidx)
|
||||
|
||||
- `http*` funcs:
|
||||
-- `httpReq`: returns a net/http.Request
|
||||
-- `http<Method>`: performs <Method> (? seems redundant if exposing httpReq)
|
||||
-- also have `resty*` funcs?
|
||||
|
||||
- i should probably explicitly provide a "safe" set vs. "full" set. can just mod the map func getters to accept a "safeOnly" bool param.
|
||||
@@ -1,6 +1,8 @@
|
||||
package sprigx
|
||||
|
||||
import (
|
||||
`net`
|
||||
`net/netip`
|
||||
`os`
|
||||
`os/user`
|
||||
`path`
|
||||
@@ -17,6 +19,7 @@ import (
|
||||
psnet `github.com/shirou/gopsutil/v4/net`
|
||||
`github.com/shirou/gopsutil/v4/process`
|
||||
`github.com/shirou/gopsutil/v4/sensors`
|
||||
`go4.org/netipx`
|
||||
`r00t2.io/goutils/timex`
|
||||
`r00t2.io/sysutils`
|
||||
)
|
||||
@@ -30,6 +33,40 @@ var (
|
||||
"Meta"/Template-Helpers
|
||||
*/
|
||||
"metaIsNil": metaIsNil,
|
||||
/*
|
||||
Networking (net)
|
||||
*/
|
||||
"netCidrMask": net.CIDRMask,
|
||||
"netExtractAddr": netExtractAddr,
|
||||
"netExtractHost": netExtractHost,
|
||||
"netExtractIpnet": netExtractIpnet,
|
||||
"netExtractPort": netExtractPort,
|
||||
"netIfaces": net.Interfaces,
|
||||
"netIp4Mask": netIp4Mask,
|
||||
"netJoinHostPort": net.JoinHostPort,
|
||||
"netParseIP": net.ParseIP,
|
||||
/*
|
||||
Networking (net/netip)
|
||||
*/
|
||||
"netipAddrPort": netip.AddrPortFrom,
|
||||
"netipParseAddr": netip.ParseAddr,
|
||||
"netipParseAddrPort": netip.ParseAddrPort,
|
||||
"netipParsePrefix": netip.ParsePrefix,
|
||||
"netipPrefix": netip.PrefixFrom,
|
||||
/*
|
||||
Networking (go4.org/netipx)
|
||||
*/
|
||||
"netipxAddrIpNet": netipx.AddrIPNet,
|
||||
"netipxCmpPfx": netipx.ComparePrefix,
|
||||
"netipxFromStdAddr": netipxFromStdAddr,
|
||||
"netipxFromIp": netipxFromIp,
|
||||
"netipxFromIpNet": netipxFromIpNet,
|
||||
"netipxParseRange": netipx.ParseIPRange,
|
||||
"netipxPfxAddr": netipx.ParsePrefixOrAddr,
|
||||
"netipxPfxIpNet": netipx.PrefixIPNet,
|
||||
"netipxPfxLast": netipx.PrefixLastIP,
|
||||
"netipxPfxRange": netipx.RangeOfPrefix,
|
||||
"netipxRange": netipx.IPRangeFrom,
|
||||
/*
|
||||
Numbers/Math
|
||||
*/
|
||||
|
||||
77
tplx/sprigx/docinfo.html
Normal file
77
tplx/sprigx/docinfo.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<!-- https://stackoverflow.com/a/34481639 -->
|
||||
<!-- Generate a nice TOC -->
|
||||
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tocify/1.9.0/javascripts/jquery.tocify.min.js"></script>
|
||||
<!-- We do not need the tocify CSS because the asciidoc CSS already provides most of what we neeed -->
|
||||
|
||||
<style>
|
||||
.tocify-header {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tocify-subheader {
|
||||
font-style: normal;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
.tocify ul {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tocify-focus {
|
||||
color: #7a2518;
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.tocify-focus > a {
|
||||
color: #7a2518;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
// Add a new container for the tocify toc into the existing toc so we can re-use its
|
||||
// styling
|
||||
$("#toc").append("<div id='generated-toc'></div>");
|
||||
$("#generated-toc").tocify({
|
||||
extendPage: true,
|
||||
context: "#content",
|
||||
highlightOnScroll: true,
|
||||
hideEffect: "slideUp",
|
||||
// Use the IDs that asciidoc already provides so that TOC links and intra-document
|
||||
// links are the same. Anything else might confuse users when they create bookmarks.
|
||||
hashGenerator: function(text, element) {
|
||||
return $(element).attr("id");
|
||||
},
|
||||
// Smooth scrolling doesn't work properly if we use the asciidoc IDs
|
||||
smoothScroll: false,
|
||||
// Set to 'none' to use the tocify classes
|
||||
theme: "none",
|
||||
// Handle book (may contain h1) and article (only h2 deeper)
|
||||
selectors: $( "#content" ).has( "h1" ).size() > 0 ? "h1,h2,h3,h4,h5" : "h2,h3,h4,h5",
|
||||
ignoreSelector: ".discrete"
|
||||
});
|
||||
|
||||
// Switch between static asciidoc toc and dynamic tocify toc based on browser size
|
||||
// This is set to match the media selectors in the asciidoc CSS
|
||||
// Without this, we keep the dynamic toc even if it is moved from the side to preamble
|
||||
// position which will cause odd scrolling behavior
|
||||
var handleTocOnResize = function() {
|
||||
if ($(document).width() < 768) {
|
||||
$("#generated-toc").hide();
|
||||
$(".sectlevel0").show();
|
||||
$(".sectlevel1").show();
|
||||
}
|
||||
else {
|
||||
$("#generated-toc").show();
|
||||
$(".sectlevel0").hide();
|
||||
$(".sectlevel1").hide();
|
||||
}
|
||||
}
|
||||
|
||||
$(window).resize(handleTocOnResize);
|
||||
handleTocOnResize();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -5,7 +5,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBadMonth error = errors.New("could not determine/parse month")
|
||||
ErrBadType error = errors.New("an invalid/unknown type was passed")
|
||||
ErrNilVal error = errors.New("a nil value was passed")
|
||||
ErrBadAddr error = errors.New("invalid/bad address")
|
||||
ErrBadAddrPort error = errors.New("invalid/bad address/port")
|
||||
ErrBadMonth error = errors.New("could not determine/parse month")
|
||||
ErrBadNet error = errors.New("invalid/bad network")
|
||||
ErrOverflow error = errors.New("integer/buffer overflow")
|
||||
ErrBadType error = errors.New("an invalid/unknown type was passed")
|
||||
ErrNilVal error = errors.New("a nil value was passed")
|
||||
ErrUnderflow error = errors.New("integer/buffer underflow")
|
||||
)
|
||||
|
||||
82
tplx/sprigx/funcs_tpl_net.go
Normal file
82
tplx/sprigx/funcs_tpl_net.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package sprigx
|
||||
|
||||
import (
|
||||
`math`
|
||||
`net`
|
||||
`strconv`
|
||||
)
|
||||
|
||||
// netExtractAddr calls net.ParseCIDR and returns the net.IP from it.
|
||||
func netExtractAddr(s string) (addr net.IP, err error) {
|
||||
|
||||
if addr, _, err = net.ParseCIDR(s); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netExtractHost extracts the host component from hostPort.
|
||||
func netExtractHost(hostPort string) (host string, err error) {
|
||||
|
||||
if host, _, err = net.SplitHostPort(hostPort); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netExtractIpnet calls net.ParseCIDR and returns the net.IPNet from it.
|
||||
func netExtractIpnet(s string) (ipnet *net.IPNet, err error) {
|
||||
|
||||
if _, ipnet, err = net.ParseCIDR(s); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netExtractPort extracts the port component from hostPort.
|
||||
func netExtractPort(hostPort string) (port uint16, err error) {
|
||||
|
||||
var portStr string
|
||||
var u64 uint64
|
||||
|
||||
if _, portStr, err = net.SplitHostPort(hostPort); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if u64, err = strconv.ParseUint(portStr, 10, 16); err != nil {
|
||||
return
|
||||
}
|
||||
port = uint16(u64)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netIp4Mask is a more flexible wrapper around net.IPv4Mask.
|
||||
func netIp4Mask(a, b, c, d any) (mask net.IPMask, err error) {
|
||||
|
||||
var idx int
|
||||
var elem any
|
||||
var elemInt int
|
||||
var mBytes [4]byte
|
||||
var orig [4]any = [4]any{a, b, c, d}
|
||||
|
||||
for idx, elem = range orig {
|
||||
if elemInt, _, err = toPosInt(elem); err != nil {
|
||||
return
|
||||
}
|
||||
if elemInt > math.MaxUint8 {
|
||||
err = ErrOverflow
|
||||
return
|
||||
}
|
||||
mBytes[idx] = byte(uint8(elemInt))
|
||||
}
|
||||
|
||||
mask = net.IPv4Mask(
|
||||
mBytes[0], mBytes[1], mBytes[2], mBytes[3],
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
47
tplx/sprigx/funcs_tpl_netipx.go
Normal file
47
tplx/sprigx/funcs_tpl_netipx.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package sprigx
|
||||
|
||||
import (
|
||||
`net`
|
||||
`net/netip`
|
||||
|
||||
`go4.org/netipx`
|
||||
)
|
||||
|
||||
// netipxFromStdAddr wraps go4.org/netipx.FromStdAddr to comply with Go template requirements.
|
||||
func netipxFromStdAddr(ip net.IP, port int, zone string) (addrPort netip.AddrPort, err error) {
|
||||
|
||||
var ok bool
|
||||
|
||||
if addrPort, ok = netipx.FromStdAddr(ip, port, zone); !ok {
|
||||
err = ErrBadAddrPort
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netipxFromIp wraps go4.org/netipx.FromStdIP to comply with Go template requirements.
|
||||
func netipxFromIp(ip net.IP) (addr netip.Addr, err error) {
|
||||
|
||||
var ok bool
|
||||
|
||||
if addr, ok = netipx.FromStdIP(ip); !ok {
|
||||
err = ErrBadAddr
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// netipxFromIpNet wraps go4.org/netipx.FromStdIPNet to comply with Go template requirements.
|
||||
func netipxFromIpNet(ipnet *net.IPNet) (pfx netip.Prefix, err error) {
|
||||
|
||||
var ok bool
|
||||
|
||||
if pfx, ok = netipx.FromStdIPNet(ipnet); !ok {
|
||||
err = ErrBadNet
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user