Documentation
¶
Index ¶
- Constants
- Variables
- func AnyToBytes(data interface{}) ([]byte, error)
- func ArrayToJSON[T any](arr []T) (string, error)
- func AskForConfirmation(key1 string, key2 string) (err error)
- func BytesToInt64(b []byte) int64
- func ConvertFloat32FromKV(kv map[string]any, key string) (r float32, err error)
- func ConvertFloat64FromKV(kv map[string]any, key string) (r float64, err error)
- func ConvertInt64FromKV(kv map[string]any, key string) (r int64, err error)
- func ConvertIntFromKV(kv map[string]any, key string) (r int, err error)
- func ConvertToArrayOfMapStringAnyFromAny(v any) ([]map[string]any, error)
- func ConvertToBoolFromKV(kv map[string]any, key string) (bool, error)
- func ConvertToFloat(v any) (float64, bool)
- func ConvertToFloat32(value interface{}) (float32, error)
- func ConvertToFloat32FromKV(kv map[string]any, key string) (float32, error)
- func ConvertToFloat64(value interface{}) (float64, error)
- func ConvertToFloat64FromKV(kv map[string]any, key string) (float64, error)
- func ConvertToInt(value interface{}) (int, error)
- func ConvertToInt64(value interface{}) (int64, error)
- func ConvertToInt64FromKV(kv map[string]any, key string) (int64, error)
- func ConvertToIntFromKV(kv map[string]any, key string) (int, error)
- func ConvertToInterfaceArrayInterfaceFromAny(v any) (r any, err error)
- func ConvertToInterfaceBoolFromAny(v any) (r any, err error)
- func ConvertToInterfaceFloat64FromAny(v any) (r any, err error)
- func ConvertToInterfaceInt64FromAny(v any) (r any, err error)
- func ConvertToInterfaceIntFromAny(v any) (r any, err error)
- func ConvertToInterfaceStringFromAny(v any) (r any, err error)
- func ConvertToMapStringInterfaceFromAny(v any) (r any, err error)
- func ConvertToStringFromKV(kv map[string]any, key string) (string, error)
- func Diff[T comparable](first []T, second []T) (included, missing []T)
- func DiffJsonFieldValues[T comparable](valuesToCheck []T, jsonData []map[string]any, fieldName string) (included, missing []T)
- func ExtractMapValue[T any](m *map[string]any, key string) (exists bool, value T, err error)
- func FindCommonValues[K comparable, V comparable](arrays1, arrays2 []map[K]any, key K) []V
- func FindCommonValuesInMapString[V comparable](arrays1, arrays2 []map[string]any, key string) []V
- func Float64sToJSON(arr []float64) string
- func FloatFitsInt64(f float64) bool
- func GetAllActualBindingAddress(configuredBindingAddress string) []string
- func GetAllMachineIP4s() []string
- func GetArrayFromV(v any) (r []any, err error)
- func GetBoolFromKV(kv map[string]any, key string) (r bool, err error)
- func GetBuildTime() string
- func GetBytesFromKV(kv map[string]any, key string) (r []byte, err error)
- func GetFloat64FromKV(kv map[string]any, key string) (r float64, err error)
- func GetInt64FromKV(kv map[string]any, key string) (r int64, err error)
- func GetIntFromKV(kv map[string]any, key string) (r int, err error)
- func GetKVFromKV(kv map[string]any, key string) (r map[string]any, err error)
- func GetMapStringStringFromKV(kv map[string]any, key string) (r map[string]string, err error)
- func GetMapStringStringFromV(v any) (r map[string]string, err error)
- func GetMapValue[T any](m map[string]any, key string) (exist bool, value T, err error)
- func GetMapValueFromJSONs[T any](a []map[string]any, key string) (values []T, error error)
- func GetStringFromKV(kv map[string]any, key string) (r string, err error)
- func GetStringFromMapStringString(kv map[string]string, key string) (r string, err error)
- func GetStringFromMapStringStringDefault(kv map[string]string, key string, defaultValue string) (r string)
- func GetTimeFromKV(kv map[string]any, key string) (r time.Time, err error)
- func GetUint64FromKV(kv map[string]any, key string) (r uint64, err error)
- func GetVFromKV[T any](kv map[string]any, key string) (r T, err error)
- func GetValueFromNestedMap(data map[string]interface{}, key string) (interface{}, error)
- func IfFloatIsInt(f float64) bool
- func Int64SliceToStrings(nums []int64) []string
- func Int64ToBytes(v int64) []byte
- func Int64ToString(i int64) string
- func Int64sIsContain(arr []int64, v int64) bool
- func Int64sToJSON(arr []int64) string
- func Int64sToStrings(arr []int64) []string
- func IntsToJSON(arr []int) string
- func IsCredentialHeader(name string) bool
- func IsSensitiveField(fieldName string) bool
- func IsValuesMatch(a, b any) bool
- func JSONToBytes(v JSON) ([]byte, error)
- func JSONToMapStringString(kv JSON) (r map[string]string)
- func JSONToString(v JSON) (string, error)
- func Mask2by2(s string) string
- func MaskDefaultDeny() bool
- func MaskEmail2by2(s string) string
- func MaskFrontBack(s string, front, back int) string
- func MaskFull(string) string
- func MaskHeaderValue(name, value string) string
- func MaskInitials(s string) string
- func MaskLocation2Decimals(value any) any
- func MaskNumber(s string, front, back int) string
- func MaskNumber2by4(s string) string
- func MaskNumber4by3(s string) string
- func MaskNumber5by4(s string) string
- func MaskNumber6by4(s string) string
- func MaskRedacted(string) string
- func MaskSensitiveValue(fieldName string, value interface{}) interface{}
- func MustConvertToInterfaceStringFromAny(v any) (r any)
- func NowAsString() string
- func RemoveDuplicates[T comparable](slice []T) []T
- func SetCredentialHeaders(names []string)
- func SetLogAllowedFields(names []string)
- func SetMaskDefaultDeny(b bool)
- func SetMaskRules(rules map[string]MaskRule)
- func SetMaskStrict(b bool)
- func SetValueInNestedMap(data map[string]interface{}, key string, value interface{})
- func ShouldStrictJSONToMapStringString(kv JSON) (r map[string]string, err error)
- func StringIsInSlice(str string, list []string) bool
- func StringsHasCommonItem(arr1, arr2 []string) bool
- func StringsIsContain(arr []string, v string) bool
- func StringsToJSON(arr []string) string
- func TCPAddressCanConnect(address string) bool
- func TCPIPPortCanConnect(ip string, port string) bool
- func TimeSubToString(t1 any, t2 any) (r string)
- func TsIsContain[T comparable](arr []T, v T) bool
- func TsIsInSlice[T comparable](v []T, aSlice []T) bool
- func TypeAsString(v any) string
- func Uint32ToBytes(v uint32) []byte
- func WriteHeadersForLog(h http.Header, exclude map[string]bool) string
- type JSON
- type MaskKind
- type MaskRule
Constants ¶
const MaskRedactedMarker = "***REDACTED***"
MaskRedactedMarker is what a log shows in place of a secret: a credential field or header, a token, a password, a PIN, an OTP or an image.
Variables ¶
var ( // RuleMaskFull hides the whole value: "********". RuleMaskFull = MaskRule{} // RuleMask2by2 keeps the first 2 and the last 2 of the whole value: "Pegawai Swasta" → // "Pe***ta"; a value of 7 or fewer is its first then "***" (MaskFrontBack). RuleMask2by2 = MaskRule{Front: 2, Back: 2} // RuleMaskNumber2by4 is an account number: "1234567890" → "12***7890". RuleMaskNumber2by4 = MaskRule{Kind: MaskKindNumber, Front: 2, Back: 4} // RuleMaskNumber5by4 is a national ID or family card number: "3201012345671234" → // "32010***1234". RuleMaskNumber5by4 = MaskRule{Kind: MaskKindNumber, Front: 5, Back: 4} // RuleMaskNumber4by3 is a phone number: "081234567789" → "0812***789". RuleMaskNumber4by3 = MaskRule{Kind: MaskKindNumber, Front: 4, Back: 3} // RuleMaskNumber6by4 is a card number, the PCI DSS display limit: "4111111111111234" → // "411111***1234". RuleMaskNumber6by4 = MaskRule{Kind: MaskKindNumber, Front: 6, Back: 4} // RuleMaskEmail2by2 is an e-mail address (MaskEmail2by2). RuleMaskEmail2by2 = MaskRule{Kind: MaskKindEmail} // RuleMaskInitials is a name (MaskInitials). RuleMaskInitials = MaskRule{Kind: MaskKindInitials} // RuleMaskLocation2Decimals is a coordinate (MaskLocation2Decimals). RuleMaskLocation2Decimals = MaskRule{Kind: MaskKindLocation} // RuleMaskRedacted is a secret or an image: "***REDACTED***". RuleMaskRedacted = MaskRule{Kind: MaskKindRedacted} )
Named rules for SetMaskRules. RuleMask<front>by<back> keeps that many characters at each end; the number rules drop spaces and dashes first. MaskStrict collapses every rule to RuleMaskFull.
var MaskEmailKnownEndings = []string{
".co.id", ".ac.id", ".go.id", ".or.id", ".web.id", ".sch.id", ".net.id", ".my.id",
".mil.id", ".biz.id", ".ponpes.id", ".desa.id", ".id",
".com", ".net", ".org", ".edu", ".gov", ".mil", ".int", ".info", ".biz",
".io", ".co", ".me", ".app", ".dev",
".co.uk", ".ac.uk", ".org.uk", ".uk",
".com.sg", ".edu.sg", ".sg",
".com.my", ".edu.my", ".my",
".com.au", ".edu.au", ".au",
".co.jp", ".ac.jp", ".jp",
}
MaskEmailKnownEndings is the list of public domain endings MaskEmail2by2 keeps as written. Everything before the ending is masked, so a sub-domain such as an employer's name in "mail.example.co.id" is not shown. The longest ending a domain matches wins, so ".co.id" is taken over ".id". Each entry starts with a dot. A host may append to it at init.
var OverrideShowPasswordOnLog = false
OverrideShowPasswordOnLog disables sensitive field masking in logs when true.
Functions ¶
func AnyToBytes ¶
AnyToBytes converts a value of a supported type to a byte slice.
func ArrayToJSON ¶
ArrayToJSON converts a slice of any type to a JSON string.
func AskForConfirmation ¶
AskForConfirmation prompts the user for two confirmation keys and returns an error if they don't match the provided keys.
func BytesToInt64 ¶
BytesToInt64 converts a byte slice to an int64.
func ConvertFloat32FromKV ¶
ConvertFloat32FromKV retrieves a value from map and converts it to float32
func ConvertFloat64FromKV ¶
ConvertFloat64FromKV retrieves a value from map and converts it to float64
func ConvertInt64FromKV ¶
func ConvertIntFromKV ¶
ConvertIntFromKV retrieves a value from map and converts it to int
func ConvertToArrayOfMapStringAnyFromAny ¶
ConvertToArrayOfMapStringAnyFromAny converts a value of any type to []map[string]any. Handles both []map[string]any (direct) and []interface{} (from JSON unmarshal) cases.
func ConvertToBoolFromKV ¶
ConvertToBoolFromKV gets value from map by key and converts it to bool
func ConvertToFloat ¶
func ConvertToFloat32 ¶
ConvertToFloat32 converts various types to float32
func ConvertToFloat32FromKV ¶
ConvertToFloat32FromKV gets value from map by key and converts it to float32
func ConvertToFloat64 ¶
ConvertToFloat64 converts various types to float64
func ConvertToFloat64FromKV ¶
ConvertToFloat64FromKV gets value from map by key and converts it to float64
func ConvertToInt ¶
ConvertToInt converts various types to int
func ConvertToInt64 ¶
ConvertToInt64 converts various types to int64
func ConvertToInt64FromKV ¶
ConvertToInt64FromKV gets value from map by key and converts it to int64
func ConvertToIntFromKV ¶
ConvertToIntFromKV gets value from map by key and converts it to int
func ConvertToInterfaceArrayInterfaceFromAny ¶
ConvertToInterfaceArrayInterfaceFromAny converts a value of any type to a slice of interfaces.
func ConvertToInterfaceBoolFromAny ¶
ConvertToInterfaceBoolFromAny converts a value of any type to a boolean interface.
func ConvertToInterfaceFloat64FromAny ¶
ConvertToInterfaceFloat64FromAny converts a value of any type to a float64 interface.
func ConvertToInterfaceInt64FromAny ¶
ConvertToInterfaceInt64FromAny converts a value of any type to an int64 interface.
func ConvertToInterfaceIntFromAny ¶
ConvertToInterfaceIntFromAny converts a value of any type to an integer interface.
func ConvertToInterfaceStringFromAny ¶
ConvertToInterfaceStringFromAny converts a value of any type to a string interface.
func ConvertToMapStringInterfaceFromAny ¶
ConvertToMapStringInterfaceFromAny converts a value of any type to a map[string]any interface.
func ConvertToStringFromKV ¶
ConvertToStringFromKV gets value from map by key and converts it to string
func Diff ¶
func Diff[T comparable](first []T, second []T) (included, missing []T)
Diff returns the intersection and difference between two arrays Returns:
- included: values from first that exist in second
- missing: values from first that do NOT exist in second
func DiffJsonFieldValues ¶
func DiffJsonFieldValues[T comparable](valuesToCheck []T, jsonData []map[string]any, fieldName string) (included, missing []T)
DiffJsonFieldValues checks values existence between valuesToCheck and jsonData[fieldName] Returns:
- included: values from valuesToCheck that exist in jsonData[fieldName]
- missing: values from valuesToCheck that do NOT exist in jsonData[fieldName]
func ExtractMapValue ¶
ExtractMapValue retrieves a value from a map and deletes the key.
func FindCommonValues ¶
func FindCommonValues[K comparable, V comparable](arrays1, arrays2 []map[K]any, key K) []V
K is the type for the map key (usually string) V is the type for the values we're comparing (must be comparable) FindCommonValues finds common values in a specific key between two slices of maps.
func FindCommonValuesInMapString ¶
func FindCommonValuesInMapString[V comparable](arrays1, arrays2 []map[string]any, key string) []V
FindCommonValuesInMapString is a specialization of FindCommonValues for maps with string keys.
func Float64sToJSON ¶
Float64sToJSON converts a slice of float64s to a JSON string.
func FloatFitsInt64 ¶ added in v1.126.5
FloatFitsInt64 reports whether f is a whole number an int64 can hold. The bounds are checked on the float before any conversion: Go leaves an out-of-range float-to-int conversion undefined, so the converted value cannot be inspected afterwards.
func GetAllActualBindingAddress ¶
GetAllActualBindingAddress returns a list of actual binding addresses based on a configured address. If the configured IP is not found on the machine, it returns all available IPs with the configured port.
func GetAllMachineIP4s ¶
func GetAllMachineIP4s() []string
GetAllMachineIP4s retrieves all non-loopback IPv4 addresses of the machine.
func GetArrayFromV ¶
GetArrayFromV converts an `any` type to a slice of `any`.
Accepts a string as well as []byte, for the same reason as GetJSONFromV.
func GetBoolFromKV ¶
GetBoolFromKV retrieves a bool value for the given key.
func GetBuildTime ¶
func GetBuildTime() string
GetBuildTime retrieves the VCS build time from the build info.
func GetBytesFromKV ¶
GetBytesFromKV retrieves a []byte (byte slice) value for the given key.
func GetFloat64FromKV ¶
GetFloat64FromKV retrieves a float64 value for the given key.
func GetInt64FromKV ¶
GetInt64FromKV retrieves an int64 value for the given key from a map[string]any. It relies on the generic GetVFromKV function for key lookup and type assertion.
func GetIntFromKV ¶
GetIntFromKV retrieves an int value (default 32 or 64 bit) for the given key.
func GetKVFromKV ¶
GetKVFromKV retrieves a nested map[string]any (KV) from a map by key. This is an alias to GetJSONFromKV since JSON is defined as map[string]any.
func GetMapStringStringFromKV ¶
GetMapStringStringFromKV retrieves a map[string]string value for the given key.
func GetMapStringStringFromV ¶
GetMapStringStringFromV converts any value to map[string]string. Handles: direct map[string]string, []byte or string (JSON), map[string]any (converts values to string).
func GetMapValue ¶
GetMapValue safely retrieves and type-asserts a value from a map[string]any. Returns: - exists: True if the key exists in the map - value: The typed value if key exists and type assertion succeeds, nil otherwise - err: Error if type assertion fails for existing key
func GetMapValueFromJSONs ¶
GetMapValueFromJSONs extracts values for a given key from a slice of maps.
func GetStringFromKV ¶
GetStringFromKV retrieves a string value for the given key from a map[string]any. It relies on the generic GetVFromKV function to perform the key lookup and type assertion.
func GetTimeFromKV ¶
GetTimeFromKV retrieves a time.Time value for the given key.
func GetUint64FromKV ¶
GetUint64FromKV retrieves a uint64 value for the given key.
func GetVFromKV ¶
GetVFromKV retrieves a value of a specific generic type T from a map[string]any. Error messages are structured for client-side parsing and localization.
func GetValueFromNestedMap ¶
GetValueFromNestedMap retrieves a value from a nested map using a dot-separated key. It traverses the map based on the keys provided in the dot-separated string. For example, given a map `{"a": {"b": 1}}` and a key `"a.b"`, it will return `1`. If any key in the path does not exist, it returns an error.
func IfFloatIsInt ¶
IfFloatIsInt reports whether f is a finite whole number: no fractional part in either sign, and neither NaN nor an infinity. It says nothing about whether the value fits an int64; FloatFitsInt64 adds that.
The earlier test, f - float64(int64(f)) > 0, saw only a positive remainder, so a negative fraction such as -5.5 passed and was truncated downstream.
func Int64SliceToStrings ¶
Int64SliceToStrings converts a slice of int64 to a slice of strings.
func Int64ToBytes ¶
Int64ToBytes encodes v as an 8-byte big-endian slice.
func Int64ToString ¶
Int64ToString converts an int64 to a string.
func Int64sIsContain ¶
Int64sIsContain checks if a slice of int64s contains a specific value.
func Int64sToJSON ¶
Int64sToJSON converts a slice of int64s to a JSON string.
func Int64sToStrings ¶
Int64sToStrings converts a slice of int64s to a slice of strings.
func IntsToJSON ¶
IntsToJSON converts a slice of ints to a JSON string.
func IsCredentialHeader ¶ added in v1.126.3
IsCredentialHeader reports whether a header carries a credential: it is in the built-in list, in the host's list, or its name holds one of the credential keywords.
func IsSensitiveField ¶
IsSensitiveField checks if a field name contains sensitive keywords. This is a unified function to detect sensitive data across the codebase.
func IsValuesMatch ¶
func JSONToBytes ¶
JSONToBytes converts a JSON object to a byte slice.
func JSONToMapStringString ¶
JSONToMapStringString converts a JSON object to a map[string]string.
func JSONToString ¶
JSONToString converts a JSON object to a string.
func Mask2by2 ¶ added in v1.126.5
Mask2by2 keeps the first 2 and the last 2 runes of the whole value.
func MaskDefaultDeny ¶
func MaskDefaultDeny() bool
MaskDefaultDeny reports the current default, so a host can log which posture it started in.
func MaskEmail2by2 ¶ added in v1.126.5
MaskEmail2by2 masks an e-mail address. The local part keeps its first 2 and last 2 runes with a fixed "***" between, or only its first rune when it has 4 or fewer. The domain is split into a known public ending (MaskEmailKnownEndings, the longest match, kept as written) and the rest before it, sub-domains included, which keeps its first 2 runes then "***", or only its first rune when it has 2 or fewer. A domain with no known ending keeps its first 2 runes then "***". A value with no "@" is "***".
adinda@example.co.id → ad***da@ex***.co.id x@mail.example.co.id → x***@ma***.co.id adinda@example.xyz → ad***da@ex***
func MaskFrontBack ¶ added in v1.126.5
MaskFrontBack keeps the first front and the last back runes of s with a fixed "***" between them. A value of front+back+3 runes or fewer keeps only its first rune: "PNS-1" with 2 and 2 is "P***", "Pegawai" is "P***", "Pegawai S" is "Pe*** S". With front 0 a short value keeps nothing. An empty value is "***".
func MaskHeaderValue ¶ added in v1.126.3
MaskHeaderValue returns the value a dump may show for a header: "***REDACTED***" for a credential header, the value itself otherwise. The debug override (IsDebug with OverrideShowPasswordOnLog) shows every header raw, as it does for a body.
func MaskInitials ¶ added in v1.126.5
MaskInitials is a name: the first rune of each word followed by a fixed "***", "Budi Santoso" → "B*** S***". The rest of the word, however long, is three asterisks, so the mask gives away neither the word nor its length. An empty or all-whitespace value is fully masked.
func MaskLocation2Decimals ¶ added in v1.126.5
MaskLocation2Decimals is a coordinate rounded to two decimals (about 1 km). A number stays a number (as a float64); a string is read as comma-separated coordinates and rounded term by term, keeping the string form. Anything that is not a coordinate is fully masked.
func MaskNumber ¶ added in v1.126.5
MaskNumber is MaskFrontBack on a number after its spaces and dashes are dropped, so the kept characters are digits and the grouping, which would show the length, is gone: "0812-3456-7789" with 4 and 3 is "0812***789".
func MaskNumber2by4 ¶ added in v1.126.5
MaskNumber2by4 is an account number: the first 2 and the last 4 digits.
func MaskNumber4by3 ¶ added in v1.126.5
MaskNumber4by3 is a phone number: the first 4 (the operator prefix) and the last 3.
func MaskNumber5by4 ¶ added in v1.126.5
MaskNumber5by4 is a national ID or family card number: the first 5 digits (the region of registration) and the last 4.
func MaskNumber6by4 ¶ added in v1.126.5
MaskNumber6by4 is a card number: the first 6 (the issuer) and the last 4.
func MaskRedacted ¶ added in v1.126.5
MaskRedacted is the marker for a secret, a token or an image: "***REDACTED***".
func MaskSensitiveValue ¶
func MaskSensitiveValue(fieldName string, value interface{}) interface{}
MaskSensitiveValue masks a value for logging.
- Credential fields (IsSensitiveField): ALWAYS "***REDACTED***".
- PII fields (SetMaskRules): masked by the rule's kind (partial Front+Back, e-mail, initials or location) unless SetMaskStrict → full.
- Unmatched fields: logged as-is under default-ALLOW, masked under default-DENY unless SetLogAllowedFields names them (SetMaskDefaultDeny).
- Requires BOTH dxlib.IsDebug AND OverrideShowPasswordOnLog to show raw values (prevents accidental exposure from a single env flip).
func MustConvertToInterfaceStringFromAny ¶
MustConvertToInterfaceStringFromAny converts a value of any type to a string interface, panicking on error.
func NowAsString ¶
func NowAsString() string
NowAsString returns the current UTC time as a string in RFC3339 format.
func RemoveDuplicates ¶
func RemoveDuplicates[T comparable](slice []T) []T
RemoveDuplicates removes duplicate values from a slice of any comparable type
func SetCredentialHeaders ¶ added in v1.126.3
func SetCredentialHeaders(names []string)
SetCredentialHeaders replaces the host's own list of credential headers (called once at init). Names are matched case-insensitively. The built-in list and the credential keywords stay in force; this only adds.
func SetLogAllowedFields ¶
func SetLogAllowedFields(names []string)
SetLogAllowedFields replaces the set of field names that stay readable under default-deny. Matched EXACTLY (lowercased), deliberately unlike maskRules: a deny rule should be fuzzy so it catches `foto_ktp` from `ktp`, but an ALLOW rule must not, or a substring like `id` would silently un-mask `national_id`.
func SetMaskDefaultDeny ¶
func SetMaskDefaultDeny(b bool)
SetMaskDefaultDeny chooses what happens to a field the rules do not mention: false = log it (default, current behaviour), true = mask it unless SetLogAllowedFields names it. Called once by the host at init from its own configuration; see maskDefaultDeny for why this is a switch.
func SetMaskRules ¶
SetMaskRules replaces the PII field→rule map (called once by the host at init).
func SetMaskStrict ¶
func SetMaskStrict(b bool)
SetMaskStrict forces full masking of PII regardless of per-field rules (prod hardening).
func SetValueInNestedMap ¶
SetValueInNestedMap sets a value in a nested map using a dot-separated key. It creates nested maps if they don't exist.
func ShouldStrictJSONToMapStringString ¶
ShouldStrictJSONToMapStringString strictly converts a JSON object to a map[string]string, returning an error if any value is not a string.
func StringIsInSlice ¶
StringIsInSlice checks if a string exists in a slice of strings.
func StringsHasCommonItem ¶
StringsHasCommonItem checks if two string slices have any common items.
func StringsIsContain ¶
StringsIsContain checks if a slice of strings contains a specific value.
func StringsToJSON ¶
StringsToJSON converts a slice of strings to a JSON string.
func TCPAddressCanConnect ¶
TCPAddressCanConnect checks if a TCP connection can be established to a given address.
func TCPIPPortCanConnect ¶
TCPIPPortCanConnect checks if a TCP connection can be established to a given IP and port.
func TimeSubToString ¶
TimeSubToString returns the string representation of the duration between two time.Time objects.
func TsIsContain ¶
func TsIsContain[T comparable](arr []T, v T) bool
TsIsContain checks if a slice of a comparable type contains a specific value.
func TsIsInSlice ¶
func TsIsInSlice[T comparable](v []T, aSlice []T) bool
TsIsInSlice checks if all elements of a slice exist in another slice.
func TypeAsString ¶
TypeAsString returns the type of a variable as a string.
func Uint32ToBytes ¶
Uint32ToBytes encodes v as a 4-byte big-endian slice.
func WriteHeadersForLog ¶ added in v1.126.3
WriteHeadersForLog renders h as "Name: value" lines, one per value, in name order, with every credential value masked and any line break inside a value turned into a space so a value cannot forge a line of its own. Names in exclude are left out (a dump writes Host and the framing headers itself). It returns the text, ready to append to a dump.
Types ¶
type JSON ¶
JSON is a type alias for map[string]any, representing a JSON object.
func GetJSONFromKV ¶
GetJSONFromKV retrieves a JSON object from a map by key.
func GetJSONFromV ¶
GetJSONFromV converts an `any` type to a JSON object.
A JSON/CLOB column does not arrive as []byte on every engine: Oracle hands a CLOB back as a Go string, and row-type normalisation turns a []byte text column into a string before this runs. Accept both encodings of the same document rather than rejecting one of them as "not JSON".
func MapStringStringToJSON ¶
MapStringStringToJSON converts a map[string]string to a JSON object.
func MaskForLog ¶ added in v1.126.2
MaskForLog returns a deep copy of data with every value masked the way MaskSensitiveValue masks it, at every depth: nested objects, arrays, and objects inside arrays all get the same treatment, so a body that puts everything under one "params" key is masked the same as a flat one. The credential keywords, the host's PII rules (SetMaskRules, SetMaskStrict) and the default-deny switch (SetMaskDefaultDeny, SetLogAllowedFields) all apply, each to the leaf field's own name.
A key that matches a credential keyword masks whatever it holds, object or array, whole as "***REDACTED***". A key that matches a PII rule and holds an object masks it whole as "********": there is no front or back of a nested object to reveal, and fail-closed is the safer reading. The one exception is MaskKindLocation, which walks the object and rounds its numeric leaves. An array's elements take the array's key, so {"phone_numbers": ["0812...", "0813..."]} masks each number under the rule that matches phone_numbers, and an object inside that array is masked whole.
Use it for anything written to a log; it never changes the data it is given.
func MaskSensitiveDataInJSON ¶
MaskSensitiveDataInJSON recursively masks sensitive fields in a JSON structure. Returns a deep copy with sensitive values replaced by "***REDACTED***".
Only the built-in credential keywords (IsSensitiveField) apply here, at any depth of nested objects; arrays are copied as they are. It serves configuration.FilterSensitiveData, whose readers expect the host's PII rules and default-deny posture NOT to apply (a DENY host's config dump would otherwise go blank). A log dump of request or response data goes through MaskForLog instead.
func StringToJSON ¶
StringToJSON converts a JSON string to a JSON object.
type MaskKind ¶ added in v1.126.2
type MaskKind int
MaskKind selects how a PII field is masked. The zero value, MaskKindPartial, is the original Front+Back rule, so a host's existing rules keep their meaning.
const ( // MaskKindPartial keeps Front leading and Back trailing characters of the whole value with a // fixed "***" between them (MaskFrontBack). {Front: 0, Back: 0} (or MaskStrict) is the full // "********". MaskKindPartial MaskKind = iota // MaskKindEmail is MaskEmail2by2: "adinda@mail.example.co.id" becomes "ad***da@ma***.co.id". MaskKindEmail // MaskKindInitials keeps the first letter of each word and masks the rest of it with three // asterisks, three whatever the word's length: "Budi Santoso" becomes "B*** S***". Words // are split on any run of whitespace, so surrounding and doubled spaces vanish; a // one-letter word is "A***" too, so a word's length cannot be read off the mask; a // hyphenated name is one word. An empty value is fully masked. MaskKindInitials // MaskKindLocation rounds a coordinate to two decimals (about 1 km), so an area is logged, // not a doorstep. It applies to a number, a "lat,lng" string, and, unlike the other kinds, // to the numeric leaves of an object or array under the key, so {"location": {"lat": .., // "lng": ..}} is walked rather than masked whole. A value that is not a coordinate is fully // masked. MaskKindLocation // MaskKindNumber is MaskKindPartial for a number written with spaces or dashes: they are // dropped first, so only digits are kept at the ends (MaskNumber). MaskKindNumber // MaskKindRedacted replaces the value with "***REDACTED***", the marker for a secret. MaskKindRedacted )
Directories
¶
| Path | Synopsis |
|---|---|
|
crypto
|
|
|
x25519
Package x25519 performs X25519 key agreement (RFC 7748) on raw 32-byte keys, as peers exchange them on the wire.
|
Package x25519 performs X25519 key agreement (RFC 7748) on raw 32-byte keys, as peers exchange them on the wire. |
|
Package tls builds the crypto/tls configuration for the API server and for the process's outbound HTTP and WebSocket clients from a configuration block, so that every hop that terminates or originates TLS in a dxlib process reads its trust the same way and from the same code.
|
Package tls builds the crypto/tls configuration for the API server and for the process's outbound HTTP and WebSocket clients from a configuration block, so that every hop that terminates or originates TLS in a dxlib process reads its trust the same way and from the same code. |
|
tlstest
Package tlstest builds a throwaway PKI in memory for tests: a root, an intermediate, and leaves with whatever SANs, validity windows and key sizes a test needs, written to PEM files on demand.
|
Package tlstest builds a throwaway PKI in memory for tests: a root, an intermediate, and leaves with whatever SANs, validity windows and key sizes a test needs, written to PEM files on demand. |
|
Package xlsx writes a one-sheet .xlsx workbook of text cells, streaming the rows into an io.Writer.
|
Package xlsx writes a one-sheet .xlsx workbook of text cells, streaming the rows into an io.Writer. |