godao

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

README

go-dao

Data Access Object

My personal variable types in Golang. All of which is just an extension and made it simpler to create objects and converting them to other types

warning: this is meant for my own resuble utilities, that i use a lot, and making it available for me to import via go modules

  • Map (map[string]any with extra features: access by json path, encode-to-from json/msgpack)
  • Array (making array methods similiar to js array)
  • Bytes ([]bytes, with value conversion methods)

Documentation

Index

Constants

View Source
const (
	FieldNameCamel uint8 = iota
	FieldNameSnake
	FieldNameKebab
)

Variables

This section is empty.

Functions

func Allowable added in v0.1.5

func Allowable(pattern string) (min, max string)

Allowable parses the pattern and determines the minimum and maximum allowable values that the pattern can represent. When the max cannot be determined, 'true' will be returned for infinite.

func GOBDecode added in v0.1.5

func GOBDecode(data []byte, src any, useValues ...bool) (err error)

func GOBEncode added in v0.1.5

func GOBEncode(v any, useValues ...bool) (data []byte, err error)

func IsPattern added in v0.1.5

func IsPattern(str string) bool

IsPattern returns true if the string is a pattern.

func JsonDecode

func JsonDecode(data []byte, v any) (err error)

func JsonEncode

func JsonEncode(v any, pretty ...bool) (data []byte)

func MSGPackDecode added in v0.1.5

func MSGPackDecode(data []byte, v any) (err error)

func MSGPackEncode added in v0.1.5

func MSGPackEncode(v any) (data []byte, err error)

func MapKeys added in v0.1.5

func MapKeys[K comparable, V any](m map[K]V) (s []K)

func MapToStruct added in v0.1.5

func MapToStruct(src Map, tags string) (newStruct reflect.Type)

func MapValues added in v0.1.5

func MapValues[K comparable, V comparable](m map[K]V) (s []V)

func Match added in v0.1.5

func Match(str, pattern string) bool

func MatchLimit added in v0.1.5

func MatchLimit(str, pattern string, maxcomp int) (matched, stopped bool)

func MsgDecode

func MsgDecode(data []byte, v any) (err error)

func PopulateIntArray added in v0.1.5

func PopulateIntArray(count int) (r []int)

Types

type Arr added in v0.1.5

type Arr[T string | any] struct {
	Values []T `json:"data,omitempty"`
}

func NewArrayType

func NewArrayType[T comparable](initialValue ...T) (arr *Arr[T])

generic array

func (*Arr[T]) Contains added in v0.1.5

func (a *Arr[T]) Contains(matcher ...T) (r bool)

func (*Arr[T]) Filter added in v0.1.5

func (a *Arr[T]) Filter(cb func(int, T) bool) (r []T)

func (*Arr[T]) First added in v0.1.5

func (a *Arr[T]) First() T

func (*Arr[T]) ForEach added in v0.1.5

func (a *Arr[T]) ForEach(cb func(int, T, []T))

func (*Arr[T]) Get added in v0.1.5

func (a *Arr[T]) Get(index int) (r T)

func (*Arr[T]) GoString added in v0.1.5

func (a *Arr[T]) GoString() string

func (*Arr[T]) IndexOf added in v0.1.5

func (a *Arr[T]) IndexOf(matcher T) (r int)

func (*Arr[T]) Insert added in v0.1.5

func (a *Arr[T]) Insert(value T, index int) *Arr[T]

func (*Arr[T]) Last added in v0.1.5

func (a *Arr[T]) Last() T

func (*Arr[T]) Len added in v0.1.5

func (a *Arr[T]) Len() int

func (*Arr[T]) Map added in v0.1.5

func (a *Arr[T]) Map(cb func(int, T) T) (r []T)

func (*Arr[T]) MatchPattern added in v0.1.5

func (a *Arr[T]) MatchPattern(matcher string, result func(int, T)) (r bool)

func (*Arr[T]) Pop added in v0.1.5

func (a *Arr[T]) Pop() (v T)

func (*Arr[T]) Push added in v0.1.5

func (a *Arr[T]) Push(value T) (index int)

func (*Arr[T]) Randomise added in v0.1.5

func (a *Arr[T]) Randomise() *Arr[T]

func (*Arr[T]) Remove added in v0.1.5

func (a *Arr[T]) Remove(index int, count ...int) []T

func (*Arr[T]) Shift added in v0.1.5

func (a *Arr[T]) Shift() (v T)

func (*Arr[T]) Sort added in v0.1.5

func (a *Arr[T]) Sort(order string) *Arr[T]

func (*Arr[T]) String added in v0.1.5

func (a *Arr[T]) String() string

type Array

type Array = Arr[any]

Array is a dynamic type of array

func NewArray

func NewArray(initialValue ...[]any) *Array

create a new Array.

type Bytes

type Bytes []byte

func (Bytes) Append added in v0.1.5

func (b Bytes) Append(data []byte) Bytes

func (Bytes) Clear added in v0.1.5

func (b Bytes) Clear()

func (Bytes) Contains added in v0.1.5

func (b Bytes) Contains(f []byte) (ok bool)

func (Bytes) Empty added in v0.1.5

func (b Bytes) Empty() bool

func (Bytes) Encode added in v0.1.5

func (b Bytes) Encode(v any) (r Bytes, err error)

func (Bytes) Find added in v0.1.5

func (b Bytes) Find(value []byte) (start, end int, extract []byte)

func (Bytes) Float added in v0.1.5

func (v Bytes) Float(i ...float64) (val Float)

func (Bytes) GoString added in v0.1.5

func (b Bytes) GoString() string

func (Bytes) Humanize added in v0.1.5

func (b Bytes) Humanize() string

func (Bytes) Int added in v0.1.5

func (v Bytes) Int(i ...int) (val Int)

func (Bytes) IsJSON added in v0.1.5

func (b Bytes) IsJSON() bool

func (Bytes) Join added in v0.1.5

func (b Bytes) Join(src []Bytes, delim ...rune) (r Bytes)

func (Bytes) ReadFrom added in v0.1.5

func (b Bytes) ReadFrom(r io.Reader) (int, error)

func (Bytes) Size added in v0.1.5

func (b Bytes) Size() int

func (Bytes) Slice added in v0.1.5

func (b Bytes) Slice(pos int, length ...int) (data []byte)

func (Bytes) Split added in v0.1.5

func (b Bytes) Split(delim ...rune) (r []Bytes)

func (Bytes) String added in v0.1.5

func (b Bytes) String() string

func (Bytes) UiInt64 added in v0.1.5

func (v Bytes) UiInt64(i ...uint64) (val uint64)

func (Bytes) Uint16 added in v0.1.5

func (v Bytes) Uint16(i ...uint16) (val uint16)

func (Bytes) Uint32 added in v0.1.5

func (v Bytes) Uint32(i ...uint32) (val uint32)

func (Bytes) UnsafeString added in v0.1.5

func (b Bytes) UnsafeString() string

func (Bytes) Write added in v0.1.5

func (b Bytes) Write(value []byte) int

func (Bytes) WriteRune added in v0.1.5

func (b Bytes) WriteRune(r []rune) int

func (Bytes) WriteString added in v0.1.5

func (b Bytes) WriteString(s string) int

func (Bytes) WriteTo added in v0.1.5

func (b Bytes) WriteTo(w io.Writer) (int, error)

type Float

type Float float64

func (Float) Bytes added in v0.1.5

func (i Float) Bytes() []byte

func (Float) F32 added in v0.1.5

func (i Float) F32() float32

func (Float) FromBytes added in v0.1.5

func (i Float) FromBytes(v []byte) Float

func (Float) String added in v0.1.5

func (i Float) String() string

type Int

type Int int

func (Int) Bytes added in v0.1.5

func (i Int) Bytes() []byte

func (Int) FromBytes added in v0.1.5

func (i Int) FromBytes(v []byte) Int

func (Int) I16 added in v0.1.5

func (i Int) I16() int16

func (Int) I32 added in v0.1.5

func (i Int) I32() int32

func (Int) I64 added in v0.1.5

func (i Int) I64() int64

func (Int) I8 added in v0.1.5

func (i Int) I8() int8

func (Int) String added in v0.1.5

func (i Int) String() string

type MStructConfig added in v0.1.5

type MStructConfig struct {
	Tag string
}

type Map

type Map map[string]any

func NewMap

func NewMap() Map

func (Map) Bool added in v0.1.5

func (m Map) Bool(key string) bool

func (Map) ByKeyOrder added in v0.1.5

func (m Map) ByKeyOrder(sel []string, cb func(int, string, any))

func (Map) Bytes added in v0.1.5

func (m Map) Bytes(keys ...string) json.RawValue

func (Map) Call added in v0.1.5

func (m Map) Call(key string, args ...any) (out any, err error)

special func

func (Map) CanCall added in v0.1.5

func (m Map) CanCall(key string) (r bool)

func (Map) Consume added in v0.1.5

func (m Map) Consume(v map[string]any) Map

func (Map) Decode added in v0.1.5

func (m Map) Decode(key string, dst any) (err error)

decode the values into any variable

func (Map) DecodeBinary added in v0.1.5

func (m Map) DecodeBinary(data []byte) (mp Map, err error)

func (Map) Del added in v0.1.5

func (m Map) Del(p string) (res Result)

func (Map) Diffs added in v0.1.5

func (m Map) Diffs(src Map) (diff []string)

func (Map) Dom added in v0.1.5

func (m Map) Dom(tag string, inner ...string) (res string)

func (Map) Each added in v0.1.5

func (m Map) Each(fn func(int, string, any) bool) (a []any)

func (Map) EncodeBinary added in v0.1.5

func (m Map) EncodeBinary(additional ...map[string][]rune) (data []byte, err error)

func (Map) EqualKeys added in v0.1.5

func (m Map) EqualKeys(src Map) (r bool)

func (Map) ForEach added in v0.1.5

func (m Map) ForEach(cb func(int, string, any))

func (Map) FromBytes added in v0.1.5

func (m Map) FromBytes(data []byte) (r Result)

func (Map) FromString added in v0.1.5

func (m Map) FromString(data string) (r Result)

func (Map) Get added in v0.1.5

func (m Map) Get(p string, defaultValue ...any) (res Result)

func (Map) GetAsArray added in v0.1.5

func (m Map) GetAsArray(jpath string) (res []Map)

func (Map) GetByIndex added in v0.1.5

func (m Map) GetByIndex(i int) (k string, v any)

func (Map) HJSON added in v0.1.5

func (m Map) HJSON(keys ...string) interface{}

func (Map) Has added in v0.1.5

func (m Map) Has(keys ...string) bool

func (Map) Int added in v0.1.5

func (m Map) Int(key string) int

func (Map) Interface added in v0.1.5

func (m Map) Interface(p string) (res any)

func (Map) Iterate added in v0.1.5

func (m Map) Iterate(from string, cb func(string, Result) bool) (result Map)

func (Map) JSON added in v0.1.5

func (m Map) JSON(keys ...string) any

func (Map) JSON_Indent added in v0.1.5

func (m Map) JSON_Indent(keys ...string) any

func (Map) KeyMatch added in v0.1.5

func (m Map) KeyMatch(pattern string) (key string, value any, ok bool)

func (Map) Keys added in v0.1.5

func (m Map) Keys() []string

func (Map) Length added in v0.1.5

func (m Map) Length() int

func (Map) Map added in v0.1.5

func (m Map) Map(key string) Map

func (Map) MatchesKey added in v0.1.5

func (m Map) MatchesKey(pattern string, res func(k string, v any)) (ok bool)

func (Map) Merge added in v0.1.5

func (m Map) Merge(s ...Map) Map

func (Map) MergeStrict added in v0.1.5

func (m Map) MergeStrict(s Map, excludes []string) Map

func (Map) Selective added in v0.1.5

func (m Map) Selective(keys ...string) (o Map)

func (Map) Set added in v0.1.5

func (m Map) Set(p string, value interface{}) (res any)

func (Map) String added in v0.1.5

func (m Map) String(key string) string

func (Map) Values added in v0.1.5

func (m Map) Values() *Arr[any]

func (Map) ValuesString added in v0.1.5

func (m Map) ValuesString() []string

type RawValue

type RawValue = json.RawValue

func MsgEncode

func MsgEncode(v any, pretty ...bool) (data RawValue, err error)

type Result added in v0.1.5

type Result struct {
	gjson.Result
}

func (Result) Bytes added in v0.1.5

func (r Result) Bytes() []byte

func (Result) Decode added in v0.1.5

func (r Result) Decode(v any) (err error)

func (Result) Delete added in v0.1.5

func (r Result) Delete(path string) (err error)

func (Result) Each added in v0.1.5

func (r Result) Each(cb func(key, value any) bool)

func (Result) Get added in v0.1.5

func (r Result) Get(key string) Result

func (Result) Map added in v0.1.5

func (r Result) Map() Map

func (Result) Set added in v0.1.5

func (r Result) Set(p string, value any) (err error)

type SMap added in v0.1.5

type SMap[T string, V any] struct {
	V map[T]V
}

func (*SMap[T, V]) Bytes added in v0.1.5

func (s *SMap[T, V]) Bytes(pretty ...bool) []byte

func (*SMap[T, V]) Delete added in v0.1.5

func (s *SMap[T, V]) Delete(path string)

func (*SMap[T, V]) Get added in v0.1.5

func (s *SMap[T, V]) Get(path string) (val Result)

func (*SMap[T, V]) GetMany added in v0.1.5

func (s *SMap[T, V]) GetMany(path ...string) (val []Result)

func (*SMap[T, V]) Parse added in v0.1.5

func (s *SMap[T, V]) Parse(val []byte) *SMap[T, V]

func (*SMap[T, V]) Set added in v0.1.5

func (s *SMap[T, V]) Set(path string, val V)

func (*SMap[T, V]) String added in v0.1.5

func (s *SMap[T, V]) String(pretty ...bool) string

type StringArray

type StringArray = Arr[string]

example of speficic type of array

Directories

Path Synopsis
encoding
msg
internal
dao

Jump to

Keyboard shortcuts

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