util

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package util contains multiple utils for Fish

Index

Constants

View Source
const (
	B  HumanSize = 1
	KB           = B << 10
	MB           = KB << 10
	GB           = MB << 10
	TB           = GB << 10
	PB           = TB << 10
	EB           = PB << 10
)

Definitions of different byte sizes and some maximums

Variables

This section is empty.

Functions

func Contains

func Contains(list []string, value string) bool

Contains check the string slice contains string in it

func CreateLock

func CreateLock(lockPath string) error

CreateLock creates the lock file, notice - remove it yourself

func DotSerialize

func DotSerialize(prefix string, in any) map[string]string

DotSerialize serializes data to get map as key.subkey=value with dot separation for the keys

func FileCopy

func FileCopy(src string, dst string) error

FileCopy copies from one place to another

func FileReplaceBlock

func FileReplaceBlock(path, blockFrom, blockTo string, lines ...string) error

FileReplaceBlock is a simple block replace in the file

func FileReplaceToken

func FileReplaceToken(path string, fullLine, add, anycase bool, tokenValues ...string) error

FileReplaceToken simple replaces tocken in the file

func FileStartsWith

func FileStartsWith(path string, prefix []byte) error

FileStartsWith checks the file starts with required prefix

func RunAndLog added in v0.7.6

func RunAndLog(section string, timeout time.Duration, stdin io.Reader, path string, arg ...string) (string, string, error)

RunAndLog Runs & logs the executable command

func RunAndLogRetry added in v0.7.6

func RunAndLogRetry(section string, retry int, timeout time.Duration, stdin io.Reader, path string, arg ...string) (stdout string, stderr string, err error)

Will retry on error and store the retry output and errors to return

func SerializeMetadata

func SerializeMetadata(format, prefix string, data map[string]any) (out []byte, err error)

SerializeMetadata serializes dictionary to usable format

func WaitLock

func WaitLock(lockPath string, clean func()) error

WaitLock waits for the lock file and clean func will be executed if it's invalid

Types

type Duration added in v0.7.3

type Duration time.Duration

Duration is a simple wrapper to add serialization functions

func (Duration) MarshalJSON added in v0.7.3

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON represents Duration as JSON string

func (*Duration) StoreStringDuration added in v0.8.1

func (d *Duration) StoreStringDuration(s string) error

StoreStringDuration parses a duration string into a duration Example: "10d", "-1.5w" or "3Y4M5d" Added time units: d(D), w(W), M, y(Y)

func (*Duration) String added in v0.8.2

func (d *Duration) String() string

func (*Duration) UnmarshalJSON added in v0.7.3

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON parses JSON string as Duration

type HumanSize added in v0.7.5

type HumanSize uint64

HumanSize describes data size In Human Form

func NewHumanSize added in v0.7.5

func NewHumanSize(input string) (HumanSize, error)

NewHumanSize creates human size for you

func (HumanSize) Bytes added in v0.7.5

func (hs HumanSize) Bytes() uint64

Bytes returns amount of bytes stored in HumanSize

func (HumanSize) MarshalText added in v0.7.5

func (hs HumanSize) MarshalText() ([]byte, error)

MarshalText represents HumanSize as string

func (HumanSize) String added in v0.7.5

func (hs HumanSize) String() string

String represent HumanSize as human readable string

func (*HumanSize) UnmarshalText added in v0.7.5

func (hs *HumanSize) UnmarshalText(data []byte) error

UnmarshalText converts text to HumanSize number To be properly parsed the text should contain number and unit ("B", "KB", "MB"...) in the end

type PassThruMonitor

type PassThruMonitor struct {
	io.Reader
	Name   string // Prefix for the message
	Length int64  // Expected length
	// contains filtered or unexported fields
}

PassThruMonitor wraps an existing io.Reader to monitor the stream

It simply forwards the Read() call, while displaying the results from individual calls to it.

func (*PassThruMonitor) Read

func (pt *PassThruMonitor) Read(p []byte) (int, error)

Read 'overrides' the underlying io.Reader's Read method. This is the one that will be called by io.Copy(). We simply use it to keep track of byte counts and then forward the call.

type StreamLogMonitor added in v0.7.2

type StreamLogMonitor struct {
	Prefix string // Prefix for the line
	// contains filtered or unexported fields
}

StreamLogMonitor wraps an existing io.Reader to monitor the log stream and adds prefix before each line

func (*StreamLogMonitor) Write added in v0.7.2

func (slm *StreamLogMonitor) Write(p []byte) (int, error)

Write will read 'overrides' the underlying io.Reader's Read method

type UnparsedJSON added in v0.7.5

type UnparsedJSON string

UnparsedJSON is used to store json as is and not parse it until the right time

func (UnparsedJSON) MarshalJSON added in v0.7.5

func (r UnparsedJSON) MarshalJSON() ([]byte, error)

MarshalJSON represents UnparsedJson as bytes

func (*UnparsedJSON) UnmarshalJSON added in v0.7.5

func (r *UnparsedJSON) UnmarshalJSON(b []byte) error

UnmarshalJSON converts bytes to UnparsedJson

func (*UnparsedJSON) UnmarshalYAML added in v0.7.5

func (r *UnparsedJSON) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML is needed to properly convert incoming yaml requests into json

Jump to

Keyboard shortcuts

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