util

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileStartsWithDirectory    = fmt.Errorf("FileStartsWith: Unable to check file prefix for directory")
	ErrFileStartsWithFileTooSmall = fmt.Errorf("FileStartsWith: File is too small for prefix")
	ErrFileStartsWithNotEqual     = fmt.Errorf("FileStartsWith: File is not starts with the prefix")
)
View Source
var EmptyByte = []byte{}
View Source
var LineBreak = []byte("\n")

Functions

func Contains

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

func CreateLock

func CreateLock(lock_path string) error

The function creates the lock file, notice - remove it yourself

func DotSerialize

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

Simple serializer to get map as key.subkey=value with dot separation for the keys

func ExpressionSqlFilter added in v0.6.0

func ExpressionSqlFilter(filter string) (string, error)

Ensures the where filter doesn't contain bad things (SQL injections) and returns a good one could be used as Where() in gorm. It expects just an expression, so no other SQL keys will work here. For example: * `id=1 AND a in (1,2) ORDER BY i; DROP u;` will become just `"id" = 1 AND "a" IN (1, 2)` * `DROP users` - will fail * `id = 1 OR lol in (SELECT * FROM users)` - will fail

func FileCopy

func FileCopy(src string, dst string) error

func FileReplaceBlock

func FileReplaceBlock(path, block_from, block_to string, lines ...string) error

func FileReplaceToken

func FileReplaceToken(path string, full_line, add, anycase bool, token_values ...string) error

func FileStartsWith

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

func SerializeMetadata

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

Serializes dictionary to usable format

func WaitLock

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

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

Types

type PassThruMonitor

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

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
}

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)

Read 'overrides' the underlying io.Reader's Read method

type UnparsedJson

type UnparsedJson string

func (*UnparsedJson) MarshalJSON

func (r *UnparsedJson) MarshalJSON() ([]byte, error)

func (*UnparsedJson) UnmarshalJSON

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

func (*UnparsedJson) UnmarshalYAML added in v0.7.0

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

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