kitutil

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 16 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 Any2Type

func Any2Type[T any](data any) (T, error)

func DecodeJson

func DecodeJson(reader io.Reader, v any) error

func GetJsonType

func GetJsonType(data json.RawMessage) string

func GetPointer

func GetPointer[T any](v T) *T

func GetTimestamp

func GetTimestamp() int64

func GetUUID

func GetUUID() string

func Interface2String

func Interface2String(inter any) string

func JsonRawMessageToString

func JsonRawMessageToString(data json.RawMessage) string

JsonRawMessageToString returns JSON strings as their decoded value and other JSON values as raw text.

func LogError

func LogError(message string)

func LogInfo

func LogInfo(message string)

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 Marshal

func Marshal(v any) ([]byte, error)

func MaskSensitiveInfo

func MaskSensitiveInfo(str string, upstreamURLs ...string) string

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 SetLogging(info LogFunc, errorFn LogFunc)

func SetSystemErrorLogging

func SetSystemErrorLogging(errorFn LogFunc)

SetSystemErrorLogging configures the hook for internal converter failures.

func String2Int

func String2Int(str string) int

func StringToByteSlice

func StringToByteSlice(s string) []byte

func Unmarshal

func Unmarshal(data []byte, v any) error

func UnmarshalJsonStr

func UnmarshalJsonStr(data string, v any) error

func UnmarshalNoCopy added in v0.3.8

func UnmarshalNoCopy(data []byte, v any) error

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.

func Valid added in v0.2.1

func Valid(data []byte) bool

Valid reports whether data is a syntactically valid JSON document.

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.

type LogFunc

type LogFunc func(message string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL