util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

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 NewString

func NewString(v string) *string

func Ptr

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

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 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 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 (*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