util

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 14 Imported by: 13

Documentation

Index

Constants

View Source
const (
	DiffAdd string = "add"
	DiffDel string = "delete"
	DiffMod string = "modify"
	DiffEq  string = "eq"
)

Variables

This section is empty.

Functions

func BoolMaybeDeNil

func BoolMaybeDeNil(s *bool) bool

func Exists

func Exists(path string) (bool, error)

func FuncName

func FuncName(skip int) string

func Int32to64

func Int32to64(i *int32) *int64

func IntMaybeDefault

func IntMaybeDefault(s *int, def int) int

func JsonStr

func JsonStr(r interface{}) string

func Jsonify

func Jsonify(r interface{}) json.RawMessage

func ListSubFolders

func ListSubFolders(path string) ([]string, error)

func Max

func Max(x, y int) int

Max returns the larger of x or y.

func MaybeAssignStr

func MaybeAssignStr(s **string, defStr string)

func MaybeCreate

func MaybeCreate(folder string) error

func MaybeDefault

func MaybeDefault[T any](s *T, v T) T

func MaybeNil

func MaybeNil[T any](s *T) (res T)

func Min

func Min(x, y int) int

Min returns the smaller of x or y.

func NewDiff added in v0.5.0

func NewDiff(path string, from, to DiffMarshaler) (*Diff, *Result)

func NewJsonDiff added in v0.5.0

func NewJsonDiff[T any](path string, from, to *T) (*Diff, *Result)

func NewString

func NewString(v string) *string

func Ptr

func Ptr[T any](v T) *T

func SameResult added in v0.2.1

func SameResult(lh, rh *Result) bool

func StrMaybeDefault

func StrMaybeDefault(s *string, defStr string) string

func StrMaybeNil

func StrMaybeNil(s *string) string

func SumSlice

func SumSlice(s []int) int

Types

type Diff added in v0.5.0

type Diff struct {
	From []byte `json:"-" yaml:"-"`
	To   []byte `json:"-" yaml:"-"`
	Type string `json:"type" yaml:"type"`
	Path string `json:"path" yaml:"path"`
	Diff string `json:"diff" yaml:"diff"`
}

func (*Diff) String added in v0.5.3

func (d *Diff) String() string

type DiffMarshaler added in v0.5.0

type DiffMarshaler interface {
	MarshalForDiff() ([]byte, *Result)
}

type Result

type Result struct {
	Code      int         `json:"code"`
	Msg       string      `json:"message"`
	Ctx       string      `json:"context"`
	Timestamp time.Time   `json:"timestamp"`
	Result    interface{} `json:"result"`
	Inner     *Result     `json:"inner,omitempty"`
}

func ErrResult

func ErrResult(err error) *Result

func Error

func Error(ctx string, err error) *Result

func Errorf

func Errorf(format string, a ...interface{}) *Result

func GetAPIUrl

func GetAPIUrl(baseUrl, endpoint string) (string, *Result)

func GetUrl

func GetUrl(baseUrl, endpoint string) (string, *Result)

func ListFiles

func ListFiles(folder string) ([]string, *Result)

will return full path.

func LogError added in v0.5.2

func LogError(l *zerolog.Logger, ctx string, err error) *Result

func LogMsgError added in v0.4.2

func LogMsgError(logger *zerolog.Logger, ctx string, msg string) *Result

func MoveFile added in v0.6.1

func MoveFile(src, dst string) *Result

func MsgError

func MsgError(ctx string, msg string) *Result

func NewErrResult

func NewErrResult(ctx string, r interface{}) *Result

func NewResult

func NewResult(ctx string, r interface{}) *Result

func OK

func OK(ctx string) *Result

func StupidDeepCopy added in v0.6.2

func StupidDeepCopy[T any](v *T) (*T, *Result)

func (*Result) Error

func (r *Result) Error() string

func (Result) GetRootCause

func (r Result) GetRootCause() *Result

func (*Result) LogWith

func (r *Result) LogWith(logger *zerolog.Logger, ctx string) *Result

func (*Result) With

func (r *Result) With(ctx string) *Result

Jump to

Keyboard shortcuts

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