Documentation
ΒΆ
Overview ΒΆ
Package knifer is the root package of the knifer-go utility toolkit.
This module is split into 55 public subpackages by domain. Import only the packages you need. The subpackages are grouped below for navigation:
String & text:
vstr strings and text similarity helpers vregex regular expressions vtpl html/template rendering (TemPLate) vurl URL/URI parsing, escaping, query building vhan Han text romanization adapters vtok tokenization adapters
Collections & data structures:
vslice slices vmap maps vset sets vobj object-level helpers vblf bloom filters (BLoom Filter) vcache generic caches (FIFO/LRU/LFU/Timed) vbean struct/map mapping and copying
Primitives & conversion:
vbool booleans vnum numeric helpers vconv permissive type conversion vdate date/time vref reflection
Encoding & serialization:
vcodec Base64/Hex vcsv CSV reading/writing vimg raster images and graphical captchas vjson JSON vxml XML vhash non-cryptographic hashes
Networking & communication:
vhttp standard-library HTTP client/server vresty Resty-based HTTP client vmail email message construction, MIME attachments, and SMTP sending vskt sockets (SocKeT) vnet IP/port/interface utilities vftp FTP adapters vssh SSH/SFTP adapters
Security & matching:
vcrypto cryptography and digests vjwt JWT sign/verify vmask data masking (desensitization) vpass password strength analysis vdfa DFA word-tree text matching
Tasks & concurrency:
vjob job orchestration vcron cron scheduling vsem semaphores (SEMaphore) vrand randomness
IO & files:
vfile file and IO helpers vzip archive/compression vpoi office documents (Excel)
Runtime & system:
vsys system information (SYStem) vlog logging verr error handling, panic recovery, stacks (errx) vconf configuration vcli CLI helpers vai AI adapters
Identity & misc:
vid generated IDs (UUID/Snowflake/ObjectId/NanoId) vident legal identity numbers (ID cards) vform form and input validators vver version comparison (VERsion) vdb database/sql helpers vgeo coordinate conversion (WGS-84/GCJ-02/BD-09)
Example:
import "github.com/imajinyun/knifer-go/vstr" import "github.com/imajinyun/knifer-go/vhttp"
Subpackages are independent from each other. The root package exposes no business APIs; it only defines the cross-cutting error contract (ErrCode, Error, CodeCarrier, CodeOf and the New/Wrap/Errorf constructors) that subpackages may use to classify failures consistently.
Callers can match failures by code regardless of the originating subpackage:
if errors.Is(err, knifer.ErrCodeInvalidInput) { ... }
if code, ok := knifer.CodeOf(err); ok { ... }
Subpackages that participate should return *knifer.Error or implement CodeCarrier on their existing error types/sentinels while wrapping any underlying cause so the standard error chain is preserved.
The project follows an internal implementation plus public facade layout: concrete implementations live in internal/* packages, while application code should import the public v* packages. This keeps domain boundaries explicit and allows internal implementations to evolve without exposing every helper as public API.
Index ΒΆ
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type CodeCarrier ΒΆ
type CodeCarrier interface {
ErrorCode() ErrCode
}
CodeCarrier is implemented by errors that can expose a knifer-go error code.
Custom subpackage errors can implement this interface while preserving their own concrete type and sentinel semantics.
type ErrCode ΒΆ
type ErrCode string
ErrCode is a stable, cross-subpackage error classifier.
It is itself an error so that it can be used directly with errors.Is:
if errors.Is(err, knifer.ErrCodeInvalidInput) { ... }
const ( // ErrCodeInvalidInput indicates the caller provided invalid arguments. ErrCodeInvalidInput ErrCode = "GK_INVALID_INPUT" // ErrCodeNotFound indicates the requested resource does not exist. ErrCodeNotFound ErrCode = "GK_NOT_FOUND" // ErrCodeUnsupported indicates the requested operation is not supported. ErrCodeUnsupported ErrCode = "GK_UNSUPPORTED" // ErrCodeUnsafeResource indicates the requested file, URL, archive entry, or // remote resource failed a safety policy such as traversal or SSRF checks. ErrCodeUnsafeResource ErrCode = "GK_UNSAFE_RESOURCE" // ErrCodeTimeout indicates the operation exceeded its time budget. ErrCodeTimeout ErrCode = "GK_TIMEOUT" // ErrCodeProviderFailure indicates an injected provider, transport, codec, // filesystem, random source, or external adapter failed after input was valid. ErrCodeProviderFailure ErrCode = "GK_PROVIDER_FAILURE" // ErrCodeInternal indicates an unexpected internal failure. ErrCodeInternal ErrCode = "GK_INTERNAL" )
Predefined cross-cutting error codes.
These cover the most common failure categories shared across subpackages. Domain-specific codes can be defined within each subpackage when needed.
type Error ΒΆ
type Error struct {
// Code classifies the error. It is matched by errors.Is.
Code ErrCode
// Message is a human-readable description.
Message string
// Cause is the underlying error, if any. It is exposed through Unwrap.
Cause error
}
Error is the unified error type for knifer-go subpackages.
Subpackages that want to participate in the cross-cutting error contract should return *Error and wrap any underlying cause through Cause so that callers can rely on errors.Is(err, knifer.ErrCodeXxx) and on the standard error-chain helpers.
Example ΒΆ
package main
import (
"errors"
"fmt"
"github.com/imajinyun/knifer-go"
)
func main() {
err := knifer.NewError(knifer.ErrCodeInvalidInput, "url is empty")
fmt.Println(errors.Is(err, knifer.ErrCodeInvalidInput))
fmt.Println(err)
}
Output: true GK_INVALID_INPUT: url is empty
func WrapError ΒΆ
WrapError builds an *Error that wraps cause; cause is preserved on the chain and remains discoverable via errors.Is / errors.As.
Example ΒΆ
package main
import (
"errors"
"fmt"
"github.com/imajinyun/knifer-go"
)
func main() {
cause := errors.New("connection refused")
err := knifer.WrapError(knifer.ErrCodeTimeout, "dial failed", cause)
fmt.Println(errors.Is(err, knifer.ErrCodeTimeout))
fmt.Println(errors.Is(err, cause))
}
Output: true true
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
agentevidencecheck
command
|
|
|
apiconvergencecheck
command
|
|
|
apifreezecheck
command
|
|
|
archimportscheck
command
|
|
|
benchmarkregressioncheck
command
|
|
|
capabilitydomainscheck
command
|
|
|
changepolicycheck
command
|
|
|
ciworkflowcheck
command
|
|
|
coveragecheck
command
|
|
|
dependencytierscheck
command
|
|
|
docsquickstartcheck
command
|
|
|
dynamiccontractscheck
command
|
|
|
errormodelcheck
command
|
|
|
facadeboundarycheck
command
|
|
|
governancemigrationcheck
command
|
|
|
internal/govreport
Package govreport provides a shared JSON report envelope for governance checkers.
|
Package govreport provides a shared JSON report envelope for governance checkers. |
|
lifecyclecheck
command
|
|
|
localgovernancegatescheck
command
|
|
|
namingcheck
Package namingcheck enforces AST-based naming contracts for knifer-go APIs.
|
Package namingcheck enforces AST-based naming contracts for knifer-go APIs. |
|
panicpolicycheck
command
|
|
|
providercontractcheck
command
|
|
|
randomsourcepolicycheck
command
|
|
|
roadmapcatalogcheck
command
|
|
|
threatmodelcheck
command
|
|
|
toolsgen
command
Command toolsgen generates docs/api/tools.json, a machine-readable catalog of the public v* facade functions for AI/tooling consumption.
|
Command toolsgen generates docs/api/tools.json, a machine-readable catalog of the public v* facade functions for AI/tooling consumption. |
|
internal
|
|
|
ai
Package ai implements provider-neutral AI adapter primitives.
|
Package ai implements provider-neutral AI adapter primitives. |
|
bean
Package bean provides struct/map property mapping helpers.
|
Package bean provides struct/map property mapping helpers. |
|
bloomfilter
Package bloomfilter provides Bloom filters and extended bitmap implementations.
|
Package bloomfilter provides Bloom filters and extended bitmap implementations. |
|
boolean
Package boolean provides boolean helpers.
|
Package boolean provides boolean helpers. |
|
cache
Package cache provides cache implementations inspired by Cache, including FIFO, LFU, LRU, Timed, Weak, and NoCache variants.
|
Package cache provides cache implementations inspired by Cache, including FIFO, LFU, LRU, Timed, Weak, and NoCache variants. |
|
cli
Package cli implements dependency-free helpers for lightweight command-line tooling.
|
Package cli implements dependency-free helpers for lightweight command-line tooling. |
|
codec
Package codec provides encoding and decoding helpers.
|
Package codec provides encoding and decoding helpers. |
|
conf
Package conf provides configuration file readers for properties, setting, and simple YAML formats.
|
Package conf provides configuration file readers for properties, setting, and simple YAML formats. |
|
constraint
Package constraint contains internal generic type constraints shared by implementation packages.
|
Package constraint contains internal generic type constraints shared by implementation packages. |
|
conv
Package conv provides permissive type conversion helpers.
|
Package conv provides permissive type conversion helpers. |
|
cron
Package cron provides a cron-expression-based task scheduling framework aligned with the utility toolkit-cron.
|
Package cron provides a cron-expression-based task scheduling framework aligned with the utility toolkit-cron. |
|
crypto
Package crypto provides security-oriented digest, HMAC, AES, RSA, and PEM encoding helpers.
|
Package crypto provides security-oriented digest, HMAC, AES, RSA, and PEM encoding helpers. |
|
csvx
Package csvx provides CSV reader and writer helpers.
|
Package csvx provides CSV reader and writer helpers. |
|
date
Package date provides date and time helpers.
|
Package date provides date and time helpers. |
|
db
Package db provides database helpers built on top of database/sql.
|
Package db provides database helpers built on top of database/sql. |
|
dfa
Package dfa provides deterministic-finite-automaton text matching utilities.
|
Package dfa provides deterministic-finite-automaton text matching utilities. |
|
errx
Package errx provides small error handling and panic-recovery helpers used by internal packages.
|
Package errx provides small error handling and panic-recovery helpers used by internal packages. |
|
file
Package file provides file and IO helpers.
|
Package file provides file and IO helpers. |
|
ftp
Package ftp implements provider-neutral FTP transfer primitives.
|
Package ftp implements provider-neutral FTP transfer primitives. |
|
geo
Package geo provides coordinate conversion helpers for common China map coordinate systems.
|
Package geo provides coordinate conversion helpers for common China map coordinate systems. |
|
hash
Package hash provides general-purpose hash helpers.
|
Package hash provides general-purpose hash helpers. |
|
httpboundary
Package httpboundary centralizes HTTP trust-boundary host classification.
|
Package httpboundary centralizes HTTP trust-boundary host classification. |
|
httpx
Package httpx provides HTTP client and server implementations.
|
Package httpx provides HTTP client and server implementations. |
|
httpx/http
Package http is aligned with the utility toolkit-http and provides HTTP client, download, Cookie, UserAgent, SimpleServer, and related utilities.
|
Package http is aligned with the utility toolkit-http and provides HTTP client, download, Cookie, UserAgent, SimpleServer, and related utilities. |
|
httpx/internal/shared
Package shared holds engine-agnostic HTTP protocol types and helpers (methods, headers, content types, and errors).
|
Package shared holds engine-agnostic HTTP protocol types and helpers (methods, headers, content types, and errors). |
|
httpx/resty
Package resty provides the internal implementation for the vresty package.
|
Package resty provides the internal implementation for the vresty package. |
|
id
Package id provides helpers for generating unique identifiers.
|
Package id provides helpers for generating unique identifiers. |
|
identity
Package identity implements identity and legal identifier helpers.
|
Package identity implements identity and legal identifier helpers. |
|
imgx
Package imgx provides image helpers, graphical captcha generators, and ZXing-backed QR/barcode utilities.
|
Package imgx provides image helpers, graphical captcha generators, and ZXing-backed QR/barcode utilities. |
|
job
Package job provides helpers for running sliceable work with configurable scheduling.
|
Package job provides helpers for running sliceable work with configurable scheduling. |
|
json
Package json provides JSON parsing and generation helpers, including objects, arrays, path access, and lightweight XML conversion adapters.
|
Package json provides JSON parsing and generation helpers, including objects, arrays, path access, and lightweight XML conversion adapters. |
|
jwt
Package jwt provides JWT (JSON Web Token) creation, parsing, signing, and validation utilities matching the utility toolkit-jwt.
|
Package jwt provides JWT (JSON Web Token) creation, parsing, signing, and validation utilities matching the utility toolkit-jwt. |
|
log
Package log provides a unified logging interface and default console implementations matching the utility toolkit-log.
|
Package log provides a unified logging interface and default console implementations matching the utility toolkit-log. |
|
mail
Package mail provides message construction, MIME attachment rendering, and SMTP sending helpers.
|
Package mail provides message construction, MIME attachment rendering, and SMTP sending helpers. |
|
maps
Package maps provides common helpers for Go map collections.
|
Package maps provides common helpers for Go map collections. |
|
mask
Package mask provides internal data masking helpers.
|
Package mask provides internal data masking helpers. |
|
net
Package net provides network, IP, TLS, and multipart helpers.
|
Package net provides network, IP, TLS, and multipart helpers. |
|
num
Package num provides numeric helpers.
|
Package num provides numeric helpers. |
|
obj
Package obj provides internal object helpers.
|
Package obj provides internal object helpers. |
|
pass
Package pass provides password strength analysis helpers.
|
Package pass provides password strength analysis helpers. |
|
pinyin
Package pinyin implements provider-neutral Chinese-to-pinyin primitives.
|
Package pinyin implements provider-neutral Chinese-to-pinyin primitives. |
|
poi
Package poi provides internal office-document utilities.
|
Package poi provides internal office-document utilities. |
|
rand
Package rand provides random value helpers.
|
Package rand provides random value helpers. |
|
ref
Package ref provides reflection helpers for fields, methods, construction, invocation, and safe value conversion.
|
Package ref provides reflection helpers for fields, methods, construction, invocation, and safe value conversion. |
|
regex
Package regex provides regular-expression helpers.
|
Package regex provides regular-expression helpers. |
|
semaphore
Package semaphore provides a weighted, context-aware counting semaphore.
|
Package semaphore provides a weighted, context-aware counting semaphore. |
|
sets
Package sets provides generic and typed set utilities.
|
Package sets provides generic and typed set utilities. |
|
slice
Package slice provides slice helpers.
|
Package slice provides slice helpers. |
|
socket
Package socket provides NIO/AIO-style socket communication helpers.
|
Package socket provides NIO/AIO-style socket communication helpers. |
|
ssh
Package ssh implements provider-neutral SSH and SFTP transfer primitives.
|
Package ssh implements provider-neutral SSH and SFTP transfer primitives. |
|
str
Package str provides string and character helpers.
|
Package str provides string and character helpers. |
|
system
Package system provides runtime, operating system, user, and host information utilities.
|
Package system provides runtime, operating system, user, and host information utilities. |
|
template
Package template provides internal Go html/template rendering helpers.
|
Package template provides internal Go html/template rendering helpers. |
|
tokenize
Package tokenize implements provider-neutral text tokenization primitives.
|
Package tokenize implements provider-neutral text tokenization primitives. |
|
url
Package url provides internal URL and URI helpers.
|
Package url provides internal URL and URI helpers. |
|
validator
Package validator provides value validation helpers.
|
Package validator provides value validation helpers. |
|
version
Package version provides internal version comparison and expression matching helpers.
|
Package version provides internal version comparison and expression matching helpers. |
|
xml
Package xml provides XML parsing, formatting, tree navigation, conversion, and escaping helpers.
|
Package xml provides XML parsing, formatting, tree navigation, conversion, and escaping helpers. |
|
zip
Package zip provides internal compression helpers.
|
Package zip provides internal compression helpers. |
|
Package vai provides provider-neutral AI chat and embedding helpers.
|
Package vai provides provider-neutral AI chat and embedding helpers. |
|
Package vbean provides public APIs for struct and map property mapping.
|
Package vbean provides public APIs for struct and map property mapping. |
|
Package vblf provides public APIs for Bloom filter utilities.
|
Package vblf provides public APIs for Bloom filter utilities. |
|
Package vbool provides public APIs for boolean utilities.
|
Package vbool provides public APIs for boolean utilities. |
|
Package vcache provides public APIs for cache utilities.
|
Package vcache provides public APIs for cache utilities. |
|
Package vcli provides public APIs for lightweight command-line helpers.
|
Package vcli provides public APIs for lightweight command-line helpers. |
|
Package vcodec provides public APIs for encoding and decoding utilities.
|
Package vcodec provides public APIs for encoding and decoding utilities. |
|
Package vconf provides configuration file reading and grouped configuration utilities.
|
Package vconf provides configuration file reading and grouped configuration utilities. |
|
Package vconv provides public APIs for permissive type conversion.
|
Package vconv provides public APIs for permissive type conversion. |
|
Package vcron provides public APIs for cron scheduling utilities.
|
Package vcron provides public APIs for cron scheduling utilities. |
|
Package vcrypto provides public APIs for cryptographic utilities.
|
Package vcrypto provides public APIs for cryptographic utilities. |
|
Package vcsv provides public APIs for CSV reading and writing.
|
Package vcsv provides public APIs for CSV reading and writing. |
|
Package vdate provides public APIs for date/time utilities.
|
Package vdate provides public APIs for date/time utilities. |
|
Package vdb exposes database/sql helper APIs for SQL execution, query building, entities, conditions, pagination, transactions, named parameters, and lightweight metadata lookup.
|
Package vdb exposes database/sql helper APIs for SQL execution, query building, entities, conditions, pagination, transactions, named parameters, and lightweight metadata lookup. |
|
Package vdfa exposes deterministic-finite-automaton text matching APIs.
|
Package vdfa exposes deterministic-finite-automaton text matching APIs. |
|
Package verr exposes error handling, panic recovery, and stack helpers.
|
Package verr exposes error handling, panic recovery, and stack helpers. |
|
Package vfile provides public APIs for file and IO utilities.
|
Package vfile provides public APIs for file and IO utilities. |
|
Package vform provides public APIs for form and input validation utilities.
|
Package vform provides public APIs for form and input validation utilities. |
|
Package vftp provides provider-neutral FTP list, download, and upload helpers.
|
Package vftp provides provider-neutral FTP list, download, and upload helpers. |
|
Package vgeo provides public APIs for coordinate conversion utilities.
|
Package vgeo provides public APIs for coordinate conversion utilities. |
|
Package vhan provides provider-neutral Han text romanization helpers.
|
Package vhan provides provider-neutral Han text romanization helpers. |
|
Package vhash provides public APIs for hash utilities.
|
Package vhash provides public APIs for hash utilities. |
|
Package vhttp provides public APIs for HTTP utilities.
|
Package vhttp provides public APIs for HTTP utilities. |
|
Package vid provides public APIs for ID generation utilities.
|
Package vid provides public APIs for ID generation utilities. |
|
Package vident provides identity and legal identifier helpers.
|
Package vident provides identity and legal identifier helpers. |
|
Package vimg provides public APIs for image utilities.
|
Package vimg provides public APIs for image utilities. |
|
Package vjob provides public APIs for sliceable job execution.
|
Package vjob provides public APIs for sliceable job execution. |
|
Package vjson provides public APIs for JSON utilities.
|
Package vjson provides public APIs for JSON utilities. |
|
Package vjwt provides public APIs for JWT utilities.
|
Package vjwt provides public APIs for JWT utilities. |
|
Package vlog provides public APIs for logging utilities.
|
Package vlog provides public APIs for logging utilities. |
|
Package vmail exposes email message construction, MIME attachment, and SMTP sending helpers.
|
Package vmail exposes email message construction, MIME attachment, and SMTP sending helpers. |
|
Package vmap provides public APIs for map utilities.
|
Package vmap provides public APIs for map utilities. |
|
Package vmask provides data masking (desensitization) utilities.
|
Package vmask provides data masking (desensitization) utilities. |
|
Package vnet provides public APIs for network, IP, URL-encoding, TLS, and multipart utilities.
|
Package vnet provides public APIs for network, IP, URL-encoding, TLS, and multipart utilities. |
|
Package vnum provides public APIs for numeric utilities.
|
Package vnum provides public APIs for numeric utilities. |
|
Package vobj provides object utilities.
|
Package vobj provides object utilities. |
|
Package vpass provides password strength helpers.
|
Package vpass provides password strength helpers. |
|
Package vpoi provides office-document utilities.
|
Package vpoi provides office-document utilities. |
|
Package vrand provides public APIs for random value utilities.
|
Package vrand provides public APIs for random value utilities. |
|
Package vref provides public APIs for reflection utilities.
|
Package vref provides public APIs for reflection utilities. |
|
Package vregex provides public APIs for regular-expression utilities.
|
Package vregex provides public APIs for regular-expression utilities. |
|
Package vresty provides convenient HTTP client wrappers backed by resty.
|
Package vresty provides convenient HTTP client wrappers backed by resty. |
|
Package vsem provides public APIs for semaphore utilities.
|
Package vsem provides public APIs for semaphore utilities. |
|
Package vset provides public APIs for set utilities.
|
Package vset provides public APIs for set utilities. |
|
Package vskt provides public APIs for socket utilities.
|
Package vskt provides public APIs for socket utilities. |
|
Package vslice provides public APIs for slice utilities.
|
Package vslice provides public APIs for slice utilities. |
|
Package vssh provides provider-neutral SSH command and SFTP transfer helpers.
|
Package vssh provides provider-neutral SSH command and SFTP transfer helpers. |
|
Package vstr provides public APIs for string and text utilities.
|
Package vstr provides public APIs for string and text utilities. |
|
Package vsys provides public APIs for system information utilities.
|
Package vsys provides public APIs for system information utilities. |
|
Package vtok provides provider-neutral text tokenization helpers.
|
Package vtok provides provider-neutral text tokenization helpers. |
|
Package vtpl provides Go html/template rendering utilities.
|
Package vtpl provides Go html/template rendering utilities. |
|
Package vurl provides URL and URI utilities.
|
Package vurl provides URL and URI utilities. |
|
Package vver provides version comparison and expression matching utilities.
|
Package vver provides version comparison and expression matching utilities. |
|
Package vxml provides public APIs for XML utilities.
|
Package vxml provides public APIs for XML utilities. |
|
Package vzip provides ZIP, gzip, and zlib utilities.
|
Package vzip provides ZIP, gzip, and zlib utilities. |
