utils

package
v0.13.0-test.4 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const CustomTypesContextKey contextKey = "custom_types"
View Source
const ExecutionIdContextKey contextKey = "execution_id"
View Source
const FunctionMessagesContextKey contextKey = "function_messages"
View Source
const FunctionNameContextKey contextKey = "function_name"
View Source
const FunctionOutputContextKey contextKey = "function_output"
View Source
const MetadataContextKey contextKey = "metadata"
View Source
const PluginContextKey contextKey = "plugin"
View Source
const TimeFormat = "2006-01-02T15:04:05.000Z"

TimeFormat is the default time format template throughout the application. It is used for output to logs, query results, etc.

View Source
const WasmAdapterContextKey contextKey = "wasm_adapter"
View Source
const WasmHostContextKey contextKey = "wasm_host"

Variables

This section is empty.

Functions

func CanBeNil

func CanBeNil(rt reflect.Type) bool

func Cast

func Cast[T any](obj any) (T, error)

func ConvertToError

func ConvertToError(e any) error

func ConvertToMap

func ConvertToMap(input any) (map[any]any, error)

func ConvertToSlice

func ConvertToSlice(input any) ([]any, error)

func ConvertToSliceOf

func ConvertToSliceOf[T any](obj any) ([]T, bool)

func CopyMemory

func CopyMemory(mem wasm.Memory, sourceOffset, targetOffset, size uint32) bool

func DebugModeEnabled

func DebugModeEnabled() bool

func DecodeUTF16

func DecodeUTF16(bytes []byte) string

func DereferencePointer

func DereferencePointer(obj any) any

func EncodeUTF16

func EncodeUTF16(str string) []byte

func EnvVarFlagEnabled

func EnvVarFlagEnabled(envVarName string) bool

func FlushSentryEvents

func FlushSentryEvents()

func GenerateUUIDv7

func GenerateUUIDv7() string

func GetTime

func GetTime() time.Time

GetTime returns the current time.

func HasNil

func HasNil(x any) bool

HasNil returns true if the given interface value is nil, or contains an object that is nil.

func HttpClient

func HttpClient() *http.Client

func InitSentry

func InitSentry(rootPath string)

func JsonDeserialize

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

JsonDeserialize deserializes the given JSON data into the given value. Unlike json.Unmarshal, it does not automatically use a float64 type for numbers. It uses goccy/go-json to improve performance.

func JsonSerialize

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

JsonSerialize serializes the given value to JSON. Unlike json.Marshal, it does not escape HTML characters. It uses goccy/go-json to improve performance.

func MakePointer

func MakePointer(obj any) any

func MapKeys

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

func MapKeysAndValues

func MapKeysAndValues[M ~map[K]V, K comparable, V any](m M) ([]K, []V)

func MapToStruct

func MapToStruct(m map[string]any, result any) error

func MapValues

func MapValues[M ~map[K]V, K comparable, V any](m M) []V

func NewSentrySpan

func NewSentrySpan(ctx context.Context, funcName string) (*sentry.Span, context.Context)

func NewSentrySpanForCallingFunc

func NewSentrySpanForCallingFunc(ctx context.Context) (*sentry.Span, context.Context)

func NewSentrySpanForCurrentFunc

func NewSentrySpanForCurrentFunc(ctx context.Context) (*sentry.Span, context.Context)

func NilIf

func NilIf[T any](condition bool, val T) *T

func NilIfEmpty

func NilIfEmpty(val string) *string

func ParseTime

func ParseTime(s string) (time.Time, error)

ParseTime parses a string into a time.Time object. It tries multiple formats to parse the string.

func SplitConsoleOutputLine

func SplitConsoleOutputLine(line string) (level string, message string)

func TraceModeEnabled

func TraceModeEnabled() bool

func TrimStringBefore

func TrimStringBefore(s string, sep string) string

func WriteJsonContentHeader

func WriteJsonContentHeader(w http.ResponseWriter)

Types

type Cleaner

type Cleaner interface {
	Clean() error
	AddCleanup(fn func() error)
	AddCleaner(c Cleaner)
}

func NewCleaner

func NewCleaner() Cleaner

func NewCleanerN

func NewCleanerN(capacity int) Cleaner

type HttpResult

type HttpResult[T any] struct {
	Data      T
	StartTime time.Time
	EndTime   time.Time
}

func PostHttp

func PostHttp[TResult any](ctx context.Context, url string, payload any, beforeSend func(context.Context, *http.Request) error) (*HttpResult[TResult], error)

func (HttpResult[T]) Duration

func (r HttpResult[T]) Duration() time.Duration

type JSONTime

type JSONTime time.Time

JSONTime extends the time type so that when it marshals to JSON the output is fixed to include milliseconds as three digits.

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

func (JSONTime) String

func (t JSONTime) String() string

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) error

type LogMessage

type LogMessage struct {
	Level   string `json:"level,omitempty"`
	Message string `json:"message"`
}

func TransformConsoleOutput

func TransformConsoleOutput(buffers OutputBuffers) []LogMessage

func (LogMessage) IsError

func (l LogMessage) IsError() bool

type OutputBuffers

type OutputBuffers interface {
	StdOut() *bytes.Buffer
	StdErr() *bytes.Buffer
}

func NewOutputBuffers

func NewOutputBuffers() OutputBuffers

Jump to

Keyboard shortcuts

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