Documentation
¶
Overview ¶
Package utils provides shared utility functions.
Index ¶
- Constants
- func BytesToString(b []byte) string
- func CheckSingleton() error
- func Contains[T comparable](slice []T, item T) bool
- func DecodeJSON(r io.Reader, v any) error
- func DefaultRestyClient() *resty.Client
- func DownloadFile(url, filename string) error
- func EmbedServer() error
- func EncodeJSON(w io.Writer, v any) error
- func EncodeJSONEscapeHTML(w io.Writer, v any, esc bool) error
- func EncodeJSONEscapeHTMLIndent(w io.Writer, v any, esc bool, indent string) error
- func FileExist(name string) bool
- func GetFunctionName(i any) string
- func GetRemoteAddr(req *http.Request) string
- func HTTPTransport() *http.Transport
- func HasHan(txt string) bool
- func HostInfo() (string, string, error)
- func Int64ToInt32(n int64) (int32, bool)
- func IntToInt32(n int) (int32, bool)
- func IntToUint32(n int) (uint32, bool)
- func IsRoutableIP(ipStr string) bool
- func IsUnixAddr(addr string) bool
- func IsUrl(text string) bool
- func MarkdownSanitizePolicy() *bluemonday.Policy
- func MarkdownToHTML(source []byte) ([]byte, error)
- func MarkdownToSafeHTML(source []byte) ([]byte, error)
- func NetListener(addr string) (net.Listener, error)
- func NewUUID() string
- func ParseFunctionName(name string) (string, string)
- func PortAvailable(port string) bool
- func RandomString(n int) (string, error)
- func RestyClientWithTrace() *resty.Client
- func SHA256(txt string) string
- func SameStringSlice(x, y []string) bool
- func SanitizeHTML(raw []byte) []byte
- func SignalHandler() <-chan bool
- func StringToBytes(s string) []byte
- func ToAbsolutePath(base, path string) string
- func Uint64ToInt64(n uint64) (int64, bool)
- func Uint64ToUint32(n uint64) (uint32, bool)
- func ValidImageContentType(ct string) bool
Constants ¶
const EmbedServerPort = "15656"
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶
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 DefaultRestyClient ¶ added in v0.35.2
func DownloadFile ¶ added in v0.32.1
func EmbedServer ¶ added in v0.13.1
func EmbedServer() error
func EncodeJSONEscapeHTML ¶ added in v0.35.2
func EncodeJSONEscapeHTMLIndent ¶ added in v0.35.2
func GetFunctionName ¶
func GetRemoteAddr ¶
GetRemoteAddr Obtain IP address of the client.
func HTTPTransport ¶ added in v0.92.0
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 Int64ToInt32 ¶ added in v0.97.8
Int64ToInt32 converts n to int32 when it fits in the int32 range.
func IntToInt32 ¶ added in v0.97.8
IntToInt32 converts n to int32 when it fits in the int32 range.
func IntToUint32 ¶ added in v0.97.8
IntToUint32 converts n to uint32 when it is non-negative and within range.
func IsRoutableIP ¶
func IsUnixAddr ¶
IsUnixAddr Check if specified address is a unix socket like "unix:/run/flowbot.sock".
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
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
MarkdownToSafeHTML converts markdown to HTML and sanitizes it for browser display. Use this (not MarkdownToHTML alone) before templ.Raw / template.HTML.
func NetListener ¶
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 ParseFunctionName ¶
func PortAvailable ¶ added in v0.13.1
func RandomString ¶ added in v0.32.1
func RestyClientWithTrace ¶ added in v0.92.0
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 SameStringSlice ¶
func SanitizeHTML ¶ added in v0.97.8
SanitizeHTML strips unsafe tags/attributes using MarkdownSanitizePolicy (UGC + KaTeX).
func SignalHandler ¶ added in v0.18.1
func SignalHandler() <-chan bool
func StringToBytes ¶
StringToBytes converts string to byte slice without allocation.
func ToAbsolutePath ¶
ToAbsolutePath Convert relative filepath to absolute.
func Uint64ToInt64 ¶ added in v0.97.8
Uint64ToInt64 converts n to int64 when it fits in the int64 range.
func Uint64ToUint32 ¶ added in v0.97.8
Uint64ToUint32 converts n to uint32 when it fits in the uint32 range.
func ValidImageContentType ¶
Types ¶
This section is empty.
Source Files
¶
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. |