utils

package
v0.98.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package utils provides shared utility functions.

Index

Constants

View Source
const EmbedServerPort = "15656"

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without allocation.

func CheckSingleton added in v0.13.1

func CheckSingleton() error

func Contains added in v0.93.0

func Contains[T comparable](slice []T, item T) bool

Contains reports whether item is present in slice.

func DecodeJSON added in v0.35.2

func DecodeJSON(r io.Reader, v any) error

func DefaultRestyClient added in v0.35.2

func DefaultRestyClient() *resty.Client

func DownloadFile added in v0.32.1

func DownloadFile(url, filename string) error

func EmbedServer added in v0.13.1

func EmbedServer() error

func EncodeJSON added in v0.35.2

func EncodeJSON(w io.Writer, v any) error

func EncodeJSONEscapeHTML added in v0.35.2

func EncodeJSONEscapeHTML(w io.Writer, v any, esc bool) error

func EncodeJSONEscapeHTMLIndent added in v0.35.2

func EncodeJSONEscapeHTMLIndent(w io.Writer, v any, esc bool, indent string) error

func FileExist

func FileExist(name string) bool

func GetFunctionName

func GetFunctionName(i any) string

func GetRemoteAddr

func GetRemoteAddr(req *http.Request) string

GetRemoteAddr Obtain IP address of the client.

func HTTPTransport added in v0.92.0

func HTTPTransport() *http.Transport

HTTPTransport returns the shared HTTP transport with connection pool tuning. Provider implementations that create raw http.Client instances should use this instead of http.DefaultTransport to ensure consistent pool behavior across all outgoing provider calls.

func HasHan

func HasHan(txt string) bool

func HostInfo added in v0.35.1

func HostInfo() (string, string, error)

func Int64ToInt32 added in v0.97.8

func Int64ToInt32(n int64) (int32, bool)

Int64ToInt32 converts n to int32 when it fits in the int32 range.

func IntToInt32 added in v0.97.8

func IntToInt32(n int) (int32, bool)

IntToInt32 converts n to int32 when it fits in the int32 range.

func IntToUint32 added in v0.97.8

func IntToUint32(n int) (uint32, bool)

IntToUint32 converts n to uint32 when it is non-negative and within range.

func IsRoutableIP

func IsRoutableIP(ipStr string) bool

func IsUnixAddr

func IsUnixAddr(addr string) bool

IsUnixAddr Check if specified address is a unix socket like "unix:/run/flowbot.sock".

func IsUrl

func IsUrl(text string) bool

func MarkdownSanitizePolicy added in v0.97.8

func MarkdownSanitizePolicy() *bluemonday.Policy

MarkdownSanitizePolicy returns bluemonday.UGCPolicy extended for KaTeX MathML and layout attributes produced by goldmark-katex.

func MarkdownToHTML added in v0.93.0

func MarkdownToHTML(source []byte) ([]byte, error)

MarkdownToHTML converts GitHub-flavored markdown into HTML. goldmark uses html.WithUnsafe so embedded HTML in markdown is preserved; callers that render in a browser MUST sanitize (prefer MarkdownToSafeHTML).

func MarkdownToSafeHTML added in v0.97.8

func MarkdownToSafeHTML(source []byte) ([]byte, error)

MarkdownToSafeHTML converts markdown to HTML and sanitizes it for browser display. Use this (not MarkdownToHTML alone) before templ.Raw / template.HTML.

func NetListener

func NetListener(addr string) (net.Listener, error)

NetListener creates net.Listener for tcp and unix domains: if addr is in the form "unix:/run/flowbot.sock" it's a unix socket, otherwise TCP host:port.

func NewUUID

func NewUUID() string

func ParseFunctionName

func ParseFunctionName(name string) (string, string)

func PortAvailable added in v0.13.1

func PortAvailable(port string) bool

func RandomString added in v0.32.1

func RandomString(n int) (string, error)

func RestyClientWithTrace added in v0.92.0

func RestyClientWithTrace() *resty.Client

RestyClientWithTrace returns a resty client configured with OTel HTTP tracing. It is an alias of DefaultRestyClient; providers should call SetContext(ctx) on individual requests so client spans nest under the caller's span.

func SHA256 added in v0.92.0

func SHA256(txt string) string

func SameStringSlice

func SameStringSlice(x, y []string) bool

func SanitizeHTML added in v0.97.8

func SanitizeHTML(raw []byte) []byte

SanitizeHTML strips unsafe tags/attributes using MarkdownSanitizePolicy (UGC + KaTeX).

func SignalHandler added in v0.18.1

func SignalHandler() <-chan bool

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without allocation.

func ToAbsolutePath

func ToAbsolutePath(base, path string) string

ToAbsolutePath Convert relative filepath to absolute.

func Uint64ToInt64 added in v0.97.8

func Uint64ToInt64(n uint64) (int64, bool)

Uint64ToInt64 converts n to int64 when it fits in the int64 range.

func Uint64ToUint32 added in v0.97.8

func Uint64ToUint32(n uint64) (uint32, bool)

Uint64ToUint32 converts n to uint32 when it fits in the uint32 range.

func ValidImageContentType

func ValidImageContentType(ct string) bool

Types

This section is empty.

Directories

Path Synopsis
Package reexec facilitates the busybox style reexec of the docker binary that we require because of the forking limitations of using Go.
Package reexec facilitates the busybox style reexec of the docker binary that we require because of the forking limitations of using Go.
Package sets provides generic set data structures.
Package sets provides generic set data structures.
Package syncx provides synchronized concurrent-safe data structures.
Package syncx provides synchronized concurrent-safe data structures.

Jump to

Keyboard shortcuts

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