comdef

package
v0.0.0-...-f5003fd Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package comdef provide some common type or constant definitions

Index

Constants

View Source
const (
	OpEq  = "="
	OpNeq = "!="
	OpLt  = "<"
	OpLte = "<="
	OpGt  = ">"
	OpGte = ">="
)

consts for compare operation

View Source
const (
	SingleQuote = '\''
	DoubleQuote = '"'
	SlashQuote  = '\\'

	SingleQuoteStr = "'"
	DoubleQuoteStr = `"`
	SlashQuoteStr  = "\\"
)

consts quote chars

View Source
const (
	// CommaStr const define
	CommaStr = ","
	// CommaChar define
	CommaChar = ','

	// EqualStr define
	EqualStr = "="
	// EqualChar define
	EqualChar = '='

	// ColonStr define
	ColonStr = ":"
	// ColonChar define
	ColonChar = ':'

	// SemicolonStr semicolon define
	SemicolonStr = ";"
	// SemicolonChar define
	SemicolonChar = ';'

	// PathStr define const
	PathStr = "/"
	// PathChar define
	PathChar = '/'

	// DefaultSep comma string
	DefaultSep = ","

	// SpaceChar char
	SpaceChar = ' '
	// SpaceStr string
	SpaceStr = " "

	// NewlineChar char
	NewlineChar = '\n'
	// NewlineStr string
	NewlineStr = "\n"
)
View Source
const Newline = "\n"

Newline string for non-windows

View Source
const NoIdx = -1

NoIdx invalid index or length

Variables

View Source
var ErrConvType = errors.New("convert value type error")

ErrConvType error

Functions

This section is empty.

Types

type BaseFormatter

type BaseFormatter struct {

	// Out formatted to the writer
	Out io.Writer
	// Src data(array, map, struct) for format
	Src any
	// MaxDepth limit depth for array, map data TODO
	MaxDepth int
	// Prefix string for each element
	Prefix string
	// Indent string for format each element
	Indent string
	// ClosePrefix string for last "]", "}"
	ClosePrefix string
	// contains filtered or unexported fields
}

BaseFormatter struct

func (*BaseFormatter) BsWriter

func (f *BaseFormatter) BsWriter() ByteStringWriter

BsWriter build and get

func (*BaseFormatter) Reset

func (f *BaseFormatter) Reset()

Reset after format

func (*BaseFormatter) SetOutput

func (f *BaseFormatter) SetOutput(out io.Writer)

SetOutput writer

type ByteStringWriter

type ByteStringWriter interface {
	io.Writer
	io.ByteWriter
	io.StringWriter
	fmt.Stringer
}

ByteStringWriter interface

type Compared

type Compared interface {
	Int | Uint | Float | ~string
}

Compared type. alias of constraints.SortedType

TODO: use type alias, will error on go1.18 Error: types.go:50: interface contains type constraints type Compared = SortedType

type DataFormatter

type DataFormatter interface {
	Format() string
	FormatTo(w io.Writer)
}

DataFormatter interface

type Errors

type Errors []error

Errors multi error list

func (Errors) ErrOrNil

func (es Errors) ErrOrNil() error

ErrOrNil error

func (Errors) Error

func (es Errors) Error() string

Error string

func (Errors) First

func (es Errors) First() error

First error

type Float

type Float interface {
	~float32 | ~float64
}

Float interface type

type Float64able

type Float64able interface {
	Float64() (float64, error)
}

Float64able interface

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Int interface type

type Int64able

type Int64able interface {
	Int64() (int64, error)
}

Int64able interface

type IntCheckFunc

type IntCheckFunc func(val int) error

IntCheckFunc check func

type IntOrFloat

type IntOrFloat interface {
	Int | Float
}

IntOrFloat interface type. all int and float types

type Integer

type Integer interface {
	Int | Uint
}

Integer interface type. all int or uint types

type MarshalFunc

type MarshalFunc func(v any) ([]byte, error)

MarshalFunc define

type MatchFunc

type MatchFunc[T any] func(v T) bool

MatchFunc definition. implements Matcher interface

func (MatchFunc[T]) Match

func (fn MatchFunc[T]) Match(v T) bool

Match satisfies the Matcher interface

type Matcher

type Matcher[T any] interface {
	Match(s T) bool
}

Matcher interface

type SafeStringFunc

type SafeStringFunc func(v any) string

SafeStringFunc safe convert value to string

type ScalarType

type ScalarType interface {
	Int | Uint | Float | ~string | ~bool
}

ScalarType basic interface type.

TIP: has bool type, it cannot be ordered

contains: (x)int, float, ~string, ~bool types

type SimpleType

type SimpleType interface {
	Int | Uint | Float | ~string | ~bool
}

SimpleType interface type. alias of ScalarType

contains: (x)int, float, ~string, ~bool types

type SortedType

type SortedType interface {
	Int | Uint | Float | ~string
}

SortedType interface type. same of constraints.Ordered

it can be ordered, that supports the operators < <= >= >.

contains: (x)int, float, ~string types

type StrCheckFunc

type StrCheckFunc func(val string) error

StrCheckFunc check func

type StringHandleFunc

type StringHandleFunc func(s string) string

StringHandleFunc definition

func (StringHandleFunc) Handle

func (fn StringHandleFunc) Handle(s string) string

Handle satisfies the StringHandler interface

type StringHandler

type StringHandler interface {
	Handle(s string) string
}

StringHandler interface

type StringMatchFunc

type StringMatchFunc func(s string) bool

StringMatchFunc definition

func (StringMatchFunc) Match

func (fn StringMatchFunc) Match(s string) bool

Match satisfies the StringMatcher interface

type StringMatcher

type StringMatcher interface {
	Match(s string) bool
}

StringMatcher interface

type StringWriteStringer

type StringWriteStringer interface {
	io.StringWriter
	fmt.Stringer
}

StringWriteStringer interface

type ToStringFunc

type ToStringFunc func(v any) (string, error)

ToStringFunc try to convert value to string, return error on fail

type ToTypeFunc

type ToTypeFunc[T any] func(any) (T, error)

ToTypeFunc convert value to defined type

type Uint

type Uint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Uint interface type

type UnmarshalFunc

type UnmarshalFunc func(bts []byte, ptr any) error

UnmarshalFunc define

type Xint

type Xint interface {
	Int | Uint
}

Xint interface type. alias of Integer

type XintOrFloat

type XintOrFloat interface {
	Int | Uint | Float
}

XintOrFloat interface type. all int, uint and float types

Jump to

Keyboard shortcuts

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