utils

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const SyftBoxArt = `` /* 214-byte string literal not displayed */

Variables

View Source
var (
	ErrInvalidEmail = errors.New("invalid email")
)
View Source
var (
	ErrInvalidURL = errors.New("invalid url")
)
View Source
var (
	HWID, _ = machineid.ProtectedID("syftbox")
)

Functions

func DetectContentType added in v0.8.0

func DetectContentType(key string) string

func DirExists

func DirExists(path string) bool

func EnsureDir

func EnsureDir(path string) error

func EnsureParent

func EnsureParent(path string) error

func FileExists

func FileExists(path string) bool

func GetFreePort

func GetFreePort() (int, error)

func IsValidEmail

func IsValidEmail(email string) bool

func IsValidURL

func IsValidURL(urlString string) bool

func IsWritable added in v0.7.0

func IsWritable(path string) bool

func Map

func Map[T, U any](seq iter.Seq[T], f func(T) U) iter.Seq[U]

func MaskSecret

func MaskSecret(s string) string

func ResolvePath

func ResolvePath(path string) (string, error)

func TokenHex

func TokenHex(len int) string

func ValidateEmail

func ValidateEmail(email string) error

func ValidateURL

func ValidateURL(urlString string) error

Types

type LogInterceptor

type LogInterceptor struct {
	// contains filtered or unexported fields
}

LogInterceptor implements io.Writer and intercepts output to add structured logging information. It adds a sequence number and timestamp to each line of output.

func NewLogInterceptor

func NewLogInterceptor(target io.WriteCloser) *LogInterceptor

NewLogInterceptor creates a new LogInterceptor that adds structured logging information to each line. The interceptor will write to the provided target writer, adding a sequence number and timestamp to each line of output.

func (*LogInterceptor) Close

func (i *LogInterceptor) Close() error

Close flushes any remaining buffered data to the target writer and closes it. If there's incomplete line data in the buffer, it will be written without a trailing newline. Returns any error encountered during the flush or close operation.

func (*LogInterceptor) Write

func (i *LogInterceptor) Write(p []byte) (n int, err error)

Write implements io.Writer. It processes input data line by line, adding sequence numbers and timestamps to each complete line. Incomplete lines are buffered until a newline is received. Returns the number of bytes from p that were processed and any error encountered.

type MultiLogHandler

type MultiLogHandler struct {
	// contains filtered or unexported fields
}

MultiLogHandler implements slog.Handler interface and forwards logs to multiple handlers

func NewMultiLogHandler

func NewMultiLogHandler(handlers ...slog.Handler) *MultiLogHandler

NewMultiLogHandler creates a new MultiLogHandler that forwards logs to multiple handlers

func (*MultiLogHandler) Enabled

func (h *MultiLogHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled implements slog.Handler

func (*MultiLogHandler) Handle

func (h *MultiLogHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler

func (*MultiLogHandler) WithAttrs

func (h *MultiLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler

func (*MultiLogHandler) WithGroup

func (h *MultiLogHandler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler

type SyftBoxURL added in v0.6.0

type SyftBoxURL struct {
	Datasite    string            `json:"datasite"`
	AppName     string            `json:"app_name"`
	Endpoint    string            `json:"endpoint"`
	QueryParams map[string]string `json:"query_params"`
}

SyftBoxURL represents a parsed syft:// URL with its components

func FromSyftURL added in v0.6.0

func FromSyftURL(rawURL string) (*SyftBoxURL, error)

FromSyftURL parses a syft URL string into a SyftBoxURL struct

func NewSyftBoxURL added in v0.6.0

func NewSyftBoxURL(datasite, appName, endpoint string) (*SyftBoxURL, error)

NewSyftBoxURL creates a new SyftBoxURL with validation

func (*SyftBoxURL) BaseURL added in v0.6.0

func (s *SyftBoxURL) BaseURL() string

Syft base URL

func (*SyftBoxURL) MarshalJSON added in v0.8.2

func (s *SyftBoxURL) MarshalJSON() ([]byte, error)

func (*SyftBoxURL) SetQueryParams added in v0.6.0

func (s *SyftBoxURL) SetQueryParams(queryParams map[string]string)

SetQueryParams sets the query parameters

func (*SyftBoxURL) String added in v0.6.0

func (s *SyftBoxURL) String() string

String returns the string representation of the SyftBoxURL

func (*SyftBoxURL) ToLocalPath added in v0.6.0

func (s *SyftBoxURL) ToLocalPath() string

ToLocalPath converts the SyftBoxURL to a local file system path

func (*SyftBoxURL) UnmarshalJSON added in v0.8.2

func (s *SyftBoxURL) UnmarshalJSON(data []byte) error

func (*SyftBoxURL) UnmarshalParam added in v0.6.0

func (s *SyftBoxURL) UnmarshalParam(param string) error

UnmarshalParam implements gin.UnmarshalParam for automatic query param binding

func (*SyftBoxURL) Validate added in v0.6.0

func (s *SyftBoxURL) Validate() error

Validate validates the SyftBoxURL fields

type ValidationError added in v0.6.0

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error with field context

func (*ValidationError) Error added in v0.6.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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