utility

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TimeMillis = "15:04:05.000"

Variables

This section is empty.

Functions

func AnyBlank

func AnyBlank(args ...string) bool

AnyBlank has any empty value return true otherwise return false

func Apply

func Apply[T any](o *T, opts ...Option[T])

func B64Decode

func B64Decode(source string) []byte

func B64Encode

func B64Encode(src []byte) []byte

func Blanks

func Blanks(args ...string) bool

Blanks all value empty return true otherwise return false

func Bytes

func Bytes(data string) []byte

Bytes convert string to []byte

func DObj

func DObj[T any](source, d T) T

DObj returns source if not nil else return default value

func DString

func DString(source, d string) string

DString returns d if source blank else return source

func ErrorArgument

func ErrorArgument(err error) error

func ErrorArgumentf

func ErrorArgumentf(format string, v ...any) error

func ExternalIp

func ExternalIp() (net.IP, bool)

func FileExists

func FileExists(path string) bool

func First

func First[S ~[]E, E any](d E, list S) E

func IntranetIp

func IntranetIp() (net.IP, bool)

func IsBlank

func IsBlank(b string) bool

func IsEmail

func IsEmail(email string) bool

func Map

func Map[T, R any](dest []T, mapper func(T) R) (rs []R)

func Nils

func Nils(objs ...any) bool

Nils all values is nil return true otherwise return false

func NonBlank

func NonBlank(v string) bool

func NonBlanks

func NonBlanks(args ...string) bool

NonBlanks has any empty string returns false otherwise return true

func RandomTCPListener

func RandomTCPListener() (net.Listener, error)

func SQLString

func SQLString(s string) sql.NullString

SQLString returns a valid sql.NullString

func String

func String(data []byte) string

String convert []byte to string

Types

type Command

type Command struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

func Cmd

func Cmd(name string, args ...string) *Command

func (*Command) Dir

func (c *Command) Dir(directory string) *Command

func (*Command) Env

func (c *Command) Env(env []string) *Command

func (*Command) Path

func (c *Command) Path(path string) *Command

func (*Command) Pipeout

func (c *Command) Pipeout(fn func(line string)) *Command

func (*Command) StartAndWait

func (c *Command) StartAndWait() error

func (*Command) Stderr

func (c *Command) Stderr(stderr io.Writer) *Command

func (*Command) Stdin

func (c *Command) Stdin(stdin io.Reader) *Command

func (*Command) Stdout

func (c *Command) Stdout(stdout io.Writer) *Command

type CommandBatch

type CommandBatch struct {
	Path   string
	Dir    string
	Env    []string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	PipeFn func(string)
}

func CmdBatch

func CmdBatch(opts ...Option[CommandBatch]) *CommandBatch

func (*CommandBatch) Run

func (b *CommandBatch) Run(items ...CommandItem) error

type CommandItem

type CommandItem struct {
	Name string
	Args []string
}

type Option

type Option[T any] interface {
	Apply(*T)
}

func WithDir

func WithDir(dir string) Option[CommandBatch]

func WithEnvs

func WithEnvs(envs []string) Option[CommandBatch]

func WithPath

func WithPath(path string) Option[CommandBatch]

func WithPipeFn

func WithPipeFn(fn func(string)) Option[CommandBatch]

func WithStderr

func WithStderr(stderr io.Writer) Option[CommandBatch]

func WithStdin

func WithStdin(stdin io.Reader) Option[CommandBatch]

func WithStdout

func WithStdout(stdout io.Writer) Option[CommandBatch]

type OptionFunc

type OptionFunc[T any] func(*T)

func (OptionFunc[T]) Apply

func (f OptionFunc[T]) Apply(t *T)

type Options

type Options[T any] []Option[T]

func (Options[T]) Apply

func (opts Options[T]) Apply() *T

type ResponseEntity

type ResponseEntity interface {
	Code() int
	Error() string
	Marshal() ([]byte, error)
	MarshalIdent() ([]byte, error)
}

func NewErrResponse

func NewErrResponse(code int, msg string) ResponseEntity

func NewResponse

func NewResponse(payload any) ResponseEntity

type SafeRunner

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

func NewSafeRunner

func NewSafeRunner() *SafeRunner

func (*SafeRunner) Err

func (r *SafeRunner) Err() error

func (*SafeRunner) Run

func (r *SafeRunner) Run(fn func() error)

Jump to

Keyboard shortcuts

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