utils

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 9 Imported by: 2

README

Files

File Feature
LoadKvp Load key value pair file, intended use is as a .env loader
ErrorsWithTrace Errors with stack traces (that can be disabled)
SaveKvp Save key value pair to a given file
Convert Very simple no copy string to []byte to string conversion

where is the documentation?

The code is the documentation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNewlineInKey = errors.New("`\\n` found in key")
	ErrorEqualsInKey  = errors.New("`=` found in key")
)
View Source
var WithStack = noStack

Functions

func B2S

func B2S(b []byte) string

WARNING: DONOT MUTATE THE ENTERED VALUE AS LONG AS THE RETURNED STRING IS IN USE

func BitCast added in v1.0.5

func BitCast[From any, To any](val From) To

WARNING: Uses unsafe casting

func Load

func Load(file string, setter func(k, v string) error) error

Loads the provided env file.

func PtrCast added in v1.0.5

func PtrCast[From any, To any](val *From) *To

WARNING: Uses unsafe casting

func S2B

func S2B(s string) []byte

WARNING: DONOT MUTATE RETURNED VALUE

func SetErrorStackTrace added in v1.0.2

func SetErrorStackTrace(showTrace bool)

Types

type ErrorWithStack

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

func (ErrorWithStack) Error

func (e ErrorWithStack) Error() string

func (ErrorWithStack) OriginalError added in v1.0.2

func (e ErrorWithStack) OriginalError() string

func (ErrorWithStack) Unwrap

func (e ErrorWithStack) Unwrap() error

type KvpFile

type KvpFile struct{ os.File }

func (KvpFile) Write

func (file KvpFile) Write(k, v string) error

type Optional added in v1.0.4

type Optional[T any] struct {
	Val    T
	Exists bool
}

func (Optional[T]) MarshalJSON added in v1.0.4

func (self Optional[T]) MarshalJSON() ([]byte, error)

func (*Optional[T]) UnmarshalJSON added in v1.0.4

func (self *Optional[T]) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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