Documentation
¶
Overview ¶
Package kitutil holds the dependency-free helpers shared by the conversion kit packages (dto, types, relayconvert). It moved out of the host's common package as part of the relaykit extraction; common re-exports these for host code.
Index ¶
- Variables
- func Any2Type[T any](data any) (T, error)
- func DecodeJson(reader io.Reader, v any) error
- func GetJsonType(data json.RawMessage) string
- func GetPointer[T any](v T) *T
- func GetTimestamp() int64
- func GetUUID() string
- func Interface2String(inter any) string
- func JsonRawMessageToString(data json.RawMessage) string
- func LogError(message string)
- func LogInfo(message string)
- func LogSystemError(message string)
- func Marshal(v any) ([]byte, error)
- func MaskSensitiveInfo(str string, upstreamURLs ...string) string
- func ObjectMember(data []byte, key string) json.RawMessage
- func SetCodec(c Codec)
- func SetLogging(info LogFunc, errorFn LogFunc)
- func SetSystemErrorLogging(errorFn LogFunc)
- func String2Int(str string) int
- func StringToByteSlice(s string) []byte
- func Unmarshal(data []byte, v any) error
- func UnmarshalJsonStr(data string, v any) error
- func UnmarshalNoCopy(data []byte, v any) error
- func Valid(data []byte) bool
- type Codec
- type LogFunc
Constants ¶
This section is empty.
Variables ¶
var Debug atomic.Bool
Debug reports whether verbose kit diagnostics are enabled. The host sets this once at startup (new-api mirrors common.DebugEnabled into it).
Functions ¶
func GetJsonType ¶
func GetJsonType(data json.RawMessage) string
func GetPointer ¶
func GetPointer[T any](v T) *T
func GetTimestamp ¶
func GetTimestamp() int64
func Interface2String ¶
func JsonRawMessageToString ¶
func JsonRawMessageToString(data json.RawMessage) string
JsonRawMessageToString returns JSON strings as their decoded value and other JSON values as raw text.
func LogSystemError ¶
func LogSystemError(message string)
LogSystemError reports an internal converter failure through its dedicated hook, keeping it distinct from malformed request-data diagnostics.
func MaskSensitiveInfo ¶
MaskSensitiveInfo masks the upstream addresses in str and leaves every other URL and domain readable. upstreamURLs are the channel base URL and the URL the gateway actually requested, which differs for routes such as absolute Advanced Custom paths; empty entries are skipped. Credentials and IPv4 addresses are masked regardless of the upstream: API key values, the query values and userinfo of every URL, which carry secrets such as client_secret or key on provider endpoints, and IPs, which in network errors include the gateway's own address. Example with upstream https://api.upstream.example.com: https://api.upstream.example.com/v1/chat?key=secret -> https://***.com/***/***?key=*** lookup api.upstream.example.com -> lookup ***.***.***.com dial tcp 192.168.1.1:443 -> dial tcp ***.***.***.***:443 https://docs.example.org/errors -> unchanged https://auth.example.org/token?client_secret=s -> https://auth.example.org/token?client_secret=***
func ObjectMember ¶ added in v0.3.6
func ObjectMember(data []byte, key string) json.RawMessage
ObjectMember returns a member of a JSON object exactly as written, or nil when the member is missing or null or data is not an object. A decoded map encoded again would sort the keys of nested objects, such as the property order of a schema.
func SetCodec ¶ added in v0.2.1
func SetCodec(c Codec)
SetCodec installs the JSON engine behind every kitutil JSON helper, which also covers the custom (Un)MarshalJSON methods on relaykit DTOs. Like SetLogging it is meant to be called once during host startup before any request is served; it is not synchronized against concurrent helper calls. A nil codec is ignored so the standard-library default stays in place.
func SetLogging ¶
func SetSystemErrorLogging ¶
func SetSystemErrorLogging(errorFn LogFunc)
SetSystemErrorLogging configures the hook for internal converter failures.
func String2Int ¶
func StringToByteSlice ¶
func UnmarshalJsonStr ¶
func UnmarshalNoCopy ¶ added in v0.3.8
UnmarshalNoCopy lets supporting codecs borrow strings and raw JSON from data. Keep data and borrowed raw JSON immutable while decoded values are in use. Other codecs use their ordinary Unmarshal implementation.
Types ¶
type Codec ¶ added in v0.2.1
type Codec interface {
Marshal(v any) ([]byte, error)
Unmarshal(data []byte, v any) error
Decode(r io.Reader, v any) error
Valid(data []byte) bool
}
Codec is the JSON engine used by every kitutil JSON helper. The host may replace it once at startup via SetCodec; relaykit itself never depends on a third-party JSON library.